Don't understand wxPython ids
Grant Edwards
grante at visi.com
Wed Apr 28 00:17:37 EDT 2004
In article <BOEjc.12559$eZ5.4366 at newsread1.news.pas.earthlink.net>, Greg Krohn wrote:
> AFAIK, yes. But then again, I don't know much. Note that you can use -1
> as the id and the button will create it's own unique id for you. Then
> all you have to do is call button.GetId() whenever you need it.
Ya know, now that you mention it, I think I actually new that
once a couple years back.
>> Can somebody clue me in on the advantages of the
>> progrmmer-generated integer id numbers for objects?
>
> In the new wxPython (2.5.1.5) there's an easier way to bind events
> without using ids at all using widget.Bind, like this:
>
> import wx
>
> 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?")
> self.button.Bind(wx.EVT_BUTTON, self.OnButtonPress)
That's definitely getting closer to what I would expect in
something designed in the last 15-20 years, though passing the
binding as a parameter to wx.Button() sure seems like the
obvious solution for 90% of the cases I run into. Perhaps I'm
too used to Tk.
> I can only think of one reasn why they chose to use ids in the first
> place. Assigning many objects the same id allows you to use one EVT_*
> call for those objects. But is that really a useful feature? Who knows?
That's about the only thing I could think of. The few
situations where I'd have wanted to do someting like that I'd
gladly put a for-loop iterating over a list of objects in
exchange for being able to use single-line of code the other
90% of the time.
--
Grant Edwards grante Yow! I'm young... I'm
at HEALTHY... I can HIKE
visi.com THRU CAPT GROGAN'S LUMBAR
REGIONS!
More information about the Python-list
mailing list