15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from gi.repository import GObject
19
from gi.repository import Gtk
41
39
last_selected = None
43
41
def __init__(self, homogeneous=False, spacing=6):
44
gtk.HBox.__init__(self, homogeneous, spacing)
42
super(SpanSelector, self).__init__(
43
homogeneous=homogeneous, spacing=spacing)
46
45
self.model = self._create_model()
47
46
self.combo = self._create_combobox(self.model)
48
47
self.entry = self._create_custom_entry()
50
label = gtk.Label("Highlighting spans:")
49
label = Gtk.Label(label="Highlighting spans:")
53
self.pack_start(label, expand=False, fill=True)
54
self.pack_start(self.combo, expand=False, fill=False)
55
self.pack_start(self.entry, expand=False, fill=False)
52
self.pack_start(label, False, True, True, 0)
53
self.pack_start(self.combo, False, False, True, 0)
54
self.pack_start(self.entry, False, False, True, 0)
57
56
def set_to_oldest_span(self, span):
58
57
"""Set the span associated with the "to Oldest Revision" entry."""
67
66
self.max_custom_spans = n
69
68
def activate(self, iter):
70
"""Activate the row pointed to by gtk.TreeIter iter."""
69
"""Activate the row pointed to by Gtk.TreeIter iter."""
71
70
index = self._get_index_from_iter(iter)
72
71
self.combo.set_active(index)
100
99
self.emit("span-changed", model.get_value(iter, SPAN_DAYS_COL))
102
101
def _activate_custom_span_cb(self, w):
103
self.entry.hide_all()
104
103
self.combo.show()
106
105
span = float(w.get_text())
137
136
def _create_model(self):
138
137
# [span in days, span as string, row is seperator?, row is select
140
m = gtk.ListStore(gobject.TYPE_FLOAT,
142
gobject.TYPE_BOOLEAN,
143
gobject.TYPE_BOOLEAN)
139
m = Gtk.ListStore(GObject.TYPE_FLOAT,
141
GObject.TYPE_BOOLEAN,
142
GObject.TYPE_BOOLEAN)
145
144
self.separator = [0., "", True, False]
159
158
def _create_combobox(self, model):
160
cb = gtk.ComboBox(model)
159
cb = Gtk.ComboBox(model)
161
160
cb.set_row_separator_func(
162
161
lambda m, i: m.get_value(i, SPAN_IS_SEPARATOR_COL))
163
cell = gtk.CellRendererText()
162
cell = Gtk.CellRendererText()
164
163
cb.pack_start(cell, False)
165
164
cb.add_attribute(cell, "text", SPAN_STR_COL)
166
165
cb.connect("changed", self._combo_changed_cb)
171
170
def _create_custom_entry(self):
172
entry = gtk.HBox(False, 6)
171
entry = Gtk.HBox(False, 6)
174
spin = gtk.SpinButton(digits=2)
173
spin = Gtk.SpinButton(digits=2)
175
174
spin.set_numeric(True)
176
175
spin.set_increments(1., 10.)
177
176
spin.set_range(0., 100 * 365) # I presume 100 years is sufficient
178
177
spin.connect("activate", self._activate_custom_span_cb)
179
178
spin.connect("show", lambda w: w.grab_focus())
181
label = gtk.Label("Days")
180
label = Gtk.Label(label="Days")
183
entry.pack_start(spin, expand=False, fill=False)
184
entry.pack_start(label, expand=False, fill=False)
182
entry.pack_start(spin, False, False, True, 0)
183
entry.pack_start(label, False, False, True, 0)
192
191
Callback signature: def callback(SpanSelector, span, [user_param, ...])
194
gobject.signal_new("span-changed", SpanSelector,
195
gobject.SIGNAL_RUN_LAST,
197
(gobject.TYPE_FLOAT,))
193
GObject.signal_new("span-changed", SpanSelector,
194
GObject.SignalFlags.RUN_LAST,
196
(GObject.TYPE_FLOAT,))
199
198
"""The "custom-span-added" signal is emitted after a custom span has been
200
199
added, but before it has been selected.
202
201
Callback signature: def callback(SpanSelector, span, [user_param, ...])
204
gobject.signal_new("custom-span-added", SpanSelector,
205
gobject.SIGNAL_RUN_LAST,
207
(gobject.TYPE_FLOAT,))
203
GObject.signal_new("custom-span-added", SpanSelector,
204
GObject.SignalFlags.RUN_LAST,
206
(GObject.TYPE_FLOAT,))