Removed (s) from Author label.
[SysBars.git] / setofbars.py
blob6ffb1ef31e3834dd45048910308ba0822fc47e3c
1 import os
3 import pango
4 import gtk as g
6 import barwidget
7 import compat
8 from choices import settings
9 import choicesui
10 import plugins
12 SPACING = 1
13 PADDING = 1
15 class SetOfBarsBase(object):
16 def __init__(self, orient = barwidget.VERT, length = -1):
17 self.box = None
18 self.layout(orient, length)
19 self.connect("button-release-event", self.click_release_cb)
21 def layout(self, orient, length = -1):
22 if self.box:
23 self.box.destroy()
24 self.orient = orient
25 self.length = length
26 if orient == barwidget.VERT:
27 self.box = g.HBox(True, SPACING)
28 else:
29 self.box = g.VBox(True, SPACING)
30 self.bars = []
31 for n in range(settings.get_num_bars()):
32 self.add_bar(n)
33 self.add(self.box)
34 self.box.show()
36 def repack(self, orient = None, length = None):
37 if orient == None:
38 orient = self.orient
39 if length == None:
40 length = self.length
41 self.box.destroy()
42 self.layout(orient, length)
44 def update_label_font(self, font_name = None):
45 if not font_name:
46 font_name = settings.get_label_font()
47 pfd = pango.FontDescription(font_name)
48 for b in self.bars:
49 b.modify_font(pfd)
51 def update_overlap(self, overlap):
52 for b in self.bars:
53 b.update_overlap(overlap)
55 def add_bar(self, num):
56 desc = plugins.all_descs[num]
57 pfd = pango.FontDescription(settings.get_label_font())
58 b = barwidget.BarWidget(desc, self.orient, desc.label,
59 settings.get_overlap(), pfd, self.length)
60 self.bars.append(b)
61 self.box.pack_start(b, True, True, PADDING)
62 b.show_all()
64 def click_release_cb(self, widget, event):
65 if (event.button == 1):
66 choicesui.run_dialog(self)
67 return True
68 return False
70 def run_choices_dialog(self, *args):
71 choicesui.run_dialog(self)
73 def get_bar_widget(self, num):
74 return self.bars[num]
77 class SetOfBars(g.EventBox, SetOfBarsBase):
78 def __init__(self, orient = barwidget.VERT, length = -1,
79 menu_pos_func = None):
80 g.EventBox.__init__(self)
81 SetOfBarsBase.__init__(self, orient, length)
82 self.connect("button-press-event", self.menu_button_cb)
84 def menu_button_cb(self, widget, event):
85 if (event.button == 3):
86 menu = g.Menu()
87 i = g.ImageMenuItem(g.STOCK_ABOUT)
88 i.connect("activate", show_about)
89 menu.append(i)
90 i = g.ImageMenuItem(g.STOCK_PREFERENCES)
91 i.connect("activate", self.run_choices_dialog)
92 menu.append(i)
93 i = g.ImageMenuItem(g.STOCK_QUIT)
94 i.connect("activate", compat.quit)
95 menu.append(i)
96 menu.show_all()
97 menu.popup(None, None, self.menu_pos_func, event.button, event.time)
98 return True
99 return False
102 logo = None
103 authors = None
104 version = None
107 def show_about(*args):
108 global logo, authors, version
109 if not authors and not version:
110 authors, version = compat.get_app_info()
111 if not authors:
112 authors = "Tony Houghton"
113 if not logo:
114 logo = compat.get_logo(64)
115 d = g.AboutDialog()
116 d.set_name("SysBars")
117 if version:
118 d.set_version(version)
119 d.set_copyright("\302\251 Tony Houghton")
120 d.set_website('http://www.realh.co.uk')
121 d.set_authors([authors])
122 d.set_logo(logo)
123 d.run()
124 d.destroy()