xpra icon
Bug tracker and wiki

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


Ticket #280: eggtray2.py

File eggtray2.py, 1.1 KB (added by Antoine Martin, 9 years ago)

another test tray example using egg.trayicon

Line 
1#! /usr/bin/python
2# small script to put a logout icon in system tray
3# by Tunafish, july 2011
4#
5# parts taken from:
6# http://www.dangibbs.co.uk/journal/advanced-functionality-of-eggtrayicon
7
8import gtk, commands,os
9try:
10    import egg.trayicon
11except:
12    print "You need to install the python-eggtrayicon package"
13 
14class EggTrayIcon:
15    def __init__(self):
16        self.tray = egg.trayicon.TrayIcon("TrayIcon")
17 
18        eventbox = gtk.EventBox()
19        image = gtk.Image()
20        image.set_from_stock(gtk.STOCK_QUIT, gtk.ICON_SIZE_SMALL_TOOLBAR)
21 
22        eventbox.connect("button-press-event", self.icon_clicked)
23 
24        eventbox.add(image)
25        self.tray.add(eventbox)
26        self.tray.show_all()
27 
28    def icon_clicked(self, widget, event):
29        if event.button == 1:
30            print("button 1")
31   
32        if event.button == 3:
33            menu = gtk.Menu()
34            menuitem_exit = gtk.MenuItem("Exit")
35            menu.append(menuitem_exit)
36            menuitem_exit.connect("activate", lambda w: gtk.main_quit())
37            menu.show_all()
38            menu.popup(None, None, None, event.button, event.time, self.tray)
39 
40EggTrayIcon()
41gtk.main()