wxPython Grid Cell change question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kiran

    #1

    wxPython Grid Cell change question

    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_C HANGE. 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.gr id.EVT_GRID_EDI TOR_SHOWN, self.EditorShow n)
    self.Bind(wx.gr id.EVT_GRID_EDI TOR_HIDDEN, self.EditorHidd en)


    def EditorShown(sel f, event):
    self.editorShow n = True
    event.Skip()

    def EditorHidden(se lf, event):
    self.editorHidd en = True
    row = event.GetRow()
    col = event.GetCol()
    print "VAL = " + str(self.grid.G etCellValue(row , col))
    +str(self.OnTes tCellValue(row, col))
    event.Skip()

    def OnTestCellValue (self, row, col):
    if self.editorShow n and self.editorHidd en:
    self.editorShow n = False
    self.editorHidd en = False
    self.SetCellVal ue(row, col)

    def SetCellValue(se lf, row, col):
    print "EVENT PROCESSIGN STARTED"
    print "RAW VAL = " + str(self.grid.G etCellValue(row , col))
    value = int(self.grid.G etCellValue(row , col), 16)
    print "VAL = " + str(value)
    # if we need to add a row
    if row == (len(self.data)-1):
    self.expandGrid ()
    self.data.appen d([])
    # 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(s elf.data) # cloning object
    self.requestQue ue.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.gr id.EVT_GTID_CEL L_CHANGE, self.SetCellVal ue)


    thanks,
    Kiran

  • Kiran

    #2
    Re: wxPython Grid Cell change question

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

    thanks for looking anyhow.

    -- Kiran
    Kiran wrote:
    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_C HANGE. 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.gr id.EVT_GRID_EDI TOR_SHOWN, self.EditorShow n)
    self.Bind(wx.gr id.EVT_GRID_EDI TOR_HIDDEN, self.EditorHidd en)
    >
    >
    def EditorShown(sel f, event):
    self.editorShow n = True
    event.Skip()
    >
    def EditorHidden(se lf, event):
    self.editorHidd en = True
    row = event.GetRow()
    col = event.GetCol()
    print "VAL = " + str(self.grid.G etCellValue(row , col))
    +str(self.OnTes tCellValue(row, col))
    event.Skip()
    >
    def OnTestCellValue (self, row, col):
    if self.editorShow n and self.editorHidd en:
    self.editorShow n = False
    self.editorHidd en = False
    self.SetCellVal ue(row, col)
    >
    def SetCellValue(se lf, row, col):
    print "EVENT PROCESSIGN STARTED"
    print "RAW VAL = " + str(self.grid.G etCellValue(row , col))
    value = int(self.grid.G etCellValue(row , col), 16)
    print "VAL = " + str(value)
    # if we need to add a row
    if row == (len(self.data)-1):
    self.expandGrid ()
    self.data.appen d([])
    # 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(s elf.data) # cloning object
    self.requestQue ue.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.gr id.EVT_GTID_CEL L_CHANGE, self.SetCellVal ue)
    >
    >
    thanks,
    Kiran

    Comment

    Working...