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