wxPython cross platform taskbar

dirvine irvine.david at gmail.com
Wed Mar 8 07:31:21 EST 2006


Hi All

Does anyone have any peice of wxPython code thats cross platform and
allows an app to be minimised in the system tray. I am hoping for
windows/kde/gnome/darwin if possible. I have been playing about and
have a couple of systems that nearly get there but not quite.

I would llike to create an app that does this in the way limewire/skype
etc. do it

Hope you can help
David

Heres sample code that nearly gets there I think - it appears to work
on ubuntu/gnome

import wx

ICON_STATE = 0
BLINK_STATE = 0

ID_ICON_TIMER = wx.NewId()

class TaskBarApp(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, -1, title, size = (1, 1),
            style=wx.FRAME_NO_TASKBAR|wx.NO_FULL_REPAINT_ON_RESIZE)
        self.tbicon = wx.TaskBarIcon()
        icon = wx.Icon('yellow.ico', wx.BITMAP_TYPE_ICO)
        self.tbicon.SetIcon(icon, '')
        #wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon,
self.OnTaskBarLeftDClick)
        #wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarRightClick)
        self.tbicon.Bind(wx.EVT_TASKBAR_LEFT_DCLICK,
self.OnTaskBarLeftDClick)
        self.tbicon.Bind(wx.EVT_TASKBAR_RIGHT_UP,
self.OnTaskBarRightClick)
        self.Bind(wx.EVT_TIMER, self.BlinkIcon, id=ID_ICON_TIMER)
        self.Show(True)

    def OnTaskBarLeftDClick(self, evt):
        global ICON_STATE
        try:
            self.icontimer.Stop()
        except:
            pass
        if ICON_STATE == 1:
            icon = wx.Icon('yellow.ico', wx.BITMAP_TYPE_ICO)
            self.tbicon.SetIcon(icon, 'Yellow')
            ICON_STATE = 0
        else:
            self.SetIconTimer()
            ICON_STATE = 1

    def OnTaskBarRightClick(self, evt):
        try:
            self.icontimer.Stop()
        except:
            pass
        self.tbicon.Destroy()
        self.Close(True)
        wx.GetApp().ProcessIdle()
    #def OnTaskBarRightClick(self, evt):
    #    self.Close(True)
    #    wx.GetApp().ProcessIdle()

    def SetIconTimer(self):
        self.icontimer = wx.Timer(self, ID_ICON_TIMER)
        wx.EVT_TIMER(self, ID_ICON_TIMER, self.BlinkIcon)
        self.icontimer.Start(1000)

    def BlinkIcon(self, evt):
        global BLINK_STATE
        if BLINK_STATE == 0:
            icon = wx.Icon('red.ico', wx.BITMAP_TYPE_ICO)
            self.tbicon.SetIcon(icon, 'Red')
            BLINK_STATE = 1
        else:
            icon = wx.Icon('black.ico', wx.BITMAP_TYPE_ICO)
            self.tbicon.SetIcon(icon, 'Black')
            BLINK_STATE = 0

class MyApp(wx.App):
    def OnInit(self):
        frame = TaskBarApp(None, -1, ' ')
        frame.Center(wx.BOTH)
        frame.Show(False)
        return True

def main():
    app = MyApp(0)
    app.MainLoop()

if __name__ == '__main__':
    main()




More information about the Python-list mailing list