newbie question on menus

Hi --

I'm new to wxPython, and so far, like it very much. I am having one
problem, however, with generating menus from a configuration file. I
have some code that looks like this.

···

----------------------------------------------------------------------
menu = wxMenu()
for item in mItems[heading]:
         ID = wxNewId()
         menu.Append(ID, item[0], '')
         EVT_MENU(self, ID, self.menuEvent)
----------------------------------------------------------------------
The menus are being generated fine. My problem is that self.menuEvent
doesn't know which menu item was clicked on. Is there some way to pass
the ID or some other data to self.menuEvent so it can tell which menu
item was selected? I'm using wxPython-2.4.

Thanks for any help. Sorry, if this has been answered already, but I
couldn't find it in the list archives.

Gary

if item[0] is the name then make item[1] the ID...

EVT_MENU(self, item[1], self.menuEvent)

and in self.menuEvent do something like

tList = [ item[0] for item in mItems[heading] if item[1] == evt.GetId()]
if len(tList) >0:
  itemName = tList[0]
else:
  itemName = None

or

itemName = None
for item in mItems[heading]:
  if item[1] == evt.GetId():
    itemName = item[0]

eventualy you can store a handling method item[2] and do something like:

for item in mItems[heading]:
  if item[1] == evt.GetId():
    item[2]()

···

On Sat, 17 Apr 2004 06:27:39 -0400, Gary Jaffe <gfj555@yahoo.com> wrote:

Hi --

I'm new to wxPython, and so far, like it very much. I am having one
problem, however, with generating menus from a configuration file. I
have some code that looks like this.
----------------------------------------------------------------------
menu = wxMenu()
for item in mItems[heading]:
         ID = wxNewId()
         menu.Append(ID, item[0], '')
         EVT_MENU(self, ID, self.menuEvent)
----------------------------------------------------------------------
The menus are being generated fine. My problem is that self.menuEvent
doesn't know which menu item was clicked on. Is there some way to pass
the ID or some other data to self.menuEvent so it can tell which menu
item was selected? I'm using wxPython-2.4.

Thanks for any help. Sorry, if this has been answered already, but I
couldn't find it in the list archives.

Gary

--
Peter Damoc
Hacker Wannabe
http://www.sigmacore.net/about.html

That worked great! Thanks.

Gary

···

On Sat, 17 Apr 2004 14:16:02 +0300 "Peter Damoc" <pdamoc@gmx.net> wrote:

On Sat, 17 Apr 2004 06:27:39 -0400, Gary Jaffe <gfj555@yahoo.com> > wrote:

> Hi --
>
> I'm new to wxPython, and so far, like it very much. I am having one
> problem, however, with generating menus from a configuration file.
> I have some code that looks like this.
> -------------------------------------------------------------------
> --- menu = wxMenu()
> for item in mItems[heading]:
> ID = wxNewId()
> menu.Append(ID, item[0], '')
> EVT_MENU(self, ID, self.menuEvent)
> -------------------------------------------------------------------
> --- The menus are being generated fine. My problem is that
> self.menuEvent doesn't know which menu item was clicked on. Is
> there some way to pass the ID or some other data to self.menuEvent
> so it can tell which menu item was selected? I'm using
> wxPython-2.4.
>
> Thanks for any help. Sorry, if this has been answered already, but
> I couldn't find it in the list archives.
>
> Gary

if item[0] is the name then make item[1] the ID...

EVT_MENU(self, item[1], self.menuEvent)

and in self.menuEvent do something like

tList = [ item[0] for item in mItems[heading] if item[1] ==
evt.GetId()] if len(tList) >0:
  itemName = tList[0]
else:
  itemName = None

or

itemName = None
for item in mItems[heading]:
  if item[1] == evt.GetId():
    itemName = item[0]

eventualy you can store a handling method item[2] and do something
like:

for item in mItems[heading]:
  if item[1] == evt.GetId():
    item[2]()

--
Peter Damoc
Hacker Wannabe
sigmacore.net