[wxPython-users] Re: How to know what event IDs to use in menu?
Robin Dunn
robin at alldunn.com
Mon Apr 23 13:10:27 PDT 2007
Grant Edwards wrote:
> On 2007-04-23, Christopher Barker <Chris.Barker at noaa.gov> wrote:
>
>>> For the reasons you mention about creating possible conflicts with
>>> ID's I have started using wx.NewID():
>> Better yet, don't use explicit IDs at all. (see the wxPython style guide
>> in the Wiki)
>
>
>> Menu items don't behave as well as everything else in this
>> regard, but you can do:
>>
>> item = menu1.Append(wx.ID_ANY, '&Open', 'Open')
>> # you do need to put SOMETHING in for an ID with menu items -- I use wx.ID_ANY, 'cause I think it says what I mean.
>>
>> self.Bind(wx.EVT_MENU, self.OnFileOpen, item)
>>
>> # you can specify the object that the event comes from, rather than the
>> # ID, I think this is cleaner.
>
> Yes, that's much cleaner. I haven't figured out how to use the
> use the wx.Menu.Bind() method instead of the "parent" Frame's
> Bind method. It seems to me that one ought to be telling the
> Menu object what handler to call and not the parent Frame, but
> that doesn't look like the way it's done.
Yes it makes more sense in theory, or even to bind directly to the menu
item since it is kinda like a widget, but in reality the menu item is
not involved in the sending of the event, it just holds the info about
the item. The menu is also not involved when the menu is attached to a
menubar, in that case the frame is the one that receives the event from
the platform, and it would take more work to make it appear to be coming
from the menu or the menu item.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list