Menu item calllback does not work

Hello again,

I created a menubar, but the callback does not seem to be called. What is wrong with the following test code. (I am using Python 2.2, WxPython 2.4-2.2, on a Mandrake 9.0).
Thanks a lot for any hint !

#!/usr/bin/env python

from wxPython.wx import *

class CMenuBar(wxMenuBar):
     def __init__ (self,parent):
         wxMenuBar.__init__(self)

         menu = wxMenu()
         ID = wxNewId()
         menu.Append(ID,"Exit","Exit Application")
         self.Append(menu, "File")
         EVT_MENU(self,ID, self.OnExit)

         parent.SetMenuBar(self)

     def OnExit(self,event):
         print "Exit"

class CAppl(wxFrame):
     def __init__ (self, *args, **kwds):
         kwds["style"] = wxDEFAULT_FRAME_STYLE
         wxFrame.__init__ (self, *args, **kwds)

         # Menu Bar
         self.MenuBar = CMenuBar(self)

         self.Layout()

class Cdm(wxApp):
     def OnInit(self):
         wxInitAllImageHandlers()

         self.Appl = CAppl (None, -1, "Application")

         self.SetTopWindow (self.Appl)
         self.Appl.Show (1)

         return True

if __name__ == "__main__":
     dm = Cdm()
     dm.MainLoop()

Change EVT_MENU(.... to this
EVT_MENU(parent,ID, self.OnExit)

···

Op do 24-07-2003, om 14:48 schreef Peter Wurmsdobler:

Hello again,

I created a menubar, but the callback does not seem to be called. What
is wrong with the following test code. (I am using Python 2.2, WxPython
2.4-2.2, on a Mandrake 9.0).
Thanks a lot for any hint !

#!/usr/bin/env python

from wxPython.wx import *

class CMenuBar(wxMenuBar):
     def __init__ (self,parent):
         wxMenuBar.__init__(self)

         menu = wxMenu()
         ID = wxNewId()
         menu.Append(ID,"Exit","Exit Application")
         self.Append(menu, "File")
         EVT_MENU(self,ID, self.OnExit)

         parent.SetMenuBar(self)

     def OnExit(self,event):
         print "Exit"

class CAppl(wxFrame):
     def __init__ (self, *args, **kwds):
         kwds["style"] = wxDEFAULT_FRAME_STYLE
         wxFrame.__init__ (self, *args, **kwds)

         # Menu Bar
         self.MenuBar = CMenuBar(self)

         self.Layout()

class Cdm(wxApp):
     def OnInit(self):
         wxInitAllImageHandlers()

         self.Appl = CAppl (None, -1, "Application")

         self.SetTopWindow (self.Appl)
         self.Appl.Show (1)

         return True

if __name__ == "__main__":
     dm = Cdm()
     dm.MainLoop()

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

Jonas,

Change EVT_MENU(.... to this
EVT_MENU(parent,ID, self.OnExit)

Thanks a lot, now it works !
peter

Peter Wurmsdobler wrote:

Jonas,

Change EVT_MENU(.... to this
EVT_MENU(parent,ID, self.OnExit)

Thanks a lot, now it works !

Just to give some more info about this, the events from menubars are delivered to the frame they are attached to. There has been talk about posisbly changing this so they go to the menubar first, but if that happens it will only be in 2.5 and beyond.

···

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