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 | |
---|
8 | import gtk, commands,os |
---|
9 | try: |
---|
10 | import egg.trayicon |
---|
11 | except: |
---|
12 | print "You need to install the python-eggtrayicon package" |
---|
13 | |
---|
14 | class 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 | |
---|
40 | EggTrayIcon() |
---|
41 | gtk.main() |
---|