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