CallAfter on wx.grid work not properly

Hi all.
Robin, my grid is used to enter data in the table and to do this using
wx.grid.Grid. The user enters the data and can move to the next cell with the tab.
I want to check the contents of the fields only after entering the last field.
To make it easier for example the first field is wrong. Then after the last tab on the 2^ field
i show a message and then set focus on the first cell and enabled editor.
This works on windows but not properly on Linux. Let me explain. On Linux when show the message
then if I enter the confirmation with keyboard the field is not focused while if I confirmed it with the mouse then work.
I do not like to use the callLater so i need a workaround for this issue.
Attached script.

gestgrid.py (9.95 KB)

···


Fabio Spadaro
www.fabiospadaro.com

I'm not sure I understand what you are trying to do or what is wrong, but I noticed code like this in your sample:

            wx.CallAfter(self.grid.SetFocus)
            wx.CallAfter(self.grid.MakeCellVisible,0,0)
            wx.CallAfter(self.grid.SetGridCursor,0, 0)
            wx.CallAfter(self.grid.EnableCellEditControl,True)

This is not a good idea. Since CallAfters are implemented using events it is possible that they might be run out of order, or that the next ones will be run before the first ones are completed. This can happen if the code in a CallAfter generates an event. Better would be to make a function that contains all 4 statements and then use CallAfter to call that function.

     def doAfter(self):
         self.grid.SetFocus()
         self.grid.MakeCellVisible(0,0)
         self.grid.SetGridCursor(0, 0)
         self.grid.EnableCellEditControl(True)

     wx.CallAfter(self.doAfter)

···

On 11/15/11 1:44 AM, Fabio Spadaro wrote:

Hi all.
Robin, my grid is used to enter data in the table and to do this using
  wx.grid.Grid. The user enters the data and can move to the next cell
with the tab.
  I want to check the contents of the fields only after entering the
last field.
  To make it easier for example the first field is wrong. Then after the
last tab on the 2^ field
  i show a message and then set focus on the first cell and enabled editor.
  This works on windows but not properly on Linux. Let me explain. On
Linux when show the message
then if I enter the confirmation with keyboard the field is not focused
while if I confirmed it with the mouse then work.
  I do not like to use the callLater so i need a workaround for this issue.
  Attached script.

--
Robin Dunn
Software Craftsman