[wxPython-users] best way to disable editing widgets ?

Marco De Felice m.defel at gmail.com
Fri May 4 07:37:43 PDT 2007


I'm using validators to achieve the same result as 
wx.TextCtrl.SetEditable() but on different kinds of widgets (wx.CheckBox).
I use the following validator:

class ProtectValidator(wx.PyValidator):
    def __init__(self):
        wx.PyValidator.__init__(self)
        self.Bind(wx.EVT_CHAR, self.OnChar)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
    def Clone(self):
        return ProtectValidator()
    def Validate(self, win):
        return False
    def OnChar(self, event):
        return
    def OnMouse(self, event):
        return

testCheck = wx.CheckBox(pane, -1)
testCheck.SetValidator(ProtectValidator) #to disable "editing"
testCheck.SetValidator(wx.Validator()) #to enable "editing"

I don't know if the default validator of a chekbox is really a 
wx.Validator(), is it automatically mapped to the underlying 
wxGenericValidator? Anyway it works.

Is there a simpler/better solution?
Something like Enable(False) on the parent window but without shading 
out everything?




More information about the wxpython-users mailing list