Use PREFIX in install rule.
[SysBars.git] / addedit.py
bloba4600c9d83c087baa2c6329c98f8dc8459000752
1 import gtk as g
3 from choices import settings
5 HSPACING = 4
6 VSPACING = 4
8 class Dialog(g.Dialog):
9 """ Base dialog for adding or editing a bar. """
10 def __init__(self, parent_win, add, desc, bar_w = None):
11 self.bar_w = bar_w
12 self.parent_win = parent_win
13 if add:
14 title = _("New %s bar") % self.get_type_name()
15 buttons = (g.STOCK_CANCEL, g.RESPONSE_CANCEL,
16 g.STOCK_OK, g.RESPONSE_OK)
17 self.instant_apply = False
18 else:
19 title = _("Edit %s bar") % self.get_type_name()
20 buttons = (g.STOCK_CLOSE, g.RESPONSE_CLOSE)
21 self.instant_apply = True
22 g.Dialog.__init__(self, title, parent_win,
23 g.DIALOG_MODAL | g.DIALOG_DESTROY_WITH_PARENT, buttons)
24 self.desc = desc
25 self.label_size_group = g.SizeGroup(g.SIZE_GROUP_HORIZONTAL)
26 self.set_default_response(g.RESPONSE_OK)
27 self.layout()
29 def get_type_name(self):
30 return _("?")
32 def make_label(self, label):
33 l = g.Label(label)
34 l.set_alignment(1, 0.5)
35 self.label_size_group.add_widget(l)
36 return l
38 def layout(self):
39 hbox = g.HBox(False)
41 hbox.pack_start(self.make_label(_("Label")) , False, True, HSPACING)
42 self.label_w = g.Entry()
43 if self.instant_apply:
44 l = self.desc.label
45 else:
46 l = self.get_default_label()
47 self.label_w.set_text(l)
48 self.label_w.set_activates_default(True)
49 hbox.pack_start(self.label_w, True, True, HSPACING)
50 self.vbox.pack_start(hbox, True, True, VSPACING)
52 hbox = g.HBox(False)
53 hbox.pack_start(self.make_label(_("Colour")) , False, True, HSPACING)
54 self.colour_w = g.ColorButton(self.desc.colour)
55 hbox.pack_start(self.colour_w, True, True, HSPACING)
56 self.vbox.pack_start(hbox, True, True, VSPACING)
58 hbox = g.HBox(False)
59 hbox.pack_start(self.make_label(_("Width")) , False, True, HSPACING)
60 self.width_w = g.SpinButton()
61 self.width_w.set_range(1, 640)
62 self.width_w.set_increments(1, 10)
63 self.width_w.set_value(self.desc.width)
64 self.width_w.set_activates_default(True)
65 hbox.pack_start(self.width_w, True, True, HSPACING)
66 self.vbox.pack_start(hbox, True, True, VSPACING)
68 hbox = g.HBox(False)
69 hbox.pack_start(self.make_label(_("Update every")) , False, True,
70 HSPACING)
71 self.min_period_w = g.SpinButton(digits = 1)
72 self.min_period_w.set_range(0.1, 10)
73 self.min_period_w.set_increments(0.1, 1)
74 self.min_period_w.set_value(self.desc.min_period)
75 self.min_period_w.set_activates_default(True)
76 hbox.pack_start(self.min_period_w, True, True, HSPACING)
77 hbox.pack_start(g.Label(_("to")) , False, False, HSPACING)
78 self.max_period_w = g.SpinButton(digits = 1)
79 self.max_period_w.set_range(0.1, 10)
80 self.max_period_w.set_increments(0.1, 1)
81 self.max_period_w.set_value(self.desc.max_period)
82 self.max_period_w.set_activates_default(True)
83 hbox.pack_start(self.max_period_w, True, True, HSPACING)
84 hbox.pack_start(g.Label(_("secs")) , False, False, HSPACING)
85 self.vbox.pack_start(hbox, True, True, VSPACING)
87 if self.instant_apply:
88 self.label_w.connect("changed", self.label_changed_cb)
89 self.colour_w.connect("color-set", self.colour_set_cb)
90 self.width_w.connect("value-changed", self.width_changed_cb)
91 self.min_period_w.connect("value-changed",
92 self.min_period_changed_cb)
93 self.max_period_w.connect("value-changed",
94 self.max_period_changed_cb)
96 self.layout_for_type()
98 def run_apply_destroy(self):
99 self.show_all()
100 response = self.run()
101 if response == g.RESPONSE_OK:
102 self.apply()
103 self.destroy()
104 return response
106 def get_default_label(self):
107 """ Override in derived classes """
108 return _("?")
110 def layout_for_type(self):
111 """ Override in derived classes """
112 pass
114 def apply(self):
115 """ Override to read additional settings for specific bar type;
116 don't forget to call this base method too. """
117 self.label_changed_cb()
118 self.colour_set_cb()
119 self.width_changed_cb()
120 self.min_period_changed_cb()
121 self.max_period_changed_cb()
123 def label_changed_cb(self, w = None):
124 self.desc.label = self.label_w.get_text()
125 settings.set_bar_label(self.desc.num, self.desc.label)
126 if self.instant_apply:
127 self.bar_w.set_caption(self.desc.label)
129 def colour_set_cb(self, w = None):
130 self.desc.colour = self.colour_w.get_color()
131 settings.set_bar_colour(self.desc.num, self.desc.colour)
132 if self.instant_apply:
133 self.bar_w.change_colour(self.desc.colour)
135 def width_changed_cb(self, w = None):
136 self.desc.width = self.width_w.get_value_as_int()
137 settings.set_bar_width(self.desc.num, self.desc.width)
138 if self.instant_apply:
139 self.bar_w.change_width(self.desc.width)
141 def min_period_changed_cb(self, w = None):
142 self.desc.min_period = self.min_period_w.get_value()
143 settings.set_bar_min_period(self.desc.num, self.desc.min_period)
144 # Don't change bar now, just let it get updated next tick
146 def max_period_changed_cb(self, w = None):
147 self.desc.max_period = self.max_period_w.get_value()
148 settings.set_bar_max_period(self.desc.num, self.desc.max_period)
149 # Don't change bar now, just let it get updated next tick