如何使用wx在mac osx上设置菜单栏图标

时间:2021-12-23 07:11:39

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.

我找不到任何关于如何使用wx在OSX上创建菜单栏图标的指针。我原本以为wxTaskBarIcon类会这样做,但实际上它在Dock上创建了一个图标。在Windows上,wxTaskBarIcon创建一个Systray图标和相关的菜单,我认为在mac osx上它会创建一个菜单栏图标,我猜不会。

4 个解决方案

#1


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.

您必须将wxTaskBarIconType设置为STATUSITEM,而不是DOCK。用于此的Cocoa API是NSStatusBar和NSStatusItem;这是调用它们的wxWidgets中的代码。

#2


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.

WxPython的创建者Robin Dunn的这篇文章解释说,wxPython还不支持mac上的菜单栏图标。他们只支持Dock。

#3


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.

从wxPython 2.9.2.0开始,wx.TaskBarIcon现在将在OSX上创建一个菜单栏图标,只要你调用SetIcon即可。

#4


0  

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

wiki.wxpython.org上有一个示例,它在macOS菜单栏的“状态菜单”部分(右侧)放置一个图标(忽略页面标题):https://wiki.wxpython.org/Custom %20Mac%20OsX%20Dock%20巴%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).

它适用于macOS High Sierra(10.13.3)运行python 2.7.14(使用miniconda安装)和wxpython 3.0.0.0 osx-cocoa(经典)。

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

同样,它适用于python 3.6.4和wxpython 4.0.1 osx-cocoa(phoenix);需要修改小代码:

  • you must import wx.adv
  • 你必须导入wx.adv

  • wx.TaskBarIcon becomes wx.adv.TaskBarIcon
  • wx.TaskBarIcon成为wx.adv.TaskBarIcon

  • wx.IconFromBitmap becomes wx.Icon
  • wx.IconFromBitmap成为wx.Icon

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

这也会在其他平台上生成状态/通知/任务栏类型图标。

#1


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.

您必须将wxTaskBarIconType设置为STATUSITEM,而不是DOCK。用于此的Cocoa API是NSStatusBar和NSStatusItem;这是调用它们的wxWidgets中的代码。

#2


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.

WxPython的创建者Robin Dunn的这篇文章解释说,wxPython还不支持mac上的菜单栏图标。他们只支持Dock。

#3


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.

从wxPython 2.9.2.0开始,wx.TaskBarIcon现在将在OSX上创建一个菜单栏图标,只要你调用SetIcon即可。

#4


0  

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

wiki.wxpython.org上有一个示例,它在macOS菜单栏的“状态菜单”部分(右侧)放置一个图标(忽略页面标题):https://wiki.wxpython.org/Custom %20Mac%20OsX%20Dock%20巴%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).

它适用于macOS High Sierra(10.13.3)运行python 2.7.14(使用miniconda安装)和wxpython 3.0.0.0 osx-cocoa(经典)。

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

同样,它适用于python 3.6.4和wxpython 4.0.1 osx-cocoa(phoenix);需要修改小代码:

  • you must import wx.adv
  • 你必须导入wx.adv

  • wx.TaskBarIcon becomes wx.adv.TaskBarIcon
  • wx.TaskBarIcon成为wx.adv.TaskBarIcon

  • wx.IconFromBitmap becomes wx.Icon
  • wx.IconFromBitmap成为wx.Icon

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

这也会在其他平台上生成状态/通知/任务栏类型图标。