set validator for grid cell

i'm catching wx.grid.EVT_GRID_EDITOR_CREATED, but how do i attach my validator to the current cell being entered?

Timothy Smith wrote:

i'm catching wx.grid.EVT_GRID_EDITOR_CREATED, but how do i attach my validator to the current cell being entered?

  event.GetControl().SetValidator(MyValidator())

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Timothy Smith wrote:

i'm catching wx.grid.EVT_GRID_EDITOR_CREATED, but how do i attach my validator to the current cell being entered?

    event.GetControl().SetValidator(MyValidator())

ok cheers, i've attached the validator but i get this weird behavour, it allow the first character i enter to be of the wrong type, and will only allow one to be entered. her eis my validator class

class RosterTimeValidator(wx.PyValidator):
    def __init__(self):
        wx.PyValidator.__init__(self)
        wx.EVT_CHAR(self,self.OnChar)
           def Clone(self):
        return RosterTimeValidator()
           def Validate(self, win):
        tc = self.GetWindow()
        val = tc.GetValue()
        if val in range(0, 2359):
            return True
        else:
            return False
               def OnChar(self,evt):
        key = evt.KeyCode()
        if chr(key) in range(0,2359):
            evt.Skip
        else:
            wx.Bell()
        return

Timothy Smith wrote:

Robin Dunn wrote:

Timothy Smith wrote:

i'm catching wx.grid.EVT_GRID_EDITOR_CREATED, but how do i attach my validator to the current cell being entered?

    event.GetControl().SetValidator(MyValidator())

ok cheers, i've attached the validator but i get this weird behavour, it allow the first character i enter to be of the wrong type,

The first key is sent to the grid since it hasn't yet created the editor when that keystroke happens. It looks up the attributes for that cell and asks the GridCellEditor if that key is acceptable, and then finally calls the editor's StartingKey to stuff it in to the control. So as you've seen, there is no Validator involvement for the first character, it is all handled in the cell editor.

and will only allow one to be entered. her eis my validator class

class RosterTimeValidator(wx.PyValidator):
   def __init__(self):
       wx.PyValidator.__init__(self)
       wx.EVT_CHAR(self,self.OnChar)
         def Clone(self):
       return RosterTimeValidator()
         def Validate(self, win):
       tc = self.GetWindow()
       val = tc.GetValue()
       if val in range(0, 2359):

You are comparing apples and oranges. val is a string and you are checking if there is a matching string in a range of integers. This will always be false.

           return True
       else:
           return False
             def OnChar(self,evt):
       key = evt.KeyCode()
       if chr(key) in range(0,2359):

Same here.

···

           evt.Skip
       else:
           wx.Bell()
       return

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Timothy Smith wrote:

Robin Dunn wrote:

Timothy Smith wrote:

i'm catching wx.grid.EVT_GRID_EDITOR_CREATED, but how do i attach my validator to the current cell being entered?

    event.GetControl().SetValidator(MyValidator())

ok cheers, i've attached the validator but i get this weird behavour, it allow the first character i enter to be of the wrong type,

The first key is sent to the grid since it hasn't yet created the editor when that keystroke happens. It looks up the attributes for that cell and asks the GridCellEditor if that key is acceptable, and then finally calls the editor's StartingKey to stuff it in to the control. So as you've seen, there is no Validator involvement for the first character, it is all handled in the cell editor.

damn thats not real good, because by murphy's law if they can enter to first character incorrectly, they will.

Timothy Smith wrote:

The first key is sent to the grid since it hasn't yet created the editor when that keystroke happens. It looks up the attributes for that cell and asks the GridCellEditor if that key is acceptable, and then finally calls the editor's StartingKey to stuff it in to the control. So as you've seen, there is no Validator involvement for the first character, it is all handled in the cell editor.

damn thats not real good, because by murphy's law if they can enter to first character incorrectly, they will.

That's why it is possible to make custom GridCellEditors.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!