updated on Thu Jan 12 16:09:17 UTC 2012
[aur-mirror.git] / traywbar / traywbar-0.1.py
blob465af63118fee75e069b7e4538ce72049707381b
1 #!/usr/bin/python2
2 # A GTKv2 status icon that sits in your tray and pops up a menu with the same selection of applications you already have configured for wbar
3 # Copyright 2011 Dan Serban
4 # Licensed under GPLv3
6 import os
7 import subprocess
8 import gtk
10 class TrayWbar:
11 def __init__(self):
12 self.status_icon = gtk.StatusIcon()
13 self.status_icon.set_from_stock(gtk.STOCK_HOME)
14 self.status_icon.set_visible(True)
15 self.status_icon.set_tooltip("TrayWbar")
16 self.status_icon.connect("activate", self.on_left_click)
17 self.status_icon.connect("popup-menu", self.on_right_click)
18 gtk.main()
20 def on_execute(self, widget, event, data):
21 subprocess.Popen(self.commands[data], shell=True)
23 def on_quit(self, widget, event):
24 gtk.main_quit()
26 def on_left_click(self, event):
27 with open(os.path.expanduser("~/.wbar"), "r") as wbarconfigfile:
28 lines = wbarconfigfile.readlines()
29 wbarconfigfile.close()
30 i = 0
31 self.names = []
32 self.commands = {}
33 for wbarconfigline in lines:
34 wbarconfigline = wbarconfigline.strip()
35 if wbarconfigline[:3] == "i: ":
36 i += 1
37 do_include = False
38 if wbarconfigline[:3] == "c: " and wbarconfigline[3:7] != "wbar":
39 self.commands[i] = wbarconfigline[3:]
40 do_include = True
41 if wbarconfigline[:3] == "t: " and do_include:
42 self.names.append((wbarconfigline[3:],i))
43 main_menu = gtk.Menu()
44 for wbar_entry in self.names:
45 main_menu_item = gtk.MenuItem(wbar_entry[0])
46 main_menu_item.connect("activate", self.on_execute, self.status_icon, wbar_entry[1])
47 main_menu.append(main_menu_item)
48 main_menu.show_all()
49 main_menu.popup(None, None, gtk.status_icon_position_menu, 1, gtk.get_current_event_time(), self.status_icon)
51 def on_right_click(self, button, time, data):
52 quit_menu = gtk.Menu()
53 quit_menu_item = gtk.MenuItem("Quit")
54 quit_menu_item.connect("activate", self.on_quit, self.status_icon)
55 quit_menu.append(quit_menu_item)
56 quit_menu.show_all()
57 quit_menu.popup(None, None, gtk.status_icon_position_menu, 1, gtk.get_current_event_time(), self.status_icon)
59 if __name__ == "__main__":
60 traywbar = TrayWbar()