/b-gtk/fix-viz

To get this branch, use:
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
256.2.23 by Gary van der Merwe
Show Children
33
    def __init__(self, revision=None, scroll=True, tags=[],
34
                 show_children=False):
179 by Jelmer Vernooij
Don't use scrolling inside revisions in missing window.
35
        super(LogView, self).__init__()
36
        if scroll:
37
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
38
        else:
39
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
0.1.1 by Dan Loda
First working version of xannotate.
40
        self.set_shadow_type(gtk.SHADOW_NONE)
256.2.23 by Gary van der Merwe
Show Children
41
        self.show_children = show_children
0.1.1 by Dan Loda
First working version of xannotate.
42
        self._create()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
43
        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.
44
        self._go_callback = None
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
45
        self._clicked_callback = None
0.1.1 by Dan Loda
First working version of xannotate.
46
47
        if revision is not None:
241 by Jelmer Vernooij
Show tags in bzr viz.
48
            self.set_revision(revision, tags=tags)
0.1.1 by Dan Loda
First working version of xannotate.
49
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
50
    def set_show_callback(self, callback):
51
        self._show_callback = callback
52
53
    def set_go_callback(self, callback):
54
        self._go_callback = callback
55
256.2.23 by Gary van der Merwe
Show Children
56
    def set_revision(self, revision, tags=[], children=[]):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
57
        self._revision = revision
0.1.1 by Dan Loda
First working version of xannotate.
58
        self.revision_id.set_text(revision.revision_id)
192 by Jelmer Vernooij
Allow committer to be None.
59
        if revision.committer is not None:
60
            self.committer.set_text(revision.committer)
61
        else:
62
            self.committer.set_text("")
259 by Aaron Bentley
Add author support to gannotate and log viewer
63
        author = revision.properties.get('author', '')
64
        if author != '':
65
            self.author.set_text(author)
66
            self.author.show()
67
            self.author_label.show()
68
        else:
69
            self.author.hide()
70
            self.author_label.hide()
71
197 by Jelmer Vernooij
Fix some warnings when displaying ghost revisions. Reported by John.
72
        if revision.timestamp is not None:
73
            self.timestamp.set_text(format_date(revision.timestamp,
74
                                                revision.timezone))
0.1.1 by Dan Loda
First working version of xannotate.
75
        self.message_buffer.set_text(revision.message)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
76
        try:
77
            self.branchnick_label.set_text(revision.properties['branch-nick'])
78
        except KeyError:
79
            self.branchnick_label.set_text("")
80
256.2.23 by Gary van der Merwe
Show Children
81
        self._add_parents_or_children(revision.parent_ids,
82
                                      self.parents_widgets,
83
                                      self.parents_table)
84
        
85
        if self.show_children:
86
            self._add_parents_or_children(children,
87
                                          self.children_widgets,
88
                                          self.children_table)
89
        
241 by Jelmer Vernooij
Show tags in bzr viz.
90
        self._add_tags(tags)
0.1.1 by Dan Loda
First working version of xannotate.
91
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
92
    def _show_clicked_cb(self, widget, revid, parentid):
93
        """Callback for when the show button for a parent is clicked."""
94
        self._show_callback(revid, parentid)
95
96
    def _go_clicked_cb(self, widget, revid):
97
        """Callback for when the go button for a parent is clicked."""
98
        self._go_callback(revid)
99
241 by Jelmer Vernooij
Show tags in bzr viz.
100
    def _add_tags(self, tags):
101
        if tags == []:
102
            self.tags_list.hide()
103
            self.tags_label.hide()
104
            return
105
106
        for widget in self.tags_widgets:
107
            self.tags_list.remove(widget)
108
242 by Jelmer Vernooij
Avoid cleanup warning.
109
        self.tags_widgets = []
110
241 by Jelmer Vernooij
Show tags in bzr viz.
111
        for tag in tags:
112
            widget = gtk.Label(tag)
113
            widget.set_selectable(True)
114
            self.tags_widgets.append(widget)
115
            self.tags_list.add(widget)
116
        self.tags_list.show_all()
117
        self.tags_label.show_all()
118
        
256.2.23 by Gary van der Merwe
Show Children
119
    def _add_parents_or_children(self, revids, widgets, table):
120
        while len(widgets) > 0:
121
            widget = widgets.pop()
122
            table.remove(widget)
123
        
124
        table.resize(max(len(revids), 1), 2)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
125
256.2.23 by Gary van der Merwe
Show Children
126
        for idx, revid in enumerate(revids):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
127
            align = gtk.Alignment(0.0, 0.0)
256.2.23 by Gary van der Merwe
Show Children
128
            widgets.append(align)
129
            table.attach(align, 1, 2, idx, idx + 1,
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
130
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
131
            align.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
132
133
            hbox = gtk.HBox(False, spacing=6)
134
            align.add(hbox)
135
            hbox.show()
136
137
            image = gtk.Image()
138
            image.set_from_stock(
139
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
140
            image.show()
141
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.
142
            if self._show_callback is not None:
143
                button = gtk.Button()
144
                button.add(image)
145
                button.connect("clicked", self._show_clicked_cb,
256.2.23 by Gary van der Merwe
Show Children
146
                               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.
147
                hbox.pack_start(button, expand=False, fill=True)
148
                button.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
149
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.
150
            if self._go_callback is not None:
256.2.23 by Gary van der Merwe
Show Children
151
                button = gtk.Button(revid)
152
                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.
153
            else:
256.2.23 by Gary van der Merwe
Show Children
154
                button = gtk.Label(revid)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
155
            button.set_use_underline(False)
156
            hbox.pack_start(button, expand=False, fill=True)
157
            button.show()
0.1.1 by Dan Loda
First working version of xannotate.
158
159
    def _create(self):
160
        vbox = gtk.VBox(False, 6)
161
        vbox.set_border_width(6)
162
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
291 by Jelmer Vernooij
Put children widget on a new line.
163
        vbox.pack_start(self._create_parents(), expand=False, fill=True)
164
        if self.show_children:
165
            vbox.pack_start(self._create_children(), expand=False, fill=True)
0.1.1 by Dan Loda
First working version of xannotate.
166
        vbox.pack_start(self._create_message_view())
167
        self.add_with_viewport(vbox)
168
        vbox.show()
169
170
    def _create_headers(self):
241 by Jelmer Vernooij
Show tags in bzr viz.
171
        self.table = gtk.Table(rows=5, columns=2)
0.1.1 by Dan Loda
First working version of xannotate.
172
        self.table.set_row_spacings(6)
173
        self.table.set_col_spacings(6)
174
        self.table.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
175
176
        align = gtk.Alignment(1.0, 0.5)
177
        label = gtk.Label()
178
        label.set_markup("<b>Revision Id:</b>")
179
        align.add(label)
180
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
181
        align.show()
182
        label.show()
183
184
        align = gtk.Alignment(0.0, 0.5)
185
        self.revision_id = gtk.Label()
186
        self.revision_id.set_selectable(True)
187
        align.add(self.revision_id)
188
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
189
        align.show()
190
        self.revision_id.show()
191
0.1.1 by Dan Loda
First working version of xannotate.
192
        align = gtk.Alignment(1.0, 0.5)
259 by Aaron Bentley
Add author support to gannotate and log viewer
193
        self.author_label = gtk.Label()
194
        self.author_label.set_markup("<b>Author:</b>")
195
        align.add(self.author_label)
196
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
197
        align.show()
198
        self.author_label.show()
199
200
        align = gtk.Alignment(0.0, 0.5)
201
        self.author = gtk.Label()
202
        self.author.set_selectable(True)
203
        align.add(self.author)
204
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
205
        align.show()
206
        self.author.show()
207
        self.author.hide()
208
209
        align = gtk.Alignment(1.0, 0.5)
0.1.1 by Dan Loda
First working version of xannotate.
210
        label = gtk.Label()
211
        label.set_markup("<b>Committer:</b>")
212
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
213
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
214
        align.show()
215
        label.show()
216
217
        align = gtk.Alignment(0.0, 0.5)
218
        self.committer = gtk.Label()
219
        self.committer.set_selectable(True)
220
        align.add(self.committer)
259 by Aaron Bentley
Add author support to gannotate and log viewer
221
        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.
222
        align.show()
223
        self.committer.show()
224
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
225
        align = gtk.Alignment(0.0, 0.5)
226
        label = gtk.Label()
227
        label.set_markup("<b>Branch nick:</b>")
228
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
229
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
230
        label.show()
231
        align.show()
232
233
        align = gtk.Alignment(0.0, 0.5)
234
        self.branchnick_label = gtk.Label()
235
        self.branchnick_label.set_selectable(True)
236
        align.add(self.branchnick_label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
237
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
238
        self.branchnick_label.show()
239
        align.show()
240
0.1.1 by Dan Loda
First working version of xannotate.
241
        align = gtk.Alignment(1.0, 0.5)
242
        label = gtk.Label()
243
        label.set_markup("<b>Timestamp:</b>")
244
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
245
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
246
        align.show()
247
        label.show()
248
249
        align = gtk.Alignment(0.0, 0.5)
250
        self.timestamp = gtk.Label()
251
        self.timestamp.set_selectable(True)
252
        align.add(self.timestamp)
259 by Aaron Bentley
Add author support to gannotate and log viewer
253
        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.
254
        align.show()
255
        self.timestamp.show()
256
241 by Jelmer Vernooij
Show tags in bzr viz.
257
        align = gtk.Alignment(1.0, 0.5)
258
        self.tags_label = gtk.Label()
259
        self.tags_label.set_markup("<b>Tags:</b>")
260
        align.add(self.tags_label)
261
        align.show()
261 by Aaron Bentley
Fix tags formatting
262
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
241 by Jelmer Vernooij
Show tags in bzr viz.
263
        self.tags_label.show()
264
265
        align = gtk.Alignment(0.0, 0.5)
266
        self.tags_list = gtk.VBox()
267
        align.add(self.tags_list)
261 by Aaron Bentley
Fix tags formatting
268
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
241 by Jelmer Vernooij
Show tags in bzr viz.
269
        align.show()
270
        self.tags_list.show()
271
        self.tags_widgets = []
272
0.1.1 by Dan Loda
First working version of xannotate.
273
        return self.table
274
256.2.23 by Gary van der Merwe
Show Children
275
    
291 by Jelmer Vernooij
Put children widget on a new line.
276
    def _create_parents(self):
277
        hbox = gtk.HBox(True, 3)
256.2.23 by Gary van der Merwe
Show Children
278
        
279
        self.parents_table = self._create_parents_or_children_table(
280
            "<b>Parents:</b>")
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
281
        self.parents_widgets = []
256.2.23 by Gary van der Merwe
Show Children
282
        hbox.pack_start(self.parents_table)
291 by Jelmer Vernooij
Put children widget on a new line.
283
284
        hbox.show()
285
        return hbox
286
287
    def _create_children(self):
288
        hbox = gtk.HBox(True, 3)
289
        self.children_table = self._create_parents_or_children_table(
290
            "<b>Children:</b>")
291
        self.children_widgets = []
292
        hbox.pack_start(self.children_table)
256.2.23 by Gary van der Merwe
Show Children
293
        hbox.show()
294
        return hbox
295
        
296
    def _create_parents_or_children_table(self, text):
297
        table = gtk.Table(rows=1, columns=2)
298
        table.set_row_spacings(3)
299
        table.set_col_spacings(6)
300
        table.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
301
302
        label = gtk.Label()
256.2.23 by Gary van der Merwe
Show Children
303
        label.set_markup(text)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
304
        align = gtk.Alignment(0.0, 0.5)
305
        align.add(label)
256.2.23 by Gary van der Merwe
Show Children
306
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
307
        label.show()
308
        align.show()
309
256.2.23 by Gary van der Merwe
Show Children
310
        return table
311
    
312
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
313
0.1.1 by Dan Loda
First working version of xannotate.
314
    def _create_message_view(self):
315
        self.message_buffer = gtk.TextBuffer()
316
        tv = gtk.TextView(self.message_buffer)
317
        tv.set_editable(False)
318
        tv.set_wrap_mode(gtk.WRAP_WORD)
319
        tv.modify_font(pango.FontDescription("Monospace"))
320
        tv.show()
321
        return tv
322