[wxPython-users] How to know what event IDs to use in menu?
Christopher Barker
Chris.Barker at noaa.gov
Mon Apr 23 10:29:09 PDT 2007
Phillip Stevens 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.
>> Here's the example from the tutorial:
The tutorial is pretty old -- we've come up with cleaner ways to write
code since then!
>> ID_ABOUT = 101
>> ID_EXIT = 102
This is the only exception to my "no explicit IDs" rule. It IS a good
idea to use pre-defined ids for standard items -- it lets wxMac put them
in the right place for that platform, for instance:
menu.Append(wx.ID_ABOUT, "&About",
"More information about this program")
menu.Append(wx.ID_EXIT, "E&xit", "Terminate the program")
Don't overwrite the wx-defined ones though! See the Wiki page about
porting to OS-X for more info.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list