bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.1.1
by Dan Loda
First working version of xannotate. |
1 |
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
|
175
by Jelmer Vernooij
Add very simple gmissing command. |
2 |
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
|
0.1.1
by Dan Loda
First working version of xannotate. |
3 |
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
||
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
||
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
import pygtk |
|
19 |
pygtk.require("2.0") |
|
20 |
import gtk |
|
21 |
import pango |
|
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
22 |
import gtksourceview |
23 |
import sys |
|
24 |
||
25 |
from cStringIO import StringIO |
|
0.1.1
by Dan Loda
First working version of xannotate. |
26 |
|
27 |
from bzrlib.osutils import format_date |
|
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
28 |
from bzrlib.diff import show_diff_trees |
0.1.1
by Dan Loda
First working version of xannotate. |
29 |
|
324.2.1
by Daniel Schierbeck
Turned the logview into a notebook. |
30 |
class LogView(gtk.Notebook): |
0.1.1
by Dan Loda
First working version of xannotate. |
31 |
""" Custom widget for commit log details. |
32 |
||
33 |
A variety of bzr tools may need to implement such a thing. This is a
|
|
34 |
start.
|
|
35 |
"""
|
|
36 |
||
256.2.23
by Gary van der Merwe
Show Children |
37 |
def __init__(self, revision=None, scroll=True, tags=[], |
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
38 |
show_children=False, branch=None): |
324.2.1
by Daniel Schierbeck
Turned the logview into a notebook. |
39 |
gtk.Notebook.__init__(self) |
256.2.23
by Gary van der Merwe
Show Children |
40 |
self.show_children = show_children |
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
41 |
|
324.2.1
by Daniel Schierbeck
Turned the logview into a notebook. |
42 |
self._create_general() |
43 |
self._create_relations() |
|
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
44 |
self._create_changes() |
45 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
46 |
self._show_callback = None |
148
by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set. |
47 |
self._go_callback = None |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
48 |
self._clicked_callback = None |
0.1.1
by Dan Loda
First working version of xannotate. |
49 |
|
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
50 |
self._branch = branch |
51 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
52 |
if revision is not None: |
241
by Jelmer Vernooij
Show tags in bzr viz. |
53 |
self.set_revision(revision, tags=tags) |
0.1.1
by Dan Loda
First working version of xannotate. |
54 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
55 |
def set_show_callback(self, callback): |
56 |
self._show_callback = callback |
|
57 |
||
58 |
def set_go_callback(self, callback): |
|
59 |
self._go_callback = callback |
|
60 |
||
256.2.23
by Gary van der Merwe
Show Children |
61 |
def set_revision(self, revision, tags=[], children=[]): |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
62 |
self._revision = revision |
0.1.1
by Dan Loda
First working version of xannotate. |
63 |
self.revision_id.set_text(revision.revision_id) |
192
by Jelmer Vernooij
Allow committer to be None. |
64 |
if revision.committer is not None: |
65 |
self.committer.set_text(revision.committer) |
|
66 |
else: |
|
67 |
self.committer.set_text("") |
|
259
by Aaron Bentley
Add author support to gannotate and log viewer |
68 |
author = revision.properties.get('author', '') |
69 |
if author != '': |
|
70 |
self.author.set_text(author) |
|
71 |
self.author.show() |
|
72 |
self.author_label.show() |
|
73 |
else: |
|
74 |
self.author.hide() |
|
75 |
self.author_label.hide() |
|
76 |
||
197
by Jelmer Vernooij
Fix some warnings when displaying ghost revisions. Reported by John. |
77 |
if revision.timestamp is not None: |
78 |
self.timestamp.set_text(format_date(revision.timestamp, |
|
79 |
revision.timezone)) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
80 |
self.message_buffer.set_text(revision.message) |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
81 |
try: |
82 |
self.branchnick_label.set_text(revision.properties['branch-nick']) |
|
83 |
except KeyError: |
|
84 |
self.branchnick_label.set_text("") |
|
85 |
||
256.2.23
by Gary van der Merwe
Show Children |
86 |
self._add_parents_or_children(revision.parent_ids, |
87 |
self.parents_widgets, |
|
88 |
self.parents_table) |
|
89 |
||
90 |
if self.show_children: |
|
91 |
self._add_parents_or_children(children, |
|
92 |
self.children_widgets, |
|
93 |
self.children_table) |
|
94 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
95 |
self._add_tags(tags) |
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
96 |
self._set_diff() |
97 |
||
98 |
def _set_diff(self): |
|
99 |
parentid = self._revision.parent_ids[0] |
|
100 |
revid = self._revision.revision_id |
|
101 |
||
102 |
(parent_tree, rev_tree) = self._branch.repository.revision_trees([parentid, |
|
103 |
revid]) |
|
104 |
||
105 |
s = StringIO() |
|
106 |
show_diff_trees(parent_tree, rev_tree, s, None) |
|
107 |
self.diff_buffer.set_text(s.getvalue().decode(sys.getdefaultencoding(), 'replace')) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
108 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
109 |
def _show_clicked_cb(self, widget, revid, parentid): |
110 |
"""Callback for when the show button for a parent is clicked.""" |
|
111 |
self._show_callback(revid, parentid) |
|
112 |
||
113 |
def _go_clicked_cb(self, widget, revid): |
|
114 |
"""Callback for when the go button for a parent is clicked.""" |
|
115 |
self._go_callback(revid) |
|
116 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
117 |
def _add_tags(self, tags): |
118 |
if tags == []: |
|
119 |
self.tags_list.hide() |
|
120 |
self.tags_label.hide() |
|
121 |
return
|
|
122 |
||
123 |
for widget in self.tags_widgets: |
|
124 |
self.tags_list.remove(widget) |
|
125 |
||
242
by Jelmer Vernooij
Avoid cleanup warning. |
126 |
self.tags_widgets = [] |
127 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
128 |
for tag in tags: |
129 |
widget = gtk.Label(tag) |
|
130 |
widget.set_selectable(True) |
|
131 |
self.tags_widgets.append(widget) |
|
132 |
self.tags_list.add(widget) |
|
133 |
self.tags_list.show_all() |
|
134 |
self.tags_label.show_all() |
|
135 |
||
256.2.23
by Gary van der Merwe
Show Children |
136 |
def _add_parents_or_children(self, revids, widgets, table): |
137 |
while len(widgets) > 0: |
|
138 |
widget = widgets.pop() |
|
139 |
table.remove(widget) |
|
140 |
||
141 |
table.resize(max(len(revids), 1), 2) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
142 |
|
256.2.23
by Gary van der Merwe
Show Children |
143 |
for idx, revid in enumerate(revids): |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
144 |
align = gtk.Alignment(0.0, 0.0) |
256.2.23
by Gary van der Merwe
Show Children |
145 |
widgets.append(align) |
146 |
table.attach(align, 1, 2, idx, idx + 1, |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
147 |
gtk.EXPAND | gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
148 |
align.show() |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
149 |
|
150 |
hbox = gtk.HBox(False, spacing=6) |
|
151 |
align.add(hbox) |
|
152 |
hbox.show() |
|
153 |
||
154 |
image = gtk.Image() |
|
155 |
image.set_from_stock( |
|
156 |
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR) |
|
157 |
image.show() |
|
158 |
||
148
by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set. |
159 |
if self._show_callback is not None: |
160 |
button = gtk.Button() |
|
161 |
button.add(image) |
|
162 |
button.connect("clicked", self._show_clicked_cb, |
|
256.2.23
by Gary van der Merwe
Show Children |
163 |
self._revision.revision_id, revid) |
148
by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set. |
164 |
hbox.pack_start(button, expand=False, fill=True) |
165 |
button.show() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
166 |
|
148
by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set. |
167 |
if self._go_callback is not None: |
256.2.23
by Gary van der Merwe
Show Children |
168 |
button = gtk.Button(revid) |
169 |
button.connect("clicked", self._go_clicked_cb, revid) |
|
148
by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set. |
170 |
else: |
256.2.23
by Gary van der Merwe
Show Children |
171 |
button = gtk.Label(revid) |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
172 |
button.set_use_underline(False) |
173 |
hbox.pack_start(button, expand=False, fill=True) |
|
174 |
button.show() |
|
0.1.1
by Dan Loda
First working version of xannotate. |
175 |
|
324.2.1
by Daniel Schierbeck
Turned the logview into a notebook. |
176 |
def _create_general(self): |
0.1.1
by Dan Loda
First working version of xannotate. |
177 |
vbox = gtk.VBox(False, 6) |
178 |
vbox.set_border_width(6) |
|
179 |
vbox.pack_start(self._create_headers(), expand=False, fill=True) |
|
324.2.1
by Daniel Schierbeck
Turned the logview into a notebook. |
180 |
vbox.pack_start(self._create_message_view()) |
181 |
self.append_page(vbox, tab_label=gtk.Label("General")) |
|
182 |
vbox.show() |
|
183 |
||
184 |
def _create_relations(self): |
|
185 |
vbox = gtk.VBox(False, 6) |
|
186 |
vbox.set_border_width(6) |
|
291
by Jelmer Vernooij
Put children widget on a new line. |
187 |
vbox.pack_start(self._create_parents(), expand=False, fill=True) |
188 |
if self.show_children: |
|
189 |
vbox.pack_start(self._create_children(), expand=False, fill=True) |
|
324.2.1
by Daniel Schierbeck
Turned the logview into a notebook. |
190 |
self.append_page(vbox, tab_label=gtk.Label("Relations")) |
0.1.1
by Dan Loda
First working version of xannotate. |
191 |
vbox.show() |
324.2.4
by Daniel Schierbeck
Added 'Changes' page to logview. |
192 |
|
193 |
def _create_changes(self): |
|
194 |
slm = gtksourceview.SourceLanguagesManager() |
|
195 |
||
196 |
self.diff_buffer = gtksourceview.SourceBuffer() |
|
197 |
self.diff_buffer.set_language(slm.get_language_from_mime_type("text/x-patch")) |
|
198 |
self.diff_buffer.set_highlight(True) |
|
199 |
||
200 |
sourceview = gtksourceview.SourceView(self.diff_buffer) |
|
201 |
sourceview.set_editable(False) |
|
202 |
sourceview.modify_font(pango.FontDescription("Monospace")) |
|
203 |
||
204 |
sourceview.show() |
|
205 |
||
206 |
win = gtk.ScrolledWindow() |
|
207 |
win.add(sourceview) |
|
208 |
||
209 |
self.append_page(win, tab_label=gtk.Label("Changes")) |
|
210 |
win.show() |
|
324.2.1
by Daniel Schierbeck
Turned the logview into a notebook. |
211 |
|
0.1.1
by Dan Loda
First working version of xannotate. |
212 |
def _create_headers(self): |
241
by Jelmer Vernooij
Show tags in bzr viz. |
213 |
self.table = gtk.Table(rows=5, columns=2) |
0.1.1
by Dan Loda
First working version of xannotate. |
214 |
self.table.set_row_spacings(6) |
215 |
self.table.set_col_spacings(6) |
|
216 |
self.table.show() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
217 |
|
218 |
align = gtk.Alignment(1.0, 0.5) |
|
219 |
label = gtk.Label() |
|
220 |
label.set_markup("<b>Revision Id:</b>") |
|
221 |
align.add(label) |
|
222 |
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL) |
|
223 |
align.show() |
|
224 |
label.show() |
|
225 |
||
226 |
align = gtk.Alignment(0.0, 0.5) |
|
227 |
self.revision_id = gtk.Label() |
|
228 |
self.revision_id.set_selectable(True) |
|
229 |
align.add(self.revision_id) |
|
230 |
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
231 |
align.show() |
|
232 |
self.revision_id.show() |
|
233 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
234 |
align = gtk.Alignment(1.0, 0.5) |
259
by Aaron Bentley
Add author support to gannotate and log viewer |
235 |
self.author_label = gtk.Label() |
236 |
self.author_label.set_markup("<b>Author:</b>") |
|
237 |
align.add(self.author_label) |
|
238 |
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL) |
|
239 |
align.show() |
|
240 |
self.author_label.show() |
|
241 |
||
242 |
align = gtk.Alignment(0.0, 0.5) |
|
243 |
self.author = gtk.Label() |
|
244 |
self.author.set_selectable(True) |
|
245 |
align.add(self.author) |
|
246 |
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
247 |
align.show() |
|
248 |
self.author.show() |
|
249 |
self.author.hide() |
|
250 |
||
251 |
align = gtk.Alignment(1.0, 0.5) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
252 |
label = gtk.Label() |
253 |
label.set_markup("<b>Committer:</b>") |
|
254 |
align.add(label) |
|
259
by Aaron Bentley
Add author support to gannotate and log viewer |
255 |
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
256 |
align.show() |
257 |
label.show() |
|
258 |
||
259 |
align = gtk.Alignment(0.0, 0.5) |
|
260 |
self.committer = gtk.Label() |
|
261 |
self.committer.set_selectable(True) |
|
262 |
align.add(self.committer) |
|
259
by Aaron Bentley
Add author support to gannotate and log viewer |
263 |
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
264 |
align.show() |
265 |
self.committer.show() |
|
266 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
267 |
align = gtk.Alignment(0.0, 0.5) |
268 |
label = gtk.Label() |
|
269 |
label.set_markup("<b>Branch nick:</b>") |
|
270 |
align.add(label) |
|
259
by Aaron Bentley
Add author support to gannotate and log viewer |
271 |
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL) |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
272 |
label.show() |
273 |
align.show() |
|
274 |
||
275 |
align = gtk.Alignment(0.0, 0.5) |
|
276 |
self.branchnick_label = gtk.Label() |
|
277 |
self.branchnick_label.set_selectable(True) |
|
278 |
align.add(self.branchnick_label) |
|
259
by Aaron Bentley
Add author support to gannotate and log viewer |
279 |
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL) |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
280 |
self.branchnick_label.show() |
281 |
align.show() |
|
282 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
283 |
align = gtk.Alignment(1.0, 0.5) |
284 |
label = gtk.Label() |
|
285 |
label.set_markup("<b>Timestamp:</b>") |
|
286 |
align.add(label) |
|
259
by Aaron Bentley
Add author support to gannotate and log viewer |
287 |
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
288 |
align.show() |
289 |
label.show() |
|
290 |
||
291 |
align = gtk.Alignment(0.0, 0.5) |
|
292 |
self.timestamp = gtk.Label() |
|
293 |
self.timestamp.set_selectable(True) |
|
294 |
align.add(self.timestamp) |
|
259
by Aaron Bentley
Add author support to gannotate and log viewer |
295 |
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
296 |
align.show() |
297 |
self.timestamp.show() |
|
298 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
299 |
align = gtk.Alignment(1.0, 0.5) |
300 |
self.tags_label = gtk.Label() |
|
301 |
self.tags_label.set_markup("<b>Tags:</b>") |
|
302 |
align.add(self.tags_label) |
|
303 |
align.show() |
|
261
by Aaron Bentley
Fix tags formatting |
304 |
self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL) |
241
by Jelmer Vernooij
Show tags in bzr viz. |
305 |
self.tags_label.show() |
306 |
||
307 |
align = gtk.Alignment(0.0, 0.5) |
|
308 |
self.tags_list = gtk.VBox() |
|
309 |
align.add(self.tags_list) |
|
261
by Aaron Bentley
Fix tags formatting |
310 |
self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL) |
241
by Jelmer Vernooij
Show tags in bzr viz. |
311 |
align.show() |
312 |
self.tags_list.show() |
|
313 |
self.tags_widgets = [] |
|
314 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
315 |
return self.table |
316 |
||
256.2.23
by Gary van der Merwe
Show Children |
317 |
|
291
by Jelmer Vernooij
Put children widget on a new line. |
318 |
def _create_parents(self): |
319 |
hbox = gtk.HBox(True, 3) |
|
256.2.23
by Gary van der Merwe
Show Children |
320 |
|
321 |
self.parents_table = self._create_parents_or_children_table( |
|
322 |
"<b>Parents:</b>") |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
323 |
self.parents_widgets = [] |
256.2.23
by Gary van der Merwe
Show Children |
324 |
hbox.pack_start(self.parents_table) |
291
by Jelmer Vernooij
Put children widget on a new line. |
325 |
|
326 |
hbox.show() |
|
327 |
return hbox |
|
328 |
||
329 |
def _create_children(self): |
|
330 |
hbox = gtk.HBox(True, 3) |
|
331 |
self.children_table = self._create_parents_or_children_table( |
|
332 |
"<b>Children:</b>") |
|
333 |
self.children_widgets = [] |
|
334 |
hbox.pack_start(self.children_table) |
|
256.2.23
by Gary van der Merwe
Show Children |
335 |
hbox.show() |
336 |
return hbox |
|
337 |
||
338 |
def _create_parents_or_children_table(self, text): |
|
339 |
table = gtk.Table(rows=1, columns=2) |
|
340 |
table.set_row_spacings(3) |
|
341 |
table.set_col_spacings(6) |
|
342 |
table.show() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
343 |
|
344 |
label = gtk.Label() |
|
256.2.23
by Gary van der Merwe
Show Children |
345 |
label.set_markup(text) |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
346 |
align = gtk.Alignment(0.0, 0.5) |
347 |
align.add(label) |
|
256.2.23
by Gary van der Merwe
Show Children |
348 |
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL) |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
349 |
label.show() |
350 |
align.show() |
|
351 |
||
256.2.23
by Gary van der Merwe
Show Children |
352 |
return table |
353 |
||
354 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
355 |
|
0.1.1
by Dan Loda
First working version of xannotate. |
356 |
def _create_message_view(self): |
357 |
self.message_buffer = gtk.TextBuffer() |
|
324.2.2
by Daniel Schierbeck
Surrounded the commit message textview with a scrolled window and added a shadow. |
358 |
window = gtk.ScrolledWindow() |
359 |
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) |
|
360 |
window.set_shadow_type(gtk.SHADOW_IN) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
361 |
tv = gtk.TextView(self.message_buffer) |
362 |
tv.set_editable(False) |
|
363 |
tv.set_wrap_mode(gtk.WRAP_WORD) |
|
364 |
tv.modify_font(pango.FontDescription("Monospace")) |
|
365 |
tv.show() |
|
324.2.2
by Daniel Schierbeck
Surrounded the commit message textview with a scrolled window and added a shadow. |
366 |
window.add(tv) |
367 |
window.show() |
|
368 |
return window |
|
0.1.1
by Dan Loda
First working version of xannotate. |
369 |