/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: Jelmer Vernooij
  • Date: 2008-06-29 15:47:30 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629154730-xfsotoxwkiytf0ph
Pass graph object rather than full repository to linegraph.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
import pango
14
14
import re
15
15
import treemodel
16
 
from bzrlib import ui
17
16
 
18
17
from bzrlib.plugins.gtk import _i18n
19
 
from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
20
18
from linegraph import linegraph, same_branch
21
19
from graphcell import CellRendererGraph
22
20
from treemodel import TreeModel
23
21
from bzrlib.revision import NULL_REVISION
24
22
 
25
 
 
26
23
class TreeView(gtk.VBox):
27
24
 
28
25
    __gproperties__ = {
85
82
    }
86
83
 
87
84
    __gsignals__ = {
 
85
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
 
86
                             gobject.TYPE_NONE,
 
87
                             ()),
88
88
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
89
89
                              gobject.TYPE_NONE,
90
90
                              ()),
93
93
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
94
94
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
95
95
                              gobject.TYPE_NONE,
96
 
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
97
 
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
98
 
                              ())
 
96
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
99
97
    }
100
98
 
101
99
    def __init__(self, branch, start, maxnum, compact=True):
110
108
        """
111
109
        gtk.VBox.__init__(self, spacing=0)
112
110
 
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)
 
111
        self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
 
112
        self.connect('revisions-loaded', 
 
113
                lambda x: self.loading_msg_box.hide())
117
114
 
118
115
        self.scrolled_window = gtk.ScrolledWindow()
119
116
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
123
120
        self.pack_start(self.scrolled_window, expand=True, fill=True)
124
121
 
125
122
        self.scrolled_window.add(self.construct_treeview())
 
123
        
126
124
 
127
125
        self.iter = None
128
126
        self.branch = branch
129
127
        self.revision = None
130
 
        self.index = {}
131
128
 
132
129
        self.start = start
133
130
        self.maxnum = maxnum
183
180
        """Return revision id of currently selected revision, or None."""
184
181
        return self.get_property('revision')
185
182
 
186
 
    def has_revision_id(self, revision_id):
187
 
        return (revision_id in self.index)
188
 
 
189
183
    def set_revision(self, revision):
190
184
        self.set_property('revision', revision)
191
185
 
229
223
        self.emit('tag-added', tag, revid)
230
224
        
231
225
    def refresh(self):
 
226
        self.loading_msg_box.show()
232
227
        gobject.idle_add(self.populate, self.get_revision())
233
228
 
234
229
    def update(self):
282
277
                       should be broken.
283
278
        """
284
279
 
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()
 
280
        if self.compact:
 
281
            broken_line_length = 32
 
282
        else:
 
283
            broken_line_length = None
 
284
        
 
285
        show_graph = self.graph_column.get_visible()
 
286
 
 
287
        self.branch.lock_read()
 
288
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
 
289
                                                        (self.start,) , # Sequence of start revisions
 
290
                                                        self.maxnum, 
 
291
                                                        broken_line_length,
 
292
                                                        show_graph,
 
293
                                                        self.mainline_only)
 
294
 
 
295
        self.model = TreeModel(self.branch, linegraphdata)
 
296
        self.graph_cell.columns_len = columns_len
 
297
        width = self.graph_cell.get_size(self.treeview)[2]
 
298
        if width > 500:
 
299
            width = 500
 
300
        self.graph_column.set_fixed_width(width)
 
301
        self.graph_column.set_max_width(width)
 
302
        self.index = index
 
303
        self.treeview.set_model(self.model)
 
304
 
 
305
        if not revision or revision == NULL_REVISION:
 
306
            self.treeview.set_cursor(0)
 
307
        else:
 
308
            self.set_revision(revision)
 
309
 
 
310
        self.emit('revisions-loaded')
 
311
 
 
312
        return False
324
313
 
325
314
    def construct_treeview(self):
326
315
        self.treeview = gtk.TreeView()
333
322
        if set_tooltip is not None:
334
323
            set_tooltip(treemodel.MESSAGE)
335
324
 
336
 
        self._prev_cursor_path = None
337
325
        self.treeview.connect("cursor-changed",
338
326
                self._on_selection_changed)
339
327
 
406
394
        
407
395
        return self.treeview
408
396
    
 
397
    def construct_loading_msg(self):
 
398
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
399
                                                 gtk.ICON_SIZE_BUTTON)
 
400
        image_loading.show()
 
401
        
 
402
        label_loading = gtk.Label(
 
403
            _i18n("Please wait, loading ancestral graph..."))
 
404
        label_loading.set_alignment(0.0, 0.5)
 
405
        label_loading.show()
 
406
        
 
407
        self.loading_msg_box = gtk.HBox()
 
408
        self.loading_msg_box.set_spacing(5)
 
409
        self.loading_msg_box.set_border_width(5)        
 
410
        self.loading_msg_box.pack_start(image_loading, False, False)
 
411
        self.loading_msg_box.pack_start(label_loading, True, True)
 
412
        self.loading_msg_box.show()
 
413
        
 
414
        return self.loading_msg_box
 
415
 
409
416
    def _on_selection_changed(self, treeview):
410
417
        """callback for when the treeview changes."""
411
418
        (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
 
419
        if path is not None:
414
420
            self.iter = self.model.get_iter(path)
415
421
            self.emit('revision-selected')
416
422
 
417
423
    def _on_revision_selected(self, widget, event):
418
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
 
424
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
419
425
        if event.button == 3:
420
 
            menu = RevisionMenu(self.branch.repository, 
 
426
            menu = RevisionPopupMenu(self.branch.repository, 
421
427
                [self.get_revision().revision_id],
422
428
                self.branch)
423
429
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))