/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to revisionview.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-07-16 16:27:59 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060716162759-f3e8596921edc374
2006-07-16  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * Done some directory reorganization.
    * setup.py: added some basic install script
    * Began to implement the GTK UI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
2
 
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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
 
from bzrlib.util import bencode
25
 
 
26
 
class RevisionView(gtk.Notebook):
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
 
 
33
 
    def __init__(self, revision=None, tags=[],
34
 
                 show_children=False, branch=None):
35
 
        gtk.Notebook.__init__(self)
36
 
        self.show_children = show_children
37
 
 
38
 
        self._create_general()
39
 
        self._create_relations()
40
 
        self._create_signatures()
41
 
        self._create_file_info_view()
42
 
 
43
 
        self.set_current_page(0)
44
 
        
45
 
        self._show_callback = None
46
 
        self._go_callback = None
47
 
        self._clicked_callback = None
48
 
 
49
 
        self._branch = branch
50
 
 
51
 
        if revision is not None:
52
 
            self.set_revision(revision, tags=tags)
53
 
        self.set_file_id(None)
54
 
 
55
 
    def set_show_callback(self, callback):
56
 
        self._show_callback = callback
57
 
 
58
 
    def set_go_callback(self, callback):
59
 
        self._go_callback = callback
60
 
 
61
 
    def set_file_id(self, file_id):
62
 
        """Set a specific file id that we want to track.
63
 
 
64
 
        This just effects the display of a per-file commit message.
65
 
        If it is set to None, then all commit messages will be shown.
66
 
        """
67
 
        self._file_id = file_id
68
 
 
69
 
    def set_revision(self, revision, tags=[], children=[]):
70
 
        self._revision = revision
71
 
        self.revision_id.set_text(revision.revision_id)
72
 
        if revision.committer is not None:
73
 
            self.committer.set_text(revision.committer)
74
 
        else:
75
 
            self.committer.set_text("")
76
 
        author = revision.properties.get('author', '')
77
 
        if author != '':
78
 
            self.author.set_text(author)
79
 
            self.author.show()
80
 
            self.author_label.show()
81
 
        else:
82
 
            self.author.hide()
83
 
            self.author_label.hide()
84
 
 
85
 
        if revision.timestamp is not None:
86
 
            self.timestamp.set_text(format_date(revision.timestamp,
87
 
                                                revision.timezone))
88
 
        self.message_buffer.set_text(revision.message)
89
 
        try:
90
 
            self.branchnick_label.set_text(revision.properties['branch-nick'])
91
 
        except KeyError:
92
 
            self.branchnick_label.set_text("")
93
 
 
94
 
        self._add_parents_or_children(revision.parent_ids,
95
 
                                      self.parents_widgets,
96
 
                                      self.parents_table)
97
 
        
98
 
        if self.show_children:
99
 
            self._add_parents_or_children(children,
100
 
                                          self.children_widgets,
101
 
                                          self.children_table)
102
 
        
103
 
        self._add_tags(tags)
104
 
 
105
 
        file_info = revision.properties.get('file-info', None)
106
 
        if file_info is not None:
107
 
            file_info = bencode.bdecode(file_info.encode('UTF-8'))
108
 
 
109
 
        if file_info:
110
 
            if self._file_id is None:
111
 
                text = []
112
 
                for fi in file_info:
113
 
                    text.append('%(path)s\n%(message)s' % fi)
114
 
                self.file_info_buffer.set_text('\n'.join(text))
115
 
                self.file_info_box.show()
116
 
            else:
117
 
                text = []
118
 
                for fi in file_info:
119
 
                    if fi['file_id'] == self._file_id:
120
 
                        text.append(fi['message'])
121
 
                if text:
122
 
                    self.file_info_buffer.set_text('\n'.join(text))
123
 
                    self.file_info_box.show()
124
 
                else:
125
 
                    self.file_info_box.hide()
126
 
        else:
127
 
            self.file_info_box.hide()
128
 
 
129
 
        if self._branch is not None and self._branch.repository.has_signature_for_revision_id(revision.revision_id):
130
 
            self.signature_image.set_from_file("icons/sign-bad.png")
131
 
            self.signature_label.set_text("This revision has been signed, but the authenticity of the signature cannot be verified.")
132
 
        else:
133
 
            self.signature_image.set_from_file("icons/sign-unknown.png")
134
 
            self.signature_label.set_text("This revision has not been signed.")
135
 
 
136
 
    def _show_clicked_cb(self, widget, revid, parentid):
137
 
        """Callback for when the show button for a parent is clicked."""
138
 
        self._show_callback(revid, parentid)
139
 
 
140
 
    def _go_clicked_cb(self, widget, revid):
141
 
        """Callback for when the go button for a parent is clicked."""
142
 
        self._go_callback(revid)
143
 
 
144
 
    def _add_tags(self, tags):
145
 
        if tags == []:
146
 
            self.tags_list.hide()
147
 
            self.tags_label.hide()
148
 
            return
149
 
 
150
 
        for widget in self.tags_widgets:
151
 
            self.tags_list.remove(widget)
152
 
 
153
 
        self.tags_widgets = []
154
 
 
155
 
        for tag in tags:
156
 
            widget = gtk.Label(tag)
157
 
            widget.set_selectable(True)
158
 
            self.tags_widgets.append(widget)
159
 
            self.tags_list.add(widget)
160
 
        self.tags_list.show_all()
161
 
        self.tags_label.show_all()
162
 
        
163
 
    def _add_parents_or_children(self, revids, widgets, table):
164
 
        while len(widgets) > 0:
165
 
            widget = widgets.pop()
166
 
            table.remove(widget)
167
 
        
168
 
        table.resize(max(len(revids), 1), 2)
169
 
 
170
 
        for idx, revid in enumerate(revids):
171
 
            align = gtk.Alignment(0.0, 0.0)
172
 
            widgets.append(align)
173
 
            table.attach(align, 1, 2, idx, idx + 1,
174
 
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
175
 
            align.show()
176
 
 
177
 
            hbox = gtk.HBox(False, spacing=6)
178
 
            align.add(hbox)
179
 
            hbox.show()
180
 
 
181
 
            image = gtk.Image()
182
 
            image.set_from_stock(
183
 
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
184
 
            image.show()
185
 
 
186
 
            if self._show_callback is not None:
187
 
                button = gtk.Button()
188
 
                button.add(image)
189
 
                button.connect("clicked", self._show_clicked_cb,
190
 
                               self._revision.revision_id, revid)
191
 
                hbox.pack_start(button, expand=False, fill=True)
192
 
                button.show()
193
 
 
194
 
            if self._go_callback is not None:
195
 
                button = gtk.Button(revid)
196
 
                button.connect("clicked", self._go_clicked_cb, revid)
197
 
            else:
198
 
                button = gtk.Label(revid)
199
 
            button.set_use_underline(False)
200
 
            hbox.pack_start(button, expand=False, fill=True)
201
 
            button.show()
202
 
 
203
 
    def _create_general(self):
204
 
        vbox = gtk.VBox(False, 6)
205
 
        vbox.set_border_width(6)
206
 
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
207
 
        vbox.pack_start(self._create_message_view())
208
 
        self.append_page(vbox, tab_label=gtk.Label("General"))
209
 
        vbox.show()
210
 
 
211
 
    def _create_relations(self):
212
 
        vbox = gtk.VBox(False, 6)
213
 
        vbox.set_border_width(6)
214
 
        vbox.pack_start(self._create_parents(), expand=False, fill=True)
215
 
        if self.show_children:
216
 
            vbox.pack_start(self._create_children(), expand=False, fill=True)
217
 
        self.append_page(vbox, tab_label=gtk.Label("Relations"))
218
 
        vbox.show()
219
 
 
220
 
    def _create_headers(self):
221
 
        self.table = gtk.Table(rows=5, columns=2)
222
 
        self.table.set_row_spacings(6)
223
 
        self.table.set_col_spacings(6)
224
 
        self.table.show()
225
 
 
226
 
        align = gtk.Alignment(1.0, 0.5)
227
 
        label = gtk.Label()
228
 
        label.set_markup("<b>Revision Id:</b>")
229
 
        align.add(label)
230
 
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
231
 
        align.show()
232
 
        label.show()
233
 
 
234
 
        align = gtk.Alignment(0.0, 0.5)
235
 
        self.revision_id = gtk.Label()
236
 
        self.revision_id.set_selectable(True)
237
 
        align.add(self.revision_id)
238
 
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
239
 
        align.show()
240
 
        self.revision_id.show()
241
 
 
242
 
        align = gtk.Alignment(1.0, 0.5)
243
 
        self.author_label = gtk.Label()
244
 
        self.author_label.set_markup("<b>Author:</b>")
245
 
        align.add(self.author_label)
246
 
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
247
 
        align.show()
248
 
        self.author_label.show()
249
 
 
250
 
        align = gtk.Alignment(0.0, 0.5)
251
 
        self.author = gtk.Label()
252
 
        self.author.set_selectable(True)
253
 
        align.add(self.author)
254
 
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
255
 
        align.show()
256
 
        self.author.show()
257
 
        self.author.hide()
258
 
 
259
 
        align = gtk.Alignment(1.0, 0.5)
260
 
        label = gtk.Label()
261
 
        label.set_markup("<b>Committer:</b>")
262
 
        align.add(label)
263
 
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
264
 
        align.show()
265
 
        label.show()
266
 
 
267
 
        align = gtk.Alignment(0.0, 0.5)
268
 
        self.committer = gtk.Label()
269
 
        self.committer.set_selectable(True)
270
 
        align.add(self.committer)
271
 
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
272
 
        align.show()
273
 
        self.committer.show()
274
 
 
275
 
        align = gtk.Alignment(0.0, 0.5)
276
 
        label = gtk.Label()
277
 
        label.set_markup("<b>Branch nick:</b>")
278
 
        align.add(label)
279
 
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
280
 
        label.show()
281
 
        align.show()
282
 
 
283
 
        align = gtk.Alignment(0.0, 0.5)
284
 
        self.branchnick_label = gtk.Label()
285
 
        self.branchnick_label.set_selectable(True)
286
 
        align.add(self.branchnick_label)
287
 
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
288
 
        self.branchnick_label.show()
289
 
        align.show()
290
 
 
291
 
        align = gtk.Alignment(1.0, 0.5)
292
 
        label = gtk.Label()
293
 
        label.set_markup("<b>Timestamp:</b>")
294
 
        align.add(label)
295
 
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
296
 
        align.show()
297
 
        label.show()
298
 
 
299
 
        align = gtk.Alignment(0.0, 0.5)
300
 
        self.timestamp = gtk.Label()
301
 
        self.timestamp.set_selectable(True)
302
 
        align.add(self.timestamp)
303
 
        self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
304
 
        align.show()
305
 
        self.timestamp.show()
306
 
 
307
 
        align = gtk.Alignment(1.0, 0.5)
308
 
        self.tags_label = gtk.Label()
309
 
        self.tags_label.set_markup("<b>Tags:</b>")
310
 
        align.add(self.tags_label)
311
 
        align.show()
312
 
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
313
 
        self.tags_label.show()
314
 
 
315
 
        align = gtk.Alignment(0.0, 0.5)
316
 
        self.tags_list = gtk.VBox()
317
 
        align.add(self.tags_list)
318
 
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
319
 
        align.show()
320
 
        self.tags_list.show()
321
 
        self.tags_widgets = []
322
 
 
323
 
        return self.table
324
 
 
325
 
    
326
 
    def _create_parents(self):
327
 
        hbox = gtk.HBox(True, 3)
328
 
        
329
 
        self.parents_table = self._create_parents_or_children_table(
330
 
            "<b>Parents:</b>")
331
 
        self.parents_widgets = []
332
 
        hbox.pack_start(self.parents_table)
333
 
 
334
 
        hbox.show()
335
 
        return hbox
336
 
 
337
 
    def _create_children(self):
338
 
        hbox = gtk.HBox(True, 3)
339
 
        self.children_table = self._create_parents_or_children_table(
340
 
            "<b>Children:</b>")
341
 
        self.children_widgets = []
342
 
        hbox.pack_start(self.children_table)
343
 
        hbox.show()
344
 
        return hbox
345
 
        
346
 
    def _create_parents_or_children_table(self, text):
347
 
        table = gtk.Table(rows=1, columns=2)
348
 
        table.set_row_spacings(3)
349
 
        table.set_col_spacings(6)
350
 
        table.show()
351
 
 
352
 
        label = gtk.Label()
353
 
        label.set_markup(text)
354
 
        align = gtk.Alignment(0.0, 0.5)
355
 
        align.add(label)
356
 
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
357
 
        label.show()
358
 
        align.show()
359
 
 
360
 
        return table
361
 
    
362
 
 
363
 
 
364
 
    def _create_message_view(self):
365
 
        self.message_buffer = gtk.TextBuffer()
366
 
        window = gtk.ScrolledWindow()
367
 
        window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
368
 
        window.set_shadow_type(gtk.SHADOW_IN)
369
 
        tv = gtk.TextView(self.message_buffer)
370
 
        tv.set_editable(False)
371
 
        tv.set_wrap_mode(gtk.WRAP_WORD)
372
 
        tv.modify_font(pango.FontDescription("Monospace"))
373
 
        tv.show()
374
 
        window.add(tv)
375
 
        window.show()
376
 
        return window
377
 
 
378
 
    def _create_signatures(self):
379
 
        signature_box = gtk.Table(rows=1, columns=2)
380
 
        signature_box.set_col_spacing(0, 12)
381
 
 
382
 
        self.signature_image = gtk.Image()
383
 
        signature_box.attach(self.signature_image, 0, 1, 0, 1, gtk.FILL)
384
 
 
385
 
        self.signature_label = gtk.Label()
386
 
        signature_box.attach(self.signature_label, 1, 2, 0, 1, gtk.FILL)
387
 
 
388
 
        box = gtk.VBox(False, 6)
389
 
        box.set_border_width(6)
390
 
        box.pack_start(signature_box, expand=False)
391
 
        box.show_all()
392
 
        self.append_page(box, tab_label=gtk.Label("Signatures"))
393
 
 
394
 
    def _create_file_info_view(self):
395
 
        self.file_info_box = gtk.VBox(False, 6)
396
 
        self.file_info_box.set_border_width(6)
397
 
        self.file_info_buffer = gtk.TextBuffer()
398
 
        window = gtk.ScrolledWindow()
399
 
        window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
400
 
        window.set_shadow_type(gtk.SHADOW_IN)
401
 
        tv = gtk.TextView(self.file_info_buffer)
402
 
        tv.set_editable(False)
403
 
        tv.set_wrap_mode(gtk.WRAP_WORD)
404
 
        tv.modify_font(pango.FontDescription("Monospace"))
405
 
        tv.show()
406
 
        window.add(tv)
407
 
        window.show()
408
 
        self.file_info_box.pack_start(window)
409
 
        self.file_info_box.hide() # Only shown when there are per-file messages
410
 
        self.append_page(self.file_info_box, tab_label=gtk.Label('Per-file'))
411