/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-15 06:53:53 UTC
  • mto: This revision was merged to the branch mainline in revision 649.
  • Revision ID: v.ladeuil+lp@free.fr-20090615065353-nxyyk6lj8te4ciiw
Fix refresh warnings and progress widget usage.

* branchview/treeview.py:
(TreeView.__init__): Make the proress widget an attribute. Don't
keep an GtkIter, they are not persistent, keep the path instead.
(TreeView.do_get_property): Convert path to iter when needed.
(TreeView._on_selection_changed): Memorize path, not iter.
(TreeView.populate): Use our own widget if we can.

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
        self.progress_widget = ProgressPanel()
 
114
        self.pack_start(self.progress_widget, expand=False, fill=True)
114
115
 
115
116
        self.scrolled_window = gtk.ScrolledWindow()
116
117
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
120
121
        self.pack_start(self.scrolled_window, expand=True, fill=True)
121
122
 
122
123
        self.scrolled_window.add(self.construct_treeview())
123
 
        
124
124
 
125
 
        self.iter = None
 
125
        self.path = None
126
126
        self.branch = branch
127
127
        self.revision = None
 
128
        self.index = {}
128
129
 
129
130
        self.start = start
130
131
        self.maxnum = maxnum
148
149
        elif property.name == 'branch':
149
150
            return self.branch
150
151
        elif property.name == 'revision':
151
 
            return self.model.get_value(self.iter, treemodel.REVISION)
 
152
            return self.model.get_value(self.model.get_iter(self.path),
 
153
                                        treemodel.REVISION)
152
154
        elif property.name == 'revision-number':
153
 
            return self.model.get_value(self.iter, treemodel.REVNO)
 
155
            return self.model.get_value(self.model.get_iter(self.path),
 
156
                                        treemodel.REVNO)
154
157
        elif property.name == 'children':
155
 
            return self.model.get_value(self.iter, treemodel.CHILDREN)
 
158
            return self.model.get_value(self.model.get_iter(self.path),
 
159
                                        treemodel.CHILDREN)
156
160
        elif property.name == 'parents':
157
 
            return self.model.get_value(self.iter, treemodel.PARENTS)
 
161
            return self.model.get_value(self.model.get_iter(self.path),
 
162
                                        treemodel.PARENTS)
158
163
        else:
159
164
            raise AttributeError, 'unknown property %s' % property.name
160
165
 
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
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
288
            # We'are using our own ui, let's tell it to use our widget.
 
289
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
 
290
        self.progress_bar = ui.ui_factory.nested_progress_bar()
 
291
        self.progress_bar.update("Loading ancestry graph", 0, 5)
 
292
 
 
293
        try:
 
294
            if self.compact:
 
295
                broken_line_length = 32
 
296
            else:
 
297
                broken_line_length = None
 
298
            
 
299
            show_graph = self.graph_column.get_visible()
 
300
 
 
301
            self.branch.lock_read()
 
302
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
 
303
                                                            self.start,
 
304
                                                            self.maxnum, 
 
305
                                                            broken_line_length,
 
306
                                                            show_graph,
 
307
                                                            self.mainline_only,
 
308
                                                            self.progress_bar)
 
309
 
 
310
            self.model = TreeModel(self.branch, linegraphdata)
 
311
            self.graph_cell.columns_len = columns_len
 
312
            width = self.graph_cell.get_size(self.treeview)[2]
 
313
            if width > 500:
 
314
                width = 500
 
315
            self.graph_column.set_fixed_width(width)
 
316
            self.graph_column.set_max_width(width)
 
317
            self.index = index
 
318
            self.treeview.set_model(self.model)
 
319
 
 
320
            if not revision or revision == NULL_REVISION:
 
321
                self.treeview.set_cursor(0)
 
322
            else:
 
323
                self.set_revision(revision)
 
324
 
 
325
            self.emit('refreshed')
 
326
            return False
 
327
        finally:
 
328
            self.progress_bar.finished()
313
329
 
314
330
    def construct_treeview(self):
315
331
        self.treeview = gtk.TreeView()
322
338
        if set_tooltip is not None:
323
339
            set_tooltip(treemodel.MESSAGE)
324
340
 
 
341
        self._prev_cursor_path = None
325
342
        self.treeview.connect("cursor-changed",
326
343
                self._on_selection_changed)
327
344
 
394
411
        
395
412
        return self.treeview
396
413
    
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
414
    def _on_selection_changed(self, treeview):
417
415
        """callback for when the treeview changes."""
418
416
        (path, focus) = treeview.get_cursor()
419
 
        if path is not None:
420
 
            self.iter = self.model.get_iter(path)
 
417
        if (path is not None) and (path != self._prev_cursor_path):
 
418
            self._prev_cursor_path = path # avoid emitting twice per click
 
419
            self.path = path
421
420
            self.emit('revision-selected')
422
421
 
423
422
    def _on_revision_selected(self, widget, event):
424
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
423
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
425
424
        if event.button == 3:
426
 
            menu = RevisionPopupMenu(self.branch.repository, 
 
425
            menu = RevisionMenu(self.branch.repository, 
427
426
                [self.get_revision().revision_id],
428
427
                self.branch)
429
428
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))