Changing wxMenu Text with no ID

Hello,

I would like to change the Text of a Menu in a Menubar. But there is a problem. When a wxMenu is usually created, no ID needs to be passed. When then that menu is appended to a menubar, no ID can be passed either. However, if I wanted to change the Label (or Text, what is the difference?) with the SetLabel() method, I need to pass an ID and the new text. Where can I get the ID from ?

peter

Peter Wurmsdobler wrote:

Hello,

I would like to change the Text of a Menu in a Menubar. But there is a problem. When a wxMenu is usually created, no ID needs to be passed. When then that menu is appended to a menubar, no ID can be passed either. However, if I wanted to change the Label (or Text, what is the difference?) with the SetLabel() method, I need to pass an ID and the new text. Where can I get the ID from ?

If you are not using nested menus, you can use MenuBar.FindMenuItem to get the ID. If the menu is nested you'll need to call FindMenuItem or FindMenu on the menubar, followed by a succession of GetSubMenu and FindItem calls on the returned MenuItems till you get the one you want. You may just want to pick up menufuncs.py from http://starship.python.net/crew/hochberg/. Then you can do:

GetMenuItem(myMenuBar, "MenuName", "SubMenuName", "ItemName").SetLabel("NewLabel)

Even if you don't want to use it, it will give you an example of using FindMenuItem and friends.

-tim

···

peter

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Tim,

thanks a lot, I will tak a look at your code.

It's funny though, in my opinion, that you can create something without any identifier, and if you want to change a property of it later, you need an identifier.
Shouldn't it rather work like

menu = wxMenu()
menu.SetLabel("Label")

or

ID = wxNewId()
menu = wxMenu(ID)
menu.SetLabel(ID,"Label")

peter

Peter Wurmsdobler wrote:

Tim,

thanks a lot, I will tak a look at your code.

It's funny though, in my opinion, that you can create something without any identifier, and if you want to change a property of it later, you need an identifier.
Shouldn't it rather work like

menu = wxMenu()
menu.SetLabel("Label")

or

ID = wxNewId()
menu = wxMenu(ID)
menu.SetLabel(ID,"Label")

It looks like I didn't read your original message closely enough. You want to change to title of the Menu in the menubar, not text in any of the submenus, is that right? In that case, you just want MenuBar.SetLabelTop(pos, label). This takes the positiion (0, 1, 2, ...) of the menu that you want to rename, not an ID.

Sorry for any confusion.

-tim

···

peter

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Tim,

It looks like I didn't read your original message closely enough. You want to change to title of the Menu in the menubar, not text in any of the submenus, is that right?

That's right. However, I also have some submenus to change.

In that case, you just want MenuBar.SetLabelTop(pos, label). This takes the positiion (0, 1, 2, ...) of the menu that you want to rename, not an ID.

So the problem is only shifted. I need to store something away which should come from the Object creation, or the object creation should ask for in the first place.

As I said, I think that the way how Labels of menus are changed is not consistent.
peter

Peter Wurmsdobler wrote:

Hello,

I would like to change the Text of a Menu in a Menubar. But there is a problem. When a wxMenu is usually created, no ID needs to be passed. When then that menu is appended to a menubar, no ID can be passed either. However, if I wanted to change the Label (or Text, what is the difference?) with the SetLabel() method, I need to pass an ID and the new text. Where can I get the ID from ?

You don't need it. To change the text of an item in a menubar you use SetLabelTop and you pass it a position, not an ID.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin,

You don't need it. To change the text of an item in a menubar you use SetLabelTop and you pass it a position, not an ID.

Is there a reason why Top level menus are treated differently?
Is there a reason why wxMenus do not need an ID ?

Maybe it is due to dockable menubars?
peter

Peter Wurmsdobler wrote:

Robin,

You don't need it. To change the text of an item in a menubar you use SetLabelTop and you pass it a position, not an ID.

Is there a reason why Top level menus are treated differently?
Is there a reason why wxMenus do not need an ID ?

I don't know. It may be a historical holdover from wxWindows 1.x...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!