Gabriel Rossetti wrote:
If I create a menu item with the wx.ID_EXIT like so :
self.exitMenuItem = self.menu.Append(wx.ID_EXIT, "Exit")
it adds a menu item (it even replaces "Exit" with "Quit") but there also is
the default mac "Quit" menu item at the bottom. If I don't add it, and just
bind it :
self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
it works. The code ends up looking like :
#===========================================
class MyTaskBarIcon(wx.TaskBarIcon):
def __init__(self, *args, **kwargs):
wx.TaskBarIcon.__init__(self, *args, **kwargs)
self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
icon = wx.Icon("logo.png", wx.BITMAP_TYPE_PNG)
self.SetIcon(icon)
def CreatePopupMenu(self):
self.menu = wx.Menu()
if(wx.Platform == "__WXMAC__"):
wx.App.SetMacExitMenuItemId(wx.ID_EXIT)
else:
self.exitMenuItem = self.menu.Append(wx.ID_EXIT, "Exit")
return self.menu
def OnExit(self, evt):
print "OnExit called"
#===========================================
again, if you replace CreatePopupMenu() with this :
#===========================================
def CreatePopupMenu(self):
self.menu = wx.Menu()
self.exitMenuItem = self.menu.Append(wx.ID_EXIT, "Exit")
if(wx.Platform == "__WXMAC__"):
wx.App.SetMacExitMenuItemId(wx.ID_EXIT)
return self.menu
#===========================================
it will have 2 quit menus.
I suppose this is a bug in wx, but not a major one. I haven't done custom taskbar menus, so I hadn't encountered this yet.
Could you please add a note about this to the wiki on the Optimizing for Mac OS-X page? It would be nice for folks to be able to find this in the future.
(the wiki appears to be down at the moment, hopefully it will come back up soon.)
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov