bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
1 |
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
|
2 |
||
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
||
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
||
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
18 |
from gi.repository import GObject |
19 |
from gi.repository import Gtk |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
20 |
|
21 |
||
22 |
(
|
|
23 |
SPAN_DAYS_COL, |
|
24 |
SPAN_STR_COL, |
|
25 |
SPAN_IS_SEPARATOR_COL, |
|
26 |
SPAN_IS_CUSTOM_COL
|
|
27 |
) = range(4) |
|
28 |
||
29 |
||
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
30 |
class SpanSelector(Gtk.HBox): |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
31 |
"""Encapsulates creation and functionality of widgets used for changing |
32 |
highlight spans.
|
|
724
by Jelmer Vernooij
Fix formatting, imports. |
33 |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
34 |
Note that calling any activate_* methods will emit "span-changed".
|
35 |
"""
|
|
724
by Jelmer Vernooij
Fix formatting, imports. |
36 |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
37 |
max_custom_spans = 4 |
0.1.14
by Dan Loda
Remember custom spans across sessions. |
38 |
custom_spans = [] |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
39 |
last_selected = None |
40 |
||
41 |
def __init__(self, homogeneous=False, spacing=6): |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
42 |
GObject.GObject.__init__(self, homogeneous, spacing) |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
43 |
|
44 |
self.model = self._create_model() |
|
45 |
self.combo = self._create_combobox(self.model) |
|
46 |
self.entry = self._create_custom_entry() |
|
47 |
||
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
48 |
label = Gtk.Label(label="Highlighting spans:") |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
49 |
label.show() |
50 |
||
734.1.8
by Curtis Hovey
pass all the required args to pack_start(). |
51 |
self.pack_start(label, False, True, True, 0) |
52 |
self.pack_start(self.combo, False, False, True, 0) |
|
53 |
self.pack_start(self.entry, False, False, True, 0) |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
54 |
|
55 |
def set_to_oldest_span(self, span): |
|
56 |
"""Set the span associated with the "to Oldest Revision" entry.""" |
|
57 |
self.model.set_value(self.oldest_iter, SPAN_DAYS_COL, span) |
|
58 |
||
59 |
def set_newest_to_oldest_span(self, span): |
|
60 |
"""Set the span associated with the "Newest to Oldset" entry.""" |
|
61 |
self.model.set_value(self.newest_iter, SPAN_DAYS_COL, span) |
|
62 |
||
63 |
def set_max_custom_spans(self, n): |
|
64 |
"""Store up to n custom span entries in the combo box.""" |
|
65 |
self.max_custom_spans = n |
|
66 |
||
67 |
def activate(self, iter): |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
68 |
"""Activate the row pointed to by Gtk.TreeIter iter.""" |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
69 |
index = self._get_index_from_iter(iter) |
70 |
self.combo.set_active(index) |
|
71 |
||
72 |
def activate_last_selected(self): |
|
73 |
"""Activate the previously selected row. |
|
74 |
||
75 |
Expected to be used when cancelling custom entry or revieved bad
|
|
76 |
input.
|
|
77 |
"""
|
|
78 |
if self.last_selected: |
|
79 |
self.activate(self.last_selected) |
|
80 |
||
81 |
def activate_default(self): |
|
82 |
"""Activate the default row.""" |
|
83 |
# TODO allow setting of default?
|
|
84 |
self.activate(self.oldest_iter) |
|
85 |
||
86 |
def _get_index_from_iter(self, iter): |
|
87 |
"""Returns a row index integer from iterator.""" |
|
88 |
return int(self.model.get_string_from_iter(iter)) |
|
89 |
||
90 |
def _combo_changed_cb(self, w): |
|
91 |
model = w.get_model() |
|
92 |
iter = w.get_active_iter() |
|
93 |
||
94 |
if model.get_value(iter, SPAN_IS_CUSTOM_COL): |
|
95 |
self._request_custom_span() |
|
96 |
else: |
|
97 |
self.last_selected = iter |
|
98 |
self.emit("span-changed", model.get_value(iter, SPAN_DAYS_COL)) |
|
99 |
||
100 |
def _activate_custom_span_cb(self, w): |
|
734.1.24
by Curtis Hovey
Updated most of BranchView to gtk3. |
101 |
self.entry.hide() |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
102 |
self.combo.show() |
103 |
||
104 |
span = float(w.get_text()) |
|
724
by Jelmer Vernooij
Fix formatting, imports. |
105 |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
106 |
if span == 0: |
107 |
# FIXME this works as "cancel", returning to the previous span,
|
|
108 |
# but it emits "span-changed", which isn't necessary.
|
|
109 |
self.activate_last_selected() |
|
110 |
return
|
|
111 |
||
0.1.14
by Dan Loda
Remember custom spans across sessions. |
112 |
self.add_custom_span(span) |
113 |
self.emit("custom-span-added", span) |
|
114 |
||
115 |
self.activate(self.custom_iter) |
|
116 |
||
117 |
def add_custom_span(self, span): |
|
118 |
if not len(self.custom_spans): |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
119 |
self.custom_iter = self.model.insert_after(self.custom_iter, |
120 |
self.separator) |
|
121 |
self.custom_iter_top = self.custom_iter.copy() |
|
724
by Jelmer Vernooij
Fix formatting, imports. |
122 |
|
0.1.14
by Dan Loda
Remember custom spans across sessions. |
123 |
if len(self.custom_spans) == self.max_custom_spans: |
124 |
self.custom_spans.pop(0) |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
125 |
self.model.remove(self.model.iter_next(self.custom_iter_top)) |
724
by Jelmer Vernooij
Fix formatting, imports. |
126 |
|
0.1.14
by Dan Loda
Remember custom spans across sessions. |
127 |
self.custom_spans.append(span) |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
128 |
self.custom_iter = self.model.insert_after( |
129 |
self.custom_iter, [span, "%.2f Days" % span, False, False]) |
|
130 |
||
131 |
def _request_custom_span(self): |
|
132 |
self.combo.hide() |
|
133 |
self.entry.show_all() |
|
134 |
||
135 |
def _create_model(self): |
|
136 |
# [span in days, span as string, row is seperator?, row is select
|
|
137 |
# default?]
|
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
138 |
m = Gtk.ListStore(GObject.TYPE_FLOAT, |
139 |
GObject.TYPE_STRING, |
|
140 |
GObject.TYPE_BOOLEAN, |
|
141 |
GObject.TYPE_BOOLEAN) |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
142 |
|
143 |
self.separator = [0., "", True, False] |
|
724
by Jelmer Vernooij
Fix formatting, imports. |
144 |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
145 |
self.oldest_iter = m.append([0., "to Oldest Revision", False, False]) |
146 |
self.newest_iter = m.append([0., "Newest to Oldest", False, False]) |
|
147 |
m.append(self.separator) |
|
148 |
m.append([1., "1 Day", False, False]) |
|
149 |
m.append([7., "1 Week", False, False]) |
|
150 |
m.append([30., "1 Month", False, False]) |
|
151 |
self.custom_iter = m.append([365., "1 Year", False, False]) |
|
152 |
m.append(self.separator) |
|
153 |
m.append([0., "Custom...", False, True]) |
|
154 |
||
155 |
return m |
|
156 |
||
157 |
def _create_combobox(self, model): |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
158 |
cb = Gtk.ComboBox(model) |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
159 |
cb.set_row_separator_func( |
160 |
lambda m, i: m.get_value(i, SPAN_IS_SEPARATOR_COL)) |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
161 |
cell = Gtk.CellRendererText() |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
162 |
cb.pack_start(cell, False) |
163 |
cb.add_attribute(cell, "text", SPAN_STR_COL) |
|
164 |
cb.connect("changed", self._combo_changed_cb) |
|
165 |
cb.show() |
|
166 |
||
167 |
return cb |
|
168 |
||
169 |
def _create_custom_entry(self): |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
170 |
entry = Gtk.HBox(False, 6) |
724
by Jelmer Vernooij
Fix formatting, imports. |
171 |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
172 |
spin = Gtk.SpinButton(digits=2) |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
173 |
spin.set_numeric(True) |
174 |
spin.set_increments(1., 10.) |
|
175 |
spin.set_range(0., 100 * 365) # I presume 100 years is sufficient |
|
176 |
spin.connect("activate", self._activate_custom_span_cb) |
|
177 |
spin.connect("show", lambda w: w.grab_focus()) |
|
178 |
||
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
179 |
label = Gtk.Label(label="Days") |
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
180 |
|
734.1.8
by Curtis Hovey
pass all the required args to pack_start(). |
181 |
entry.pack_start(spin, False, False, True, 0) |
182 |
entry.pack_start(label, False, False, True, 0) |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
183 |
|
184 |
return entry |
|
185 |
||
0.1.14
by Dan Loda
Remember custom spans across sessions. |
186 |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
187 |
"""The "span-changed" signal is emitted when a new span has been selected or
|
188 |
entered.
|
|
189 |
||
0.1.14
by Dan Loda
Remember custom spans across sessions. |
190 |
Callback signature: def callback(SpanSelector, span, [user_param, ...])
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
191 |
"""
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
192 |
GObject.signal_new("span-changed", SpanSelector, |
193 |
GObject.SignalFlags.RUN_LAST, |
|
194 |
None, |
|
195 |
(GObject.TYPE_FLOAT,)) |
|
0.2.4
by Dan Loda
Extract class SpanSelector out of GAnnotateWindow. |
196 |
|
0.1.14
by Dan Loda
Remember custom spans across sessions. |
197 |
"""The "custom-span-added" signal is emitted after a custom span has been
|
198 |
added, but before it has been selected.
|
|
199 |
||
200 |
Callback signature: def callback(SpanSelector, span, [user_param, ...])
|
|
201 |
"""
|
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
202 |
GObject.signal_new("custom-span-added", SpanSelector, |
203 |
GObject.SignalFlags.RUN_LAST, |
|
204 |
None, |
|
205 |
(GObject.TYPE_FLOAT,)) |
|
0.1.14
by Dan Loda
Remember custom spans across sessions. |
206 |