xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #405: wxtray.py

File wxtray.py, 1.1 KB (added by Antoine Martin, 8 years ago)

simple wx tray example

Line 
1#!/usr/bin/env python
2
3import wx
4
5TRAY_TOOLTIP = 'System Tray Demo'
6TRAY_ICON = 'icon.png'
7
8
9def create_menu_item(menu, label, func):
10    item = wx.MenuItem(menu, -1, label)
11    menu.Bind(wx.EVT_MENU, func, id=item.GetId())
12    menu.AppendItem(item)
13    return item
14
15
16class TaskBarIcon(wx.TaskBarIcon):
17    def __init__(self):
18        super(TaskBarIcon, self).__init__()
19        self.set_icon(TRAY_ICON)
20        self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
21
22    def CreatePopupMenu(self):
23        menu = wx.Menu()
24        create_menu_item(menu, 'Say Hello', self.on_hello)
25        menu.AppendSeparator()
26        create_menu_item(menu, 'Exit', self.on_exit)
27        return menu
28
29    def set_icon(self, path):
30        icon = wx.IconFromBitmap(wx.Bitmap(path))
31        self.SetIcon(icon, TRAY_TOOLTIP)
32
33    def on_left_down(self, event):
34        print 'Tray icon was left-clicked.'
35
36    def on_hello(self, event):
37        print 'Hello, world!'
38
39    def on_exit(self, event):
40        wx.CallAfter(self.Destroy)
41
42
43def main():
44    app = wx.PySimpleApp()
45    TaskBarIcon()
46    app.MainLoop()
47
48
49if __name__ == '__main__':
50    main()