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 |
||
179
by Jelmer Vernooij
Don't use scrolling inside revisions in missing window. |
33 |
def __init__(self, revision=None, scroll=True): |
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: |
|
46 |
self.set_revision(revision) |
|
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 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
54 |
def set_revision(self, revision): |
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) |
71 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
72 |
def _show_clicked_cb(self, widget, revid, parentid): |
73 |
"""Callback for when the show button for a parent is clicked.""" |
|
74 |
self._show_callback(revid, parentid) |
|
75 |
||
76 |
def _go_clicked_cb(self, widget, revid): |
|
77 |
"""Callback for when the go button for a parent is clicked.""" |
|
78 |
self._go_callback(revid) |
|
79 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
80 |
def _add_parents(self, parent_ids): |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
81 |
for widget in self.parents_widgets: |
82 |
self.parents_table.remove(widget) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
83 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
84 |
self.parents_widgets = [] |
85 |
self.parents_table.resize(max(len(parent_ids), 1), 2) |
|
86 |
||
87 |
for idx, parent_id in enumerate(parent_ids): |
|
88 |
align = gtk.Alignment(0.0, 0.0) |
|
89 |
self.parents_widgets.append(align) |
|
90 |
self.parents_table.attach(align, 1, 2, idx, idx + 1, |
|
91 |
gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
0.1.1
by Dan Loda
First working version of xannotate. |
92 |
align.show() |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
93 |
|
94 |
hbox = gtk.HBox(False, spacing=6) |
|
95 |
align.add(hbox) |
|
96 |
hbox.show() |
|
97 |
||
98 |
image = gtk.Image() |
|
99 |
image.set_from_stock( |
|
100 |
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR) |
|
101 |
image.show() |
|
102 |
||
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. |
103 |
if self._show_callback is not None: |
104 |
button = gtk.Button() |
|
105 |
button.add(image) |
|
106 |
button.connect("clicked", self._show_clicked_cb, |
|
107 |
self._revision.revision_id, parent_id) |
|
108 |
hbox.pack_start(button, expand=False, fill=True) |
|
109 |
button.show() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
110 |
|
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. |
111 |
if self._go_callback is not None: |
112 |
button = gtk.Button(parent_id) |
|
113 |
button.connect("clicked", self._go_clicked_cb, parent_id) |
|
114 |
else: |
|
115 |
button = gtk.Label(parent_id) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
116 |
button.set_use_underline(False) |
117 |
hbox.pack_start(button, expand=False, fill=True) |
|
118 |
button.show() |
|
0.1.1
by Dan Loda
First working version of xannotate. |
119 |
|
120 |
def _create(self): |
|
121 |
vbox = gtk.VBox(False, 6) |
|
122 |
vbox.set_border_width(6) |
|
123 |
vbox.pack_start(self._create_headers(), expand=False, fill=True) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
124 |
vbox.pack_start(self._create_parents_table(), expand=False, fill=True) |
0.1.1
by Dan Loda
First working version of xannotate. |
125 |
vbox.pack_start(self._create_message_view()) |
126 |
self.add_with_viewport(vbox) |
|
127 |
vbox.show() |
|
128 |
||
129 |
def _create_headers(self): |
|
130 |
self.table = gtk.Table(rows=4, columns=2) |
|
131 |
self.table.set_row_spacings(6) |
|
132 |
self.table.set_col_spacings(6) |
|
133 |
self.table.show() |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
134 |
|
135 |
align = gtk.Alignment(1.0, 0.5) |
|
136 |
label = gtk.Label() |
|
137 |
label.set_markup("<b>Revision Id:</b>") |
|
138 |
align.add(label) |
|
139 |
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL) |
|
140 |
align.show() |
|
141 |
label.show() |
|
142 |
||
143 |
align = gtk.Alignment(0.0, 0.5) |
|
144 |
self.revision_id = gtk.Label() |
|
145 |
self.revision_id.set_selectable(True) |
|
146 |
align.add(self.revision_id) |
|
147 |
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
148 |
align.show() |
|
149 |
self.revision_id.show() |
|
150 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
151 |
align = gtk.Alignment(1.0, 0.5) |
152 |
label = gtk.Label() |
|
153 |
label.set_markup("<b>Committer:</b>") |
|
154 |
align.add(label) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
155 |
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
156 |
align.show() |
157 |
label.show() |
|
158 |
||
159 |
align = gtk.Alignment(0.0, 0.5) |
|
160 |
self.committer = gtk.Label() |
|
161 |
self.committer.set_selectable(True) |
|
162 |
align.add(self.committer) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
163 |
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. |
164 |
align.show() |
165 |
self.committer.show() |
|
166 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
167 |
align = gtk.Alignment(0.0, 0.5) |
168 |
label = gtk.Label() |
|
169 |
label.set_markup("<b>Branch nick:</b>") |
|
170 |
align.add(label) |
|
171 |
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL) |
|
172 |
label.show() |
|
173 |
align.show() |
|
174 |
||
175 |
align = gtk.Alignment(0.0, 0.5) |
|
176 |
self.branchnick_label = gtk.Label() |
|
177 |
self.branchnick_label.set_selectable(True) |
|
178 |
align.add(self.branchnick_label) |
|
179 |
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL) |
|
180 |
self.branchnick_label.show() |
|
181 |
align.show() |
|
182 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
183 |
align = gtk.Alignment(1.0, 0.5) |
184 |
label = gtk.Label() |
|
185 |
label.set_markup("<b>Timestamp:</b>") |
|
186 |
align.add(label) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
187 |
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL) |
0.1.1
by Dan Loda
First working version of xannotate. |
188 |
align.show() |
189 |
label.show() |
|
190 |
||
191 |
align = gtk.Alignment(0.0, 0.5) |
|
192 |
self.timestamp = gtk.Label() |
|
193 |
self.timestamp.set_selectable(True) |
|
194 |
align.add(self.timestamp) |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
195 |
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. |
196 |
align.show() |
197 |
self.timestamp.show() |
|
198 |
||
199 |
return self.table |
|
200 |
||
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
201 |
def _create_parents_table(self): |
202 |
self.parents_table = gtk.Table(rows=1, columns=2) |
|
203 |
self.parents_table.set_row_spacings(3) |
|
204 |
self.parents_table.set_col_spacings(6) |
|
205 |
self.parents_table.show() |
|
206 |
self.parents_widgets = [] |
|
207 |
||
208 |
label = gtk.Label() |
|
209 |
label.set_markup("<b>Parents:</b>") |
|
210 |
align = gtk.Alignment(0.0, 0.5) |
|
211 |
align.add(label) |
|
212 |
self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL) |
|
213 |
label.show() |
|
214 |
align.show() |
|
215 |
||
216 |
return self.parents_table |
|
217 |
||
0.1.1
by Dan Loda
First working version of xannotate. |
218 |
def _create_message_view(self): |
219 |
self.message_buffer = gtk.TextBuffer() |
|
220 |
tv = gtk.TextView(self.message_buffer) |
|
221 |
tv.set_editable(False) |
|
222 |
tv.set_wrap_mode(gtk.WRAP_WORD) |
|
223 |
tv.modify_font(pango.FontDescription("Monospace")) |
|
224 |
tv.show() |
|
225 |
return tv |
|
226 |