wxPython: generating event IDs?
Grant Edwards
grante at visi.com
Sun Mar 10 02:12:16 EST 2002
In article <3C8B0273.A3651580 at engcorp.com>, Peter Hansen wrote:
>> There must be a way to eliminate the need to predefine unique
>> ID numbers. I hate trying to maintain lists of numbers like
>> that (well, more accurately, I'm just bad at it).
> This little method which I've used inside a wxFrame subclass
> demonstrates a slightly simpler approach than "define a unique
> ID number". Note the use of wxNewId() to make that part
> trivial. If you attach your commands to buttons using a
> method you can wrap the little bit of ugliness and never have
> to see it again:
Thanks. I'll keep that in mind. Here's what I came up with for
buttons:
class MyButton(wxButton):
def __init__(self, parent, ident, *argt, **argd):
c = None
if argd.has_key("command"):
c = argd["command"]
del argd["command"]
wxButton.__init__(self, parent, ident, *argt, **argd)
if c:
EVT_BUTTON(self,self.GetId(),c)
The usage of MyButton() is identical to wxButton() except you
can add a command=self.foobar:
MyButton(self,-1,"Button Text",command=self.buttonCommand)
--
Grant Edwards grante Yow! I'm dressing up in
at an ill-fitting IVY-LEAGUE
visi.com SUIT!! Too late...
More information about the Python-list
mailing list