Is it possible that the automatic assignment of IDs is failing? If all the menu items have the same ID would that explain why all of their events kick off when I select any of them?
For a hoot I tried manually assigning IDs (actually, 12345, 12346, 12347…). Nothing squawks but no events launch when I select the items…
- rrue
Subject:
Re: [wxpython-users] Re: Newbie question re:wxMenuBar events
From:
Mike Driscoll mdriscoll@co.marshall.ia.us
Date:
Wed, 07 May 2008 15:48:23 -0500
To:
wxpython-users@lists.wxwidgets.org
···
Randy Rue wrote:
In the wxGlade dialog for editing menu items there is an “id” field for items. I had left it blank and I believe that’s why each item had an id of “-1” (I think this prompts the code to auto-assign some id to these objects). On the guess that this “id” field might actually name that menu choice (i.e. you might have a button called enable_ssl_button that kicks off a function called enable_ssl), I entered an id (“close_cw_menu_item”) for the close_cw menu item. Then when I generate code, running it returns a squawk "NameError: global name ‘close_cw_menu_item’ is not defined…
The “-1” is pretty much equivalent to wx.ID_ANY, which means what you say, namely that wx will “randomly” choose an unused id for the control and manage the ids in such a way that there won’t be any collisions. You can specify you’re own ids, but they need to be above some number, which I currently do not recall.
However, looking at the WIA book, it seems you can use wx.RegisterId() to prevent wx from using your explicitly assigned id. The book also mentions that you should not use ID numbers between wx.ID_LOWEST and wx.ID_HIGHEST. Kind of vague, but that should help you some.
As for the error you get, that would be caused because you didn’t define “close_cw_menu_item” earlier in the code. If you had done this:
close_cw_menu_item = wx.ID_ANY # or 12345 or some other number
then it would have worked.
Mike