/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: Vincent Ladeuil
  • Date: 2009-06-10 16:38:37 UTC
  • mto: This revision was merged to the branch mainline in revision 648.
  • Revision ID: v.ladeuil+lp@free.fr-20090610163837-8n8122j38ozwd5ef
Fix #385191 by using the new progress reporting API.

* ui.py:
(GtkProgressBar): Simplified, we don't need to inherit from
_BaseProgressBar.
(GtkProgressBar.update): Show the widget.
(ProgressBarWindow.__init__): Simplified. Don't show
unconditionally.
(ProgressBarWindow.update): Show the widget.
(ProgressPanel.update): Show the widget.
(GtkUIFactory.__init__): Simplified.
(GtkUIFactory._progress_all_finished): 

* branchview/treeview.py:
(TreeView.__init__): Set the progress reporting widget.

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
16
17
 
17
18
from bzrlib.plugins.gtk import _i18n
 
19
from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
18
20
from linegraph import linegraph, same_branch
19
21
from graphcell import CellRendererGraph
20
22
from treemodel import TreeModel
21
23
from bzrlib.revision import NULL_REVISION
22
24
 
 
25
 
23
26
class TreeView(gtk.VBox):
24
27
 
25
28
    __gproperties__ = {
82
85
    }
83
86
 
84
87
    __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))
 
96
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
 
97
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
 
98
                              ())
97
99
    }
98
100
 
99
101
    def __init__(self, branch, start, maxnum, compact=True):
108
110
        """
109
111
        gtk.VBox.__init__(self, spacing=0)
110
112
 
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())
 
113
        loading_msg_widget = ProgressPanel()
 
114
        # FIXME: Why is the following needed ? Are there really cases where we
 
115
        # use a TreeView without installing our own ui ? --vila 20090610
 
116
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
117
            ui.ui_factory.set_progress_bar_widget(loading_msg_widget)
 
118
        self.pack_start(loading_msg_widget, expand=False, fill=True)
114
119
 
115
120
        self.scrolled_window = gtk.ScrolledWindow()
116
121
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
120
125
        self.pack_start(self.scrolled_window, expand=True, fill=True)
121
126
 
122
127
        self.scrolled_window.add(self.construct_treeview())
123
 
        
124
128
 
125
129
        self.iter = None
126
130
        self.branch = branch
127
131
        self.revision = None
 
132
        self.index = {}
128
133
 
129
134
        self.start = start
130
135
        self.maxnum = maxnum
180
185
        """Return revision id of currently selected revision, or None."""
181
186
        return self.get_property('revision')
182
187
 
 
188
    def has_revision_id(self, revision_id):
 
189
        return (revision_id in self.index)
 
190
 
183
191
    def set_revision(self, revision):
184
192
        self.set_property('revision', revision)
185
193
 
223
231
        self.emit('tag-added', tag, revid)
224
232
        
225
233
    def refresh(self):
226
 
        self.loading_msg_box.show()
227
234
        gobject.idle_add(self.populate, self.get_revision())
228
235
 
229
236
    def update(self):
277
284
                       should be broken.
278
285
        """
279
286
 
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,
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
 
287
        self.progress_bar = ui.ui_factory.nested_progress_bar()
 
288
        self.progress_bar.update("Loading ancestry graph", 0, 5)
 
289
 
 
290
        try:
 
291
            if self.compact:
 
292
                broken_line_length = 32
 
293
            else:
 
294
                broken_line_length = None
 
295
            
 
296
            show_graph = self.graph_column.get_visible()
 
297
 
 
298
            self.branch.lock_read()
 
299
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
 
300
                                                            self.start,
 
301
                                                            self.maxnum, 
 
302
                                                            broken_line_length,
 
303
                                                            show_graph,
 
304
                                                            self.mainline_only,
 
305
                                                            self.progress_bar)
 
306
 
 
307
            self.model = TreeModel(self.branch, linegraphdata)
 
308
            self.graph_cell.columns_len = columns_len
 
309
            width = self.graph_cell.get_size(self.treeview)[2]
 
310
            if width > 500:
 
311
                width = 500
 
312
            self.graph_column.set_fixed_width(width)
 
313
            self.graph_column.set_max_width(width)
 
314
            self.index = index
 
315
            self.treeview.set_model(self.model)
 
316
 
 
317
            if not revision or revision == NULL_REVISION:
 
318
                self.treeview.set_cursor(0)
 
319
            else:
 
320
                self.set_revision(revision)
 
321
 
 
322
            self.emit('refreshed')
 
323
            return False
 
324
        finally:
 
325
            self.progress_bar.finished()
313
326
 
314
327
    def construct_treeview(self):
315
328
        self.treeview = gtk.TreeView()
322
335
        if set_tooltip is not None:
323
336
            set_tooltip(treemodel.MESSAGE)
324
337
 
 
338
        self._prev_cursor_path = None
325
339
        self.treeview.connect("cursor-changed",
326
340
                self._on_selection_changed)
327
341
 
394
408
        
395
409
        return self.treeview
396
410
    
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
 
 
416
411
    def _on_selection_changed(self, treeview):
417
412
        """callback for when the treeview changes."""
418
413
        (path, focus) = treeview.get_cursor()
419
 
        if path is not None:
 
414
        if (path is not None) and (path != self._prev_cursor_path):
 
415
            self._prev_cursor_path = path # avoid emitting twice per click
420
416
            self.iter = self.model.get_iter(path)
421
417
            self.emit('revision-selected')
422
418
 
423
419
    def _on_revision_selected(self, widget, event):
424
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
420
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
425
421
        if event.button == 3:
426
 
            menu = RevisionPopupMenu(self.branch.repository, 
 
422
            menu = RevisionMenu(self.branch.repository, 
427
423
                [self.get_revision().revision_id],
428
424
                self.branch)
429
425
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))