wxPython cross platform taskbar

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dirvine

    #1

    wxPython cross platform taskbar

    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.F rame):
    def __init__(self, parent, id, title):
    wx.Frame.__init __(self, parent, -1, title, size = (1, 1),
    style=wx.FRAME_ NO_TASKBAR|wx.N O_FULL_REPAINT_ ON_RESIZE)
    self.tbicon = wx.TaskBarIcon( )
    icon = wx.Icon('yellow .ico', wx.BITMAP_TYPE_ ICO)
    self.tbicon.Set Icon(icon, '')
    #wx.EVT_TASKBAR _LEFT_DCLICK(se lf.tbicon,
    self.OnTaskBarL eftDClick)
    #wx.EVT_TASKBAR _RIGHT_UP(self. tbicon, self.OnTaskBarR ightClick)
    self.tbicon.Bin d(wx.EVT_TASKBA R_LEFT_DCLICK,
    self.OnTaskBarL eftDClick)
    self.tbicon.Bin d(wx.EVT_TASKBA R_RIGHT_UP,
    self.OnTaskBarR ightClick)
    self.Bind(wx.EV T_TIMER, self.BlinkIcon, id=ID_ICON_TIME R)
    self.Show(True)

    def OnTaskBarLeftDC lick(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.Set Icon(icon, 'Yellow')
    ICON_STATE = 0
    else:
    self.SetIconTim er()
    ICON_STATE = 1

    def OnTaskBarRightC lick(self, evt):
    try:
    self.icontimer. Stop()
    except:
    pass
    self.tbicon.Des troy()
    self.Close(True )
    wx.GetApp().Pro cessIdle()
    #def OnTaskBarRightC lick(self, evt):
    # self.Close(True )
    # wx.GetApp().Pro cessIdle()

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

    def BlinkIcon(self, evt):
    global BLINK_STATE
    if BLINK_STATE == 0:
    icon = wx.Icon('red.ic o', wx.BITMAP_TYPE_ ICO)
    self.tbicon.Set Icon(icon, 'Red')
    BLINK_STATE = 1
    else:
    icon = wx.Icon('black. ico', wx.BITMAP_TYPE_ ICO)
    self.tbicon.Set Icon(icon, 'Black')
    BLINK_STATE = 0

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

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

    if __name__ == '__main__':
    main()

Working...