TrayIcon with wxWidgets

Example Code

trayicontest.py
import wx
import sys
 
ICON = [ "16 16 75 1",  "  c #A55E02", ". c #A65E02", "X c #A75F03", "o c #A96002", "O c #A86003",
         "+ c #AA6103", "@ c #AB6203", "# c #AC6303", "$ c #AE6503", "% c #AE6404", "& c #B26603",
         "* c #B06504", "= c #B36804", "- c #B36904", "; c #B56904", ": c #B66B04", "> c #B76B05",
         ", c #B96C05", "< c #BA6C05", "1 c #BB6E05", "2 c #BC6E05", "3 c #BD6F05", "4 c #BE7005",
         "5 c #BF7106", "6 c #C07105", "7 c #C07205", "8 c #C17305", "9 c #C27306", "0 c #C47508",
         "q c #C77909", "w c #C8790A", "e c #C97C0A", "r c #CB7F0B", "t c #CC7F0A", "y c #CD820B",
         "u c #CD830B", "i c #D0860B", "p c #D0870B", "a c #D38A0B", "s c #D38A0C", "d c #D58F0C",
         "f c #D68F0D", "g c #D8930D", "h c #D8940D", "j c #DB970E", "k c #DB980D", "l c #DE9C0E",
         "z c #DE9C0F", "x c #ED9F12", "c c #E1A10F", "v c #E4A40F", "b c #E6A80F", "n c #E4A410",
         "m c #E5A810", "M c #E8AB11", "N c #E8AC10", "B c #EAAE10", "V c #EAAE11", "C c #EBB011",
         "Z c #EEA521", "A c #EFAB30", "S c #F0B03E", "D c #F1B64D", "F c #F2BC5B", "G c #F3C36A",
         "H c #F4C979", "J c #F6CF88", "K c #F7D497", "L c #F8DAA6", "P c #F9E1B5", "I c #FBE7C4",
         "U c #FCEDD2", "Y c #FDF3E1", "T c #FEF9F0", "R c gray100",
         "CBNmncljgdaiyteq", "VRRRRRRRRRRRRRR0", "MRRRRRRRRRRRRRR9", "bRLxSRYxxRRRRRR7",
         "vRHxGRPxSRRRRRR5", "cRDxKRJxFRYIRRR3", "zRxxIRDxFZxxxKR1", "kUxxRRZxDSHDxxR,",
         "hIxxTKxZRRRLxxR:", "fTZxxxxJRIxxxKR-", "sRLAxxHRRYJFxZR&", "pRRRRRRRPURKxxU$",
         "uRRRRRRRJxxxxSR#", "rRRRRRRRUJDHLRR+", "eRRRRRRRRRRRRRRO", "w8642<>;=*%@oX ." ]
 
 
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()
        self.tbicon.SetIcon(wx.IconFromXPMData(ICON), "U3Runner")
 
        self.tbmenu = wx.Menu("U3Runner", 0)
        self.tbmenu.AppendCheckItem(0, "checkitem this out", "dont know how to use it")
 
        wx.EVT_TASKBAR_LEFT_UP(self.tbicon, self.clickMenu)
 
        self.Show(True)
 
    def clickMenu(self, event):
        self.tbicon.PopupMenu(self.tbmenu)
        print("Hello, click again!")
        pass
 
 
class U3Runner(wx.App):
    def OnInit(self):
        frame = TaskBarApp(None, -1, ' ')
        frame.Center(wx.BOTH)
        frame.Show(False)
        return True
 
def _main(argv=None):
    if argv is None:
        argv = sys.argv
    app = U3Runner(0)
    app.MainLoop()
 
if __name__ == '__main__':
    try:
        import psyco
        psyco.full()
    except ImportError:
        pass
    _main()

This one adds a TrayIcon using the U3™ logo and also provides a context menu upon left click on the icon.


 
snippets/python/trayicon-wxwidgets.txt · Last modified: 2010-01-15 14:36.11 by mbirth
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA