wxPython Grid Cell change question

K

Kiran

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
 
K

Kiran

Never mind, I used 2 different binds for the 2 different situations and
it worked.

thanks for looking anyhow.

-- Kiran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top