wxPython Grid Cell change question

Kiran Kiran.Karra at gmail.com
Thu Jul 13 16:43:30 EDT 2006


 Hello All,
I created a grid, where I register events every time the user changes
an existing value inside the grid control. Right now, I am using the
event: EVT_GRID_CELL_CHANGE. However, I realized that I need to
register that same kind of event even if the user doesnt change the
value, but just selects and then deselects.

I tried creating my own custom event, where i check to see if the
editor is activated and then deactivated, and if so, then set the sell
value. However, this doesnt work because the value that it needs to be
set to is the same previous value that was in the grid. Therefore, I
can never get a new value in the grid. Here is the code for the events:

in init():
      self.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.EditorShown)
      self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.EditorHidden)


def EditorShown(self, event):
     self.editorShown = True
     event.Skip()

def EditorHidden(self, event):
     self.editorHidden = True
     row = event.GetRow()
     col = event.GetCol()
     print "VAL = " + str(self.grid.GetCellValue(row, col))
+str(self.OnTestCellValue(row, col))
     event.Skip()

def OnTestCellValue(self, row, col):
     if self.editorShown and self.editorHidden:
     self.editorShown = False
     self.editorHidden = False
     self.SetCellValue(row, col)

def SetCellValue(self, row, col):
     print "EVENT PROCESSIGN STARTED"
     print "RAW VAL = " + str(self.grid.GetCellValue(row, col))
     value = int(self.grid.GetCellValue(row, col), 16)
     print "VAL = " + str(value)
     # if we need to add a row
     if row == (len(self.data)-1):
         self.expandGrid()
         self.data.append([])
     # if we need to delete a row
     if row != 0 and value == '':
         self.data[row][3] = 'Delete'
     else:
         self.addToData(row, col, value, True)
     # whether the user intended a read or write
     if self.data[row][3] != 'Delete':
         if col == 1:
             self.data[row][3] = 'Read'
         elif col == 2:
             self.data[row][3] = 'Write'

     q = copy.deepcopy(self.data) # cloning object
     self.requestQueue.put(q) # putting object onto queue
     print "EVENT PROCESSIGN ENDED"

Thanks a lot for your help, and please mind the spacing.

I should note that before, my bind was:
self.Bind(wx.grid.EVT_GTID_CELL_CHANGE, self.SetCellValue)


thanks,
Kiran




More information about the Python-list mailing list