Don't understand wxPython ids

Grant Edwards grante at visi.com
Wed Apr 28 09:47:40 EDT 2004


On 2004-04-28, Roger Binns <rogerb at rogerbinns.com> wrote:

> Here is how I use the same id in multiple locations.  I can have a
> menu entry, a toolbar button, and a button inside some HTML all
> invoke the same function.  The only coupling between them is
> the id number.
>
>       ID_FILE_DELETE=wx.NewId()
>           ...
>           menu.Append(self.ID_FILE_DELETE, "&Delete", "Delete the file")
>           ....
>           toolbar.AddLabelTool(self.ID_FILE_DELETE, "Delete", ....)
>           ....
>           wx.EVT_MENU(self, self.ID_FILE_DELETE, self.OnFileDelete)
>           ....
>           wx.EVT_BUTTON(self, self.ID_FILE_DELETE, self.OnFileDelete)

I understand, but compare the above code with this:

>           menu.Append("&Delete", "Delete the file", action=self.OnFileDelete)
>           ....
>           toolbar.AddLabelTool("Delete", action=self.OnFileDelete)

Which is easier to understand at a glance?


[pardon the re-arrangement]

> You can also use id ranges in wxPython 2.5 which makes it easy to
> send a whole bunch of different items to the same handler.

Now _that's_ something you can actually point to as a "feature"
of the ID scheme.

-- 
Grant Edwards                   grante             Yow!  .. I want FORTY-TWO
                                  at               TRYNEL FLOATATION SYSTEMS
                               visi.com            installed within SIX AND A
                                                   HALF HOURS!!!



More information about the Python-list mailing list