Adrian Castravete
Adrian Castravete

Reputation: 402

Macintosh wxPython EVT_TASKBAR_LEFT_UP or alternative

I'm trying to create a simple application that resides in the Notification area or Taskbar/System Tray area. I want it to be cross platform so that's why I'm using wxPython.

The application works well under Windows and Linux but under Macintosh it fails to show the main window when clicking the TaskbarIcon. I'm not bothered by the fact that the TaskbarIcon appears in the dock. It's just that my application doesn't work without this.

Here's 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 upped.'; right clicking prints 'Right upped.', then the application exits. On Macintosh left clicking on the icon doesn't do anything except flashing the icon; right clicking prints 'Right upped.', then the application exits.

Upvotes: 4

Views: 317

Answers (1)

Adrian Castravete
Adrian Castravete

Reputation: 402

As explained here there are several methods that one can override for certain actions available only on a mac.

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

For example just add this inside the class:

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

Just for completion, other methods are: MacOpenFile(self, filename), MacNewFile(self) and MacPrintFile(self, file_path)

Upvotes: 1

Related Questions