views:

527

answers:

1

How is it possible to add menu items to the system menu of a frame in wxPython/wxWidgets?
(I'm talking about the menu that appears when clicking on the application icon in Windows - the one with Minimize, Maximize, Close, ...).

I want to add a menu item of my own for a simple application that doesn't require a full blown top menu.

A Windows-only solution, if one exists (and is simple enough), would be useful too.

+1  A: 

I don't think wxWidgets/wxPython allows you to manipulate the system menu, with a few exceptions that are not sufficient for what you want:

  • You can remove the system menu by passing a style flag to the wx.Frame: style=wx.DEFAULT_FRAME_STYLE & ~wx.SYSTEM_MENU

  • On Mac OS X, menu items with ids such as wx.ID_EXIT and wx.ID_HELP are moved into the application menu.

I tried to bind the wx.EVT_MENU_OPEN event and although the event handler is invoked, the passed event doesn't contain anything useful on Windows. The code below prints 'None 0' when I open the Frame's system menu:

import wx

class Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Frame, self).__init__(*args, **kwargs)
        self.Bind(wx.EVT_MENU_OPEN, self.onMenuOpen)

    def onMenuOpen(self, event):
        print event.GetMenu(), event.GetMenuId()
        event.Skip()


app = wx.App(0)
frame = Frame(None)
frame.Show()
app.MainLoop()
Frank Niessink
You might want to change your answer re Mac OS X - it has no system menu in the way that Windows has. Help and quit menu items are moved to the Application menu, that's different. The closest to the system menu would be the menu that appears on the dock icon, and the access to that should be via wxTaskBarIcon.
mghie
Thanks, edited my answer.
Frank Niessink
Guess we will have to do with this being impossible... thanks.
Hexagon
@Hexagon: It is not impossible, but difficult and ugly. I could give you code how to add menu items to the Windows system menu, and I could give you a pointer on how to catch the menu commands and process them (for wxPython), but I don't know Python so I can't post a real answer to your question.
mghie