Added a Zero Install feed.
[SysBars/tal.git] / setofbars.py
blob2dde18ee1cb88684a65cded1e699bd6ab18fa965
1 import os
3 import pango
5 import rox
6 from rox import g
7 import rox.AppInfo
9 import barwidget
10 from choices import settings
11 import choicesui
12 import plugins
14 BGAP = 1 # Between each bar
15 LGAP = 2 # Between label and bar
17 class SetOfBars(g.EventBox):
18 def __init__(self, orient = barwidget.VERT, length = -1,
19 menu_pos_func = None):
20 g.EventBox.__init__(self)
21 self.menu_pos_func = menu_pos_func
22 self.layout(orient, length)
23 self.connect("button-press-event", self.button_cb)
24 self.connect("button-release-event", self.button_cb)
26 def layout(self, orient, length = -1):
27 self.orient = orient
28 self.length = length
29 if orient == barwidget.VERT:
30 self.box = g.HBox(False, BGAP)
31 self.SubBox = g.VBox
32 self.pack = g.VBox.pack_end
33 else:
34 self.box = g.VBox(False, BGAP)
35 self.SubBox = g.HBox
36 self.pack = g.HBox.pack_start
38 self.labels = []
39 self.bars = []
41 for n in range(settings.get_num_bars()):
42 self.add_bar(n)
44 self.add(self.box)
45 self.box.show()
47 def repack(self, orient = None, length = None):
48 if orient == None:
49 orient = self.orient
50 if length == None:
51 length = self.length
52 self.box.destroy()
53 self.layout(orient, length)
55 def update_label_font(self, font_name = None):
56 if not font_name:
57 font_name = settings.get_label_font()
58 pfd = pango.FontDescription(font_name)
59 for l in self.labels:
60 l.modify_font(pfd)
62 def add_bar(self, num):
63 desc = plugins.all_descs[num]
64 sub_box = self.SubBox(False, LGAP)
65 l = g.Label(desc.label)
66 pfd = pango.FontDescription(settings.get_label_font())
67 l.modify_font(pfd)
68 self.pack(sub_box, l, False, True, 0)
69 self.labels.append(l)
70 b = barwidget.BarWidget(desc, self.orient, self.length)
71 self.pack(sub_box, b, True, True, 0)
72 self.bars.append(b)
73 self.box.add(sub_box)
74 sub_box.show_all()
76 def button_cb(self, widget, event):
77 if event.type == g.gdk.BUTTON_RELEASE and event.button == 1:
78 choicesui.run_dialog(self)
79 elif event.type == g.gdk.BUTTON_PRESS and event.button == 3:
80 menu = g.Menu()
81 i = g.ImageMenuItem(g.STOCK_ABOUT)
82 i.connect("activate", show_about)
83 menu.append(i)
84 i = g.ImageMenuItem(g.STOCK_PREFERENCES)
85 i.connect("activate", self.run_choices_dialog)
86 menu.append(i)
87 i = g.ImageMenuItem(g.STOCK_QUIT)
88 i.connect("activate", quit)
89 menu.append(i)
90 menu.show_all()
91 menu.popup(None, None, self.menu_pos_func, event.button, event.time)
93 def run_choices_dialog(self, item):
94 choicesui.run_dialog(self)
96 def get_bar_widget(self, num):
97 return self.bars[num]
99 def get_label_widget(self, num):
100 return self.labels[num]
103 logo = None
104 authors = None
105 version = None
108 def show_about(item):
109 global logo, authors, version
110 if not authors and not version:
111 app_info = rox.AppInfo.AppInfo(os.path.join(rox.app_dir, 'AppInfo.xml'))
112 authors = app_info.getAuthors()
113 version = \
114 app_info.findElements('Version')[0].firstChild.nodeValue.split()[0]
115 if not authors:
116 authors = "Tony Houghton"
117 if not logo:
118 logo = g.gdk.pixbuf_new_from_file_at_size( \
119 os.path.join(rox.app_dir, '.DirIcon'), 64, 64)
120 d = g.AboutDialog()
121 d.set_name("SysBars")
122 if version:
123 d.set_version(version)
124 d.set_copyright("\302\251 Tony Houghton")
125 d.set_website('http://www.realh.co.uk')
126 d.set_authors([authors])
127 d.set_logo(logo)
128 d.run()
129 d.destroy()
132 def quit(item):
133 rox.toplevel_unref()
134 g.main_quit()