Pressing a key to enter the first character into a cell invokes the
OnEditShow event. The TAB or CR are captured in the OnKeyDown event
which comes next in time. However, at this time "GetCellValue()" returns
blank meaning the data is not yet available. Next comes OnSelectCell,
then OnEditHidden and then OnCellChange at which time the data in the
cell is at last available. Can anyone tell me how in this event handler
I can force the cursor back to the previous cell. Or is there a better
way to do it?
You'd think that you could just call SetGridCursor from within the
OnCellChanged, but it doesn't work because it is already nested inside a
SetGridCursor to when the event handler returns the original SetGridCursor
completes and moves the current cell to the new one. To get around this you
can change back to the cell in question in idle time, like this:
def OnCellChange(self, evt):
self.log.write("OnCellChange: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
# Show how to stay in a cell that has bad data. We can't just
# call SetGridCursor here since we are nested inside one so it
# won't have any effect. Instead, set coordinants to move to in
# idle time.
value = self.GetCellValue(evt.GetRow(), evt.GetCol())
if value == 'no good':
self.moveTo = evt.GetRow(), evt.GetCol()
def OnIdle(self, evt):
if self.moveTo != None:
self.SetGridCursor(self.moveTo[0], self.moveTo[1])
self.moveTo = None
Another approach is to force the completion of the edit control (savinf the
data to the table) a little early in the OnSelectCell, and then check it and
if it is bad simply don't call evt.Skip(), like this:
def OnSelectCell(self, evt):
self.log.write("OnSelectCell: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
# Another way to stay in a cell that has a bad value...
row = self.GetGridCursorRow() # current coords
col = self.GetGridCursorCol()
if self.IsCellEditControlEnabled():
self.HideCellEditControl()
self.DisableCellEditControl()
value = self.GetCellValue(row, col)
if value == 'no good 2':
return # cancels the cell selection
else:
evt.Skip()
GridSimple.py (6.53 KB)
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!