XRC, wxMenuBar's, and wxMenuBarPtr's

M

Mark Moss

I have an XRC file that contains a complete menubar. I load this
menubar into a frame with:

self.ResMenu = wxXmlResource("menus.xrc",0)
self.MenuBar = self.ResMenu.LoadMenuBar("MenuBarEditor")
self.SetMenuBar(self.MenuBar)

Then set up a menu event handler:

EVT_MENU(self, XRCID("MenuItemSnapToGrid"), self.OnSnapToGrid)

Finally, in OnSnapToGrid, I try to get a specific wxMenuItem by using
the wxMenuBar.FindItem:

m = self.MenuBar.FindItem(XRCID("MenuItemSnapToGrid"))

This falls flat on its face because:

AttributeError: wxMenuBarPtr instance has no attribute 'FindItem'

It seems that LoadMenuBar returns a wxMenuBarPtr rather than a
wxMenuBar. My question then is given a wxMenuBarPtr and the ID of the
menu-item (via XRCID), how do I get ahold of the wxMenuItem object?
Alternativly, is there a way to check/uncheck a wxMenuItem without
having a reference to the actual object (using the id or similar)?

Thanks in advance,

Mark Moss
 
L

Lukasz Pankowski

Hi,

wxMenuBarPtr has FindItemById so

m = self.MenuBar.FindItemById(XRCID("MenuItemSnapToGrid"))

should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top