/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 branchview/treeview.py

  • Committer: Daniel Schierbeck
  • Date: 2008-04-07 20:34:51 UTC
  • mfrom: (450.6.13 bugs)
  • mto: (463.2.1 bug.78765)
  • mto: This revision was merged to the branch mainline in revision 462.
  • Revision ID: daniel.schierbeck@gmail.com-20080407203451-2i6el7jf9t0k9y64
Merged bug page improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
"""
5
5
 
6
 
__copyright__ = "Copyright © 2005 Canonical Ltd."
 
6
__copyright__ = "Copyright � 2005 Canonical Ltd."
7
7
__author__    = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
8
8
 
9
9
import sys
13
13
import pango
14
14
import re
15
15
import treemodel
16
 
from bzrlib import ui
17
16
 
18
 
from bzrlib.plugins.gtk import _i18n
19
 
from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
20
17
from linegraph import linegraph, same_branch
21
18
from graphcell import CellRendererGraph
22
19
from treemodel import TreeModel
23
20
from bzrlib.revision import NULL_REVISION
24
21
 
25
 
 
26
22
class TreeView(gtk.VBox):
27
23
 
28
24
    __gproperties__ = {
85
81
    }
86
82
 
87
83
    __gsignals__ = {
 
84
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
 
85
                             gobject.TYPE_NONE,
 
86
                             ()),
88
87
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
89
88
                              gobject.TYPE_NONE,
90
89
                              ()),
93
92
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
94
93
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
95
94
                              gobject.TYPE_NONE,
96
 
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
97
 
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
98
 
                              ())
 
95
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
99
96
    }
100
97
 
101
98
    def __init__(self, branch, start, maxnum, compact=True):
110
107
        """
111
108
        gtk.VBox.__init__(self, spacing=0)
112
109
 
113
 
        loading_msg_widget = ProgressPanel()
114
 
        if getattr(ui.ui_factory, "set_nested_progress_bar_widget", None) is not None:
115
 
            ui.ui_factory.set_nested_progress_bar_widget(loading_msg_widget.get_progress_bar)
116
 
        self.pack_start(loading_msg_widget, expand=False, fill=True)
 
110
        self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
 
111
        self.connect('revisions-loaded', 
 
112
                lambda x: self.loading_msg_box.hide())
117
113
 
118
114
        self.scrolled_window = gtk.ScrolledWindow()
119
115
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
123
119
        self.pack_start(self.scrolled_window, expand=True, fill=True)
124
120
 
125
121
        self.scrolled_window.add(self.construct_treeview())
 
122
        
126
123
 
127
124
        self.iter = None
128
125
        self.branch = branch
129
126
        self.revision = None
130
 
        self.index = {}
131
127
 
132
128
        self.start = start
133
129
        self.maxnum = maxnum
183
179
        """Return revision id of currently selected revision, or None."""
184
180
        return self.get_property('revision')
185
181
 
186
 
    def has_revision_id(self, revision_id):
187
 
        return (revision_id in self.index)
188
 
 
189
182
    def set_revision(self, revision):
190
183
        self.set_property('revision', revision)
191
184
 
229
222
        self.emit('tag-added', tag, revid)
230
223
        
231
224
    def refresh(self):
 
225
        self.loading_msg_box.show()
232
226
        gobject.idle_add(self.populate, self.get_revision())
233
227
 
234
228
    def update(self):
282
276
                       should be broken.
283
277
        """
284
278
 
285
 
        self.progress_bar = ui.ui_factory.nested_progress_bar()
286
 
        self.progress_bar.update("Loading ancestry graph", 0, 5)
287
 
 
288
 
        try:
289
 
            if self.compact:
290
 
                broken_line_length = 32
291
 
            else:
292
 
                broken_line_length = None
293
 
            
294
 
            show_graph = self.graph_column.get_visible()
295
 
 
296
 
            self.branch.lock_read()
297
 
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
298
 
                                                            self.start,
299
 
                                                            self.maxnum, 
300
 
                                                            broken_line_length,
301
 
                                                            show_graph,
302
 
                                                            self.mainline_only,
303
 
                                                            self.progress_bar)
304
 
 
305
 
            self.model = TreeModel(self.branch, linegraphdata)
306
 
            self.graph_cell.columns_len = columns_len
307
 
            width = self.graph_cell.get_size(self.treeview)[2]
308
 
            if width > 500:
309
 
                width = 500
310
 
            self.graph_column.set_fixed_width(width)
311
 
            self.graph_column.set_max_width(width)
312
 
            self.index = index
313
 
            self.treeview.set_model(self.model)
314
 
 
315
 
            if not revision or revision == NULL_REVISION:
316
 
                self.treeview.set_cursor(0)
317
 
            else:
318
 
                self.set_revision(revision)
319
 
 
320
 
            self.emit('refreshed')
321
 
            return False
322
 
        finally:
323
 
            self.progress_bar.finished()
 
279
        if self.compact:
 
280
            broken_line_length = 32
 
281
        else:
 
282
            broken_line_length = None
 
283
        
 
284
        show_graph = self.graph_column.get_visible()
 
285
 
 
286
        self.branch.lock_read()
 
287
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
 
288
                                                        self.start,
 
289
                                                        self.maxnum, 
 
290
                                                        broken_line_length,
 
291
                                                        show_graph,
 
292
                                                        self.mainline_only)
 
293
 
 
294
        self.model = TreeModel(self.branch, linegraphdata)
 
295
        self.graph_cell.columns_len = columns_len
 
296
        width = self.graph_cell.get_size(self.treeview)[2]
 
297
        if width > 500:
 
298
            width = 500
 
299
        self.graph_column.set_fixed_width(width)
 
300
        self.graph_column.set_max_width(width)
 
301
        self.index = index
 
302
        self.treeview.set_model(self.model)
 
303
 
 
304
        if revision is None:
 
305
            self.treeview.set_cursor(0)
 
306
        else:
 
307
            self.set_revision(revision)
 
308
 
 
309
        self.emit('revisions-loaded')
 
310
 
 
311
        return False
324
312
 
325
313
    def construct_treeview(self):
326
314
        self.treeview = gtk.TreeView()
333
321
        if set_tooltip is not None:
334
322
            set_tooltip(treemodel.MESSAGE)
335
323
 
336
 
        self._prev_cursor_path = None
337
324
        self.treeview.connect("cursor-changed",
338
325
                self._on_selection_changed)
339
326
 
351
338
        cell.set_property("width-chars", 15)
352
339
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
353
340
        self.revno_column = gtk.TreeViewColumn("Revision No")
354
 
        self.revno_column.set_resizable(False)
 
341
        self.revno_column.set_resizable(True)
355
342
        self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
356
343
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
357
344
        self.revno_column.pack_start(cell, expand=True)
360
347
 
361
348
        self.graph_cell = CellRendererGraph()
362
349
        self.graph_column = gtk.TreeViewColumn()
363
 
        self.graph_column.set_resizable(False)
 
350
        self.graph_column.set_resizable(True)
364
351
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
365
 
        self.graph_column.pack_start(self.graph_cell, expand=True)
 
352
        self.graph_column.pack_start(self.graph_cell, expand=False)
366
353
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
367
354
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
368
355
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
373
360
        cell.set_property("width-chars", 65)
374
361
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
375
362
        self.summary_column = gtk.TreeViewColumn("Summary")
376
 
        self.summary_column.set_resizable(False)
377
 
        self.summary_column.set_expand(True)
 
363
        self.summary_column.set_resizable(True)
378
364
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
379
365
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
380
366
        self.summary_column.pack_start(cell, expand=True)
385
371
        cell.set_property("width-chars", 15)
386
372
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
387
373
        self.committer_column = gtk.TreeViewColumn("Committer")
388
 
        self.committer_column.set_resizable(False)
 
374
        self.committer_column.set_resizable(True)
389
375
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
390
 
        self.committer_column.set_fixed_width(200)
 
376
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
391
377
        self.committer_column.pack_start(cell, expand=True)
392
378
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
393
379
        self.treeview.append_column(self.committer_column)
397
383
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
398
384
        self.date_column = gtk.TreeViewColumn("Date")
399
385
        self.date_column.set_visible(False)
400
 
        self.date_column.set_resizable(False)
 
386
        self.date_column.set_resizable(True)
401
387
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
402
 
        self.date_column.set_fixed_width(130)
 
388
        self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])
403
389
        self.date_column.pack_start(cell, expand=True)
404
390
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
405
391
        self.treeview.append_column(self.date_column)
406
392
        
407
393
        return self.treeview
408
394
    
 
395
    def construct_loading_msg(self):
 
396
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
397
                                                 gtk.ICON_SIZE_BUTTON)
 
398
        image_loading.show()
 
399
        
 
400
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
 
401
        label_loading.set_alignment(0.0, 0.5)
 
402
        label_loading.show()
 
403
        
 
404
        self.loading_msg_box = gtk.HBox()
 
405
        self.loading_msg_box.set_spacing(5)
 
406
        self.loading_msg_box.set_border_width(5)        
 
407
        self.loading_msg_box.pack_start(image_loading, False, False)
 
408
        self.loading_msg_box.pack_start(label_loading, True, True)
 
409
        self.loading_msg_box.show()
 
410
        
 
411
        return self.loading_msg_box
 
412
 
409
413
    def _on_selection_changed(self, treeview):
410
414
        """callback for when the treeview changes."""
411
415
        (path, focus) = treeview.get_cursor()
412
 
        if (path is not None) and (path != self._prev_cursor_path):
413
 
            self._prev_cursor_path = path # avoid emitting twice per click
 
416
        if path is not None:
414
417
            self.iter = self.model.get_iter(path)
415
418
            self.emit('revision-selected')
416
419
 
417
420
    def _on_revision_selected(self, widget, event):
418
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
 
421
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
419
422
        if event.button == 3:
420
 
            menu = RevisionMenu(self.branch.repository, 
 
423
            menu = RevisionPopupMenu(self.branch.repository, 
421
424
                [self.get_revision().revision_id],
422
425
                self.branch)
423
426
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))