Binding events of wx.MenuBar

Hi all,

I’d like to subclass wx.MenuBar, as bellow, and deal with all events on itself. In the examples I’ve seen of wx.MenuBar, however, the events were binded in the wx.Frame related to it, using wx.EVT_MENU.

Is there someway of binding events from wx.MenuBar on itself (not on its setting frame)? Which event should be used, if possible?

Thanks in advance,

Tatiana

···

ID_NEW = wx.NewId()

class MyMenuBar(wx.MenuBar):
def init(self):
wx.MenuBar.init(self)

    file_menu = wx.Menu()
    file_menu.Append(ID_NEW, "New")

    self.Bind(wx.EVT_MENU, self.OnNew, id=ID_NEW)

def OnNew(self, event):
    print "OnNew"

Tatiana Al-Chueyr Pereira Martins wrote:

Hi all,

I'd like to subclass wx.MenuBar, as bellow, and deal with all events on itself. In the examples I've seen of wx.MenuBar, however, the events were binded in the wx.Frame related to it, using wx.EVT_MENU.

Is there someway of binding events from wx.MenuBar on itself (not on its setting frame)? Which event should be used, if possible?

Unfortunately, no. IIRC there are some platform limitations in this area so wx always sends the menu selection events from the menubar directly to the frame. I know that there has been some effort in the past to try and change this, but I don't know off the top of my head if it has been done for 2.9 or not.

···

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

Thanks, Robin!
Best regards,
Tatiana

···

Tatiana Al-Chueyr Pereira Martins wrote:

Hi all,

I'd like to subclass wx.MenuBar, as bellow, and deal with all events on
itself. In the examples I've seen of wx.MenuBar, however, the events
were binded in the wx.Frame related to it, using wx.EVT_MENU.

Is there someway of binding events from wx.MenuBar on itself (not on its
setting frame)? Which event should be used, if possible?

Unfortunately, no. IIRC there are some platform limitations in this
area so wx always sends the menu selection events from the menubar
directly to the frame. I know that there has been some effort in the
past to try and change this, but I don't know off the top of my head if
it has been done for 2.9 or not.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!