Hi there,
Here's a tiny trick I thought I should share with you.
I use wxDesigner, which generates a "dialog function", which is a function that populates a frame/dialog with controls. The problem is that the generated code doesn't create member variables for your code, so you have to use things like this:
class MyFrame(wx.Frame):
def __init__(...):
bla bla
WxDesignerGeneratedFormFunc(self, True)
def GetTheTextBoxControl(self):
return self.FindWindowById( ID_TEXTBOX1 )
Creating Get***Control functions can be tedious (even with wxDesigner's help) and calling self.GetWhateverControl() is waaay to much typing :o), so instead I wrote this tiny descriptor:
class control(object):
def __init__(self, id):
self.id = id
def __get__(self, obj, type=None):
return obj.FindWindowById(self.id)
def __set__(self, obj, val):
raise AttributeError()
Now I can do this in my Frame/Dialog derived class:
class MyFrame(wx.Frame):
def __init__(...):
bla bla
WxDesignerGeneratedFormFunc(self, True)
textbox = control(ID_TEXTBOX1)
btnOK = control(ID_OKBTN)
btnCancel = control(ID_CANCELBTN)
which allows me to just do a regular property access ("self.textbox" or "frameinstance.btnOK") to get my control.
Arnar