6

I could not find any pointers on how to create a menubar icon on OSX using wx. I originally thought that the wxTaskBarIcon class would do, but it actually creates an icon on the Dock. On Windows, wxTaskBarIcon creates a Systray icon and associated menu, and I would think that on mac osx it would create a menubar icon, I guess not.

Dprado
  • 1,610
  • 1
  • 13
  • 13

4 Answers4

4

You have to set wxTaskBarIconType to STATUSITEM, not DOCK. The Cocoa APIs for this are NSStatusBar and NSStatusItem; here's the code in wxWidgets that calls to them.

Sören Kuklau
  • 19,454
  • 7
  • 52
  • 86
2

This post by Robin Dunn, the creator of wxPython, explains that wxPython doesn't support menubar icons on mac yet. They only support the Dock.

Rabarberski
  • 23,854
  • 21
  • 74
  • 96
1

As of wxPython 2.9.2.0 wx.TaskBarIcon will create a menubar icon now instead on OSX, so long as you call SetIcon.

GP89
  • 6,600
  • 4
  • 36
  • 64
1

There is an example on wiki.wxpython.org that puts an icon in the "status menus" section (right-hand side) of the macOS menu bar (ignore the page title): https://wiki.wxpython.org/Custom%20Mac%20OsX%20Dock%20Bar%20Icon

It works for me with macOS High Sierra (10.13.3) running python 2.7.14 (installed using miniconda) with wxpython 3.0.0.0 osx-cocoa (classic).

Similarly, it works with python 3.6.4 and wxpython 4.0.1 osx-cocoa (phoenix); minor code changes required:

  • you must import wx.adv
  • wx.TaskBarIcon becomes wx.adv.TaskBarIcon
  • wx.IconFromBitmap becomes wx.Icon

This generates a status/notification/taskbar-type icon on other platforms as well.

Generic Ratzlaugh
  • 717
  • 1
  • 6
  • 13