duplicate quit menu items in mac os x task bar icon

Hello everyone,

I get two quit menu items on my taskbaricon even though I added only one.
I'd like to bind mac os x's quit button since it's at a standardized place and
that way I only have one quit button but I can figure out how. The only one
that works is the one I added. Does anyone know what's going on and how
to fix this? I using wxPython v2.8.10

Thank you,
Gabriel

Gabriel Rossetti wrote:

I get two quit menu items on my taskbaricon even though I added only one.

If you use the standard IDs for your menu items, etc, then wx should do "the right thing" on the Mac:

http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X

-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

Christopher Barker wrote:

Gabriel Rossetti wrote:
  

I get two quit menu items on my taskbaricon even though I added only one.
    
If you use the standard IDs for your menu items, etc, then wx should do "the right thing" on the Mac:

Optimizing for Mac OS X - wxPyWiki

-Chris

Ok, I tested if it was mac and if so then I don create the menu item but just link it to the event's id (wx.ID_EXIT), this works great.

Thanks,
Gabriel

Gabriel Rossetti wrote:

Ok, I tested if it was mac and if so then I don create the menu item but just link it to the event's id (wx.ID_EXIT), this works great.

That shouldn't be required -- if you use wx.ID_EXIT for the menu ID on all platforms, it should "just work".

Though if you have something working, why mess with it?

-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

Christopher Barker wrote:

Gabriel Rossetti wrote:
  

Ok, I tested if it was mac and if so then I don create the menu item but just link it to the event's id (wx.ID_EXIT), this works great.
    
That shouldn't be required -- if you use wx.ID_EXIT for the menu ID on all platforms, it should "just work".

Though if you have something working, why mess with it?

-Chris

Because it doesn't work. 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.

Gabriel

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

Gabriel Rossetti wrote:

         self.menu = wx.Menu()
         if(wx.Platform == "__WXMAC__"):
             wx.App.SetMacExitMenuItemId(wx.ID_EXIT)

This should not be needed, wx.ID_EXIT is already the default ID for the exit menu.

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.

The magical moving of the stock menu items on OS X is only done for the menubar. For other menus you'll still want to conditionally add items as needed to accommodate the platform differences.

···

On 10/1/09 2:16 PM, Christopher Barker wrote:

--
Robin Dunn
Software Craftsman

Hello,

This simple application crashes when the cursor gets on the window:
python26.exe - Application Error
The exception unknown software exception .... (etc. the usual message from Windows.

Here is the code:

···

************************
import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Title", size=(200, 200))
               self.panel = wx.Panel(self, -1)
        computeButton = wx.Button(self.panel, -1, "Compute") mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(computeButton, 0)
        mainSizer.Layout()
        self.panel.SetSizerAndFit(mainSizer)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop()
*************************

Using python 2.6.2 and wxPython 2.8.9.2. on Windows XP x64 Edition, SP2.

Thanks,

Raphael

Hi,

Hello,

This simple application crashes when the cursor gets on the window:
python26.exe - Application Error
The exception unknown software exception .... (etc. the usual message
from Windows.

Here is the code:

[...]

Using python 2.6.2 and wxPython 2.8.9.2. on Windows XP x64 Edition, SP2.

It works fine here. WinXP (32), Python 2.5.x, wxPython 2.8.x

HTH a little.

Cheers,
Scott.

···

On Mon, Oct 5, 2009 at 8:44 PM, Raphael Mayoraz <maygeo@netplus.ch> wrote:

Raphael Mayoraz wrote:

Hello,

This simple application crashes when the cursor gets on the window:
python26.exe - Application Error
The exception unknown software exception .... (etc. the usual
message from Windows.

[...]

Using python 2.6.2 and wxPython 2.8.9.2. on Windows XP x64
Edition, SP2.

This was fixed in wxPython 2.8.10.1 - upgrade and the problem should go
away.

Frank Millman

Yes, problem goes away in 2.8.10.1.

Thanks!!!

Raphael

Frank Millman wrote:

···

Raphael Mayoraz wrote:
  

Hello,

This simple application crashes when the cursor gets on the window:
python26.exe - Application Error
The exception unknown software exception .... (etc. the usual
message from Windows.

[...]
  

Using python 2.6.2 and wxPython 2.8.9.2. on Windows XP x64
Edition, SP2.

This was fixed in wxPython 2.8.10.1 - upgrade and the problem should go
away.

Frank Millman

>