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 |
|
22 |
||
23 |
from bzrlib.osutils import format_date |
|
24 |
||
25 |
||
26 |
class LogView(gtk.ScrolledWindow): |
|
27 |
""" Custom widget for commit log details. |
|
28 |
||
29 |
A variety of bzr tools may need to implement such a thing. This is a
|
|
30 |
start.
|
|
31 |
"""
|
|
32 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
33 |
def __init__(self, revision=None, scroll=True, tags=None): |
179
by Jelmer Vernooij
Don't use scrolling inside revisions in missing window. |
34 |
super(LogView, self).__init__() |
35 |
if scroll: |
|
36 |
self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) |
|
37 |
else: |
|
38 |
self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
39 |
self.set_shadow_type(gtk.SHADOW_NONE) |
40 |
self._create() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
41 |
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. |
42 |
self._go_callback = None |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
43 |
self._clicked_callback = None |
0.1.1
by Dan Loda
First working version of xannotate. |
44 |
|
45 |
if revision is not None: |
|
241
by Jelmer Vernooij
Show tags in bzr viz. |
46 |
self.set_revision(revision, tags=tags) |
0.1.1
by Dan Loda
First working version of xannotate. |
47 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
48 |
def set_show_callback(self, callback): |
49 |
self._show_callback = callback |
|
50 |
||
51 |
def set_go_callback(self, callback): |
|
52 |
self._go_callback = callback |
|
53 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
54 |
def set_revision(self, revision, tags=None): |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
55 |
self._revision = revision |
0.1.1
by Dan Loda
First working version of xannotate. |
56 |
self.revision_id.set_text(revision.revision_id) |
192
by Jelmer Vernooij
Allow committer to be None. |
57 |
if revision.committer is not None: |
58 |
self.committer.set_text(revision.committer) |
|
59 |
else: |
|
60 |
self.committer.set_text("") |
|
197
by Jelmer Vernooij
Fix some warnings when displaying ghost revisions. Reported by John. |
61 |
if revision.timestamp is not None: |
62 |
self.timestamp.set_text(format_date(revision.timestamp, |
|
63 |
revision.timezone)) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
64 |
self.message_buffer.set_text(revision.message) |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
65 |
try: |
66 |
self.branchnick_label.set_text(revision.properties['branch-nick']) |
|
67 |
except KeyError: |
|
68 |
self.branchnick_label.set_text("") |
|
69 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
70 |
self._add_parents(revision.parent_ids) |
241
by Jelmer Vernooij
Show tags in bzr viz. |
71 |
self._add_tags(tags) |
0.1.1
by Dan Loda
First working version of xannotate. |
72 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
73 |
def _show_clicked_cb(self, widget, revid, parentid): |
74 |
"""Callback for when the show button for a parent is clicked.""" |
|
75 |
self._show_callback(revid, parentid) |
|
76 |
||
77 |
def _go_clicked_cb(self, widget, revid): |
|
78 |
"""Callback for when the go button for a parent is clicked.""" |
|
79 |
self._go_callback(revid) |
|
80 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
81 |
def _add_tags(self, tags): |
82 |
if tags == []: |
|
83 |
self.tags_list.hide() |
|
84 |
self.tags_label.hide() |
|
85 |
return
|
|
86 |
||
87 |
for widget in self.tags_widgets: |
|
88 |
self.tags_list.remove(widget) |
|
89 |
||
90 |
for tag in tags: |
|
91 |
widget = gtk.Label(tag) |
|
92 |
widget.set_selectable(True) |
|
93 |
self.tags_widgets.append(widget) |
|
94 |
self.tags_list.add(widget) |
|
95 |
self.tags_list.show_all() |
|
96 |
self.tags_label.show_all() |
|
97 |
||
98 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
99 |
def _add_parents(self, parent_ids): |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
100 |
for widget in self.parents_widgets: |
101 |
self.parents_table.remove(widget) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
102 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
103 |
self.parents_widgets = [] |
104 |
self.parents_table.resize(max(len(parent_ids), 1), 2) |
|
105 |
||
106 |
for idx, parent_id in enumerate(parent_ids): |
|
107 |
align = gtk.Alignment(0.0, 0.0) |
|
108 |
self.parents_widgets.append(align) |
|
109 |
self.parents_table.attach(align, 1, 2, idx, idx + 1, |
|
110 |
gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
111 |
align.show() |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
112 |
|
113 |
hbox = gtk.HBox(False, spacing=6) |
|
114 |
align.add(hbox) |
|
115 |
hbox.show() |
|
116 |
||
117 |
image = gtk.Image() |
|
118 |
image.set_from_stock( |
|
119 |
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR) |
|
120 |
image.show() |
|
121 |
||
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. |
122 |
if self._show_callback is not None: |
123 |
button = gtk.Button() |
|
124 |
button.add(image) |
|
125 |
button.connect("clicked", self._show_clicked_cb, |
|
126 |
self._revision.revision_id, parent_id) |
|
127 |
hbox.pack_start(button, expand=False, fill=True) |
|
128 |
button.show() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
129 |
|
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. |
130 |
if self._go_callback is not None: |
131 |
button = gtk.Button(parent_id) |
|
132 |
button.connect("clicked", self._go_clicked_cb, parent_id) |
|
133 |
else: |
|
134 |
button = gtk.Label(parent_id) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
135 |
button.set_use_underline(False) |
136 |
hbox.pack_start(button, expand=False, fill=True) |
|
137 |
button.show() |
|
0.1.1
by Dan Loda
First working version of xannotate. |
138 |
|
139 |
def _create(self): |
|
140 |
vbox = gtk.VBox(False, 6) |
|
141 |
vbox.set_border_width(6) |
|
142 |
vbox.pack_start(self._create_headers(), expand=False, fill=True) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
143 |
vbox.pack_start(self._create_parents_table(), expand=False, fill=True) |
0.1.1
by Dan Loda
First working version of xannotate. |
144 |
vbox.pack_start(self._create_message_view()) |
145 |
self.add_with_viewport(vbox) |
|
146 |
vbox.show() |
|
147 |
||
148 |
def _create_headers(self): |
|
241
by Jelmer Vernooij
Show tags in bzr viz. |
149 |
self.table = gtk.Table(rows=5, columns=2) |
0.1.1
by Dan Loda
First working version of xannotate. |
150 |
self.table.set_row_spacings(6) |
151 |
self.table.set_col_spacings(6) |
|
152 |
self.table.show() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
153 |
|
154 |
align = gtk.Alignment(1.0, 0.5) |
|
155 |
label = gtk.Label() |
|
156 |
label.set_markup("<b>Revision Id:</b>") |
|
157 |
align.add(label) |
|
158 |
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL) |
|
159 |
align.show() |
|
160 |
label.show() |
|
161 |
||
162 |
align = gtk.Alignment(0.0, 0.5) |
|
163 |
self.revision_id = gtk.Label() |
|
164 |
self.revision_id.set_selectable(True) |
|
165 |
align.add(self.revision_id) |
|
166 |
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
167 |
align.show() |
|
168 |
self.revision_id.show() |
|
169 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
170 |
align = gtk.Alignment(1.0, 0.5) |
171 |
label = gtk.Label() |
|
172 |
label.set_markup("<b>Committer:</b>") |
|
173 |
align.add(label) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
174 |
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
175 |
align.show() |
176 |
label.show() |
|
177 |
||
178 |
align = gtk.Alignment(0.0, 0.5) |
|
179 |
self.committer = gtk.Label() |
|
180 |
self.committer.set_selectable(True) |
|
181 |
align.add(self.committer) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
182 |
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
183 |
align.show() |
184 |
self.committer.show() |
|
185 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
186 |
align = gtk.Alignment(0.0, 0.5) |
187 |
label = gtk.Label() |
|
188 |
label.set_markup("<b>Branch nick:</b>") |
|
189 |
align.add(label) |
|
190 |
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL) |
|
191 |
label.show() |
|
192 |
align.show() |
|
193 |
||
194 |
align = gtk.Alignment(0.0, 0.5) |
|
195 |
self.branchnick_label = gtk.Label() |
|
196 |
self.branchnick_label.set_selectable(True) |
|
197 |
align.add(self.branchnick_label) |
|
198 |
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
199 |
self.branchnick_label.show() |
|
200 |
align.show() |
|
201 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
202 |
align = gtk.Alignment(1.0, 0.5) |
203 |
label = gtk.Label() |
|
204 |
label.set_markup("<b>Timestamp:</b>") |
|
205 |
align.add(label) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
206 |
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
207 |
align.show() |
208 |
label.show() |
|
209 |
||
210 |
align = gtk.Alignment(0.0, 0.5) |
|
211 |
self.timestamp = gtk.Label() |
|
212 |
self.timestamp.set_selectable(True) |
|
213 |
align.add(self.timestamp) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
214 |
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
215 |
align.show() |
216 |
self.timestamp.show() |
|
217 |
||
241
by Jelmer Vernooij
Show tags in bzr viz. |
218 |
align = gtk.Alignment(1.0, 0.5) |
219 |
self.tags_label = gtk.Label() |
|
220 |
self.tags_label.set_markup("<b>Tags:</b>") |
|
221 |
align.add(self.tags_label) |
|
222 |
align.show() |
|
223 |
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL) |
|
224 |
self.tags_label.show() |
|
225 |
||
226 |
align = gtk.Alignment(0.0, 0.5) |
|
227 |
self.tags_list = gtk.VBox() |
|
228 |
align.add(self.tags_list) |
|
229 |
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
230 |
align.show() |
|
231 |
self.tags_list.show() |
|
232 |
self.tags_widgets = [] |
|
233 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
234 |
return self.table |
235 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
236 |
def _create_parents_table(self): |
237 |
self.parents_table = gtk.Table(rows=1, columns=2) |
|
238 |
self.parents_table.set_row_spacings(3) |
|
239 |
self.parents_table.set_col_spacings(6) |
|
240 |
self.parents_table.show() |
|
241 |
self.parents_widgets = [] |
|
242 |
||
243 |
label = gtk.Label() |
|
244 |
label.set_markup("<b>Parents:</b>") |
|
245 |
align = gtk.Alignment(0.0, 0.5) |
|
246 |
align.add(label) |
|
247 |
self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL) |
|
248 |
label.show() |
|
249 |
align.show() |
|
250 |
||
251 |
return self.parents_table |
|
252 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
253 |
def _create_message_view(self): |
254 |
self.message_buffer = gtk.TextBuffer() |
|
255 |
tv = gtk.TextView(self.message_buffer) |
|
256 |
tv.set_editable(False) |
|
257 |
tv.set_wrap_mode(gtk.WRAP_WORD) |
|
258 |
tv.modify_font(pango.FontDescription("Monospace")) |
|
259 |
tv.show() |
|
260 |
return tv |
|
261 |