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
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
)
20 def on_execute(self
, widget
, event
, data
):
21 subprocess
.Popen(self
.commands
[data
], shell
=True)
23 def on_quit(self
, widget
, event
):
26 def on_left_click(self
, event
):
27 with
open(os
.path
.expanduser("~/.wbar"), "r") as wbarconfigfile
:
28 lines
= wbarconfigfile
.readlines()
29 wbarconfigfile
.close()
33 for wbarconfigline
in lines
:
34 wbarconfigline
= wbarconfigline
.strip()
35 if wbarconfigline
[:3] == "i: ":
38 if wbarconfigline
[:3] == "c: " and wbarconfigline
[3:7] != "wbar":
39 self
.commands
[i
] = wbarconfigline
[3:]
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
)
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
)
57 quit_menu
.popup(None, None, gtk
.status_icon_position_menu
, 1, gtk
.get_current_event_time(), self
.status_icon
)
59 if __name__
== "__main__":