Macintosh wxPython EVT_TASKBAR_LEFT_UP or alternative

I am trying to create a simple application that is in the notification area or taskbar / system tray area. I want it to be cross platform, so I use wxPython.

The application works well under Windows and Linux, but under Macintosh it does not display the main window when you click TaskbarIcon. I'm not bothered by the fact that TaskbarIcon appears in the dock. It is just that my application does not work without this.

Here is some simplified code that can reproduce the problem:

from views import embimgs import wx class MyTaskBarIcon(wx.TaskBarIcon): def __init__(self, app): wx.TaskBarIcon.__init__(self) self.app = app self.Bind(wx.EVT_TASKBAR_LEFT_UP, self.on_left_up) self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.on_right_up) def on_left_up(self, evt): print 'Left upped!' def on_right_up(self, evt): print 'Right upped!' self.app.ExitMainLoop() def main(): app = wx.PySimpleApp() mti = MyTaskBarIcon(app) mti.SetIcon(wx.IconFromBitmap(embimgs.logo64.GetBitmap())) app.MainLoop() app.Destroy() if __name__ == '__main__': main() 

On Windows and Linux, left-clicking on the icon prints "Left up up."; Right-click β€œTop to Top”. Then the application terminates. On a Macintosh, left-clicking on an icon does nothing but blinking; right click up. Then the application terminates.

+4
source share
1 answer

As explained here, there are several methods that you can override for specific actions that are available only on mac.

In my case, I just needed to override the MacReopenApp method of the wx.App class. This method is called every time the user clicks the icon on the dock.

For example, just add this inside the class:

  def MacReopenApp(self): print 'Dock Icon clicked!' 

Other methods are used for completion: MacOpenFile (self, filename), MacNewFile (self) and MacPrintFile (self, file_path)

0
source

All Articles