Don't understand wxPython ids
Greg Krohn
greg at invalid.invalid
Wed Apr 28 15:14:38 EDT 2004
Grant Edwards wrote:
> I guess it's simple enough to subclass the widgets I use and
> add one, but it feels like going to buy a new car and having to
> bring your own steering wheel.
Well, no I meant importing something like this each time (it doesn't
actually work, BTW):
import wx
#Subclass wx.PyEventBinder to catch all EVT_* args
class MyPyEventBinder(wx.PyEventBinder):
def __init__(self, *args, **kwargs):
# Look for EVT_* args, bind them and del them
for kw in kwargs:
if kw.startswith('EVT_'):
self.Bind(getattr(wx, kw), kwargs[kw])
del kwargs[kw]
wx.PyEventBinder.__init__(self, *args, **kwargs)
#A little behind-the-scenes switcheroo
wx.PyEventBinder = MyPyEventBinder
if __name__ == '__main__':
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.button = wx.Button(self, -1, "What's my id?",
EVT_BUTTON=self.OnButtonPress)
def OnButtonPress(self, event):
self.button.SetLabel("My id is: %d" % self.button.GetId())
app = wx.App()
frame = MyFrame(None, -1, "Events and ids")
frame.Show(True)
app.MainLoop()
If I can't figure this out, I'll try subclassing individule widgets and
throwing it in a module.
greg
More information about the Python-list
mailing list