/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: Andrew Starr-Bochicchio
  • Date: 2011-02-15 00:15:40 UTC
  • mfrom: (709 bzr-gtk)
  • mto: This revision was merged to the branch mainline in revision 711.
  • Revision ID: a.starr.b@gmail.com-20110215001540-ivb00xv8s8ma1vn1
Re-merge on trunk, resolving one conflict.

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)
 
115
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
116
            # We'are using our own ui, let's tell it to use our widget.
 
117
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
114
118
 
115
119
        self.scrolled_window = gtk.ScrolledWindow()
116
120
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
120
124
        self.pack_start(self.scrolled_window, expand=True, fill=True)
121
125
 
122
126
        self.scrolled_window.add(self.construct_treeview())
123
 
        
124
127
 
125
 
        self.iter = None
 
128
        self.path = None
126
129
        self.branch = branch
127
130
        self.revision = None
 
131
        self.index = {}
128
132
 
129
133
        self.start = start
130
134
        self.maxnum = maxnum
132
136
 
133
137
        gobject.idle_add(self.populate)
134
138
 
135
 
        self.connect("destroy", lambda x: self.branch.unlock())
 
139
        self.connect("destroy", self._on_destroy)
 
140
 
 
141
    def _on_destroy(self, *ignored):
 
142
        self.branch.unlock()
 
143
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
144
            # We'are using our own ui, let's tell it to stop using our widget.
 
145
            ui.ui_factory.set_progress_bar_widget(None)
136
146
 
137
147
    def do_get_property(self, property):
138
148
        if property.name == 'revno-column-visible':
148
158
        elif property.name == 'branch':
149
159
            return self.branch
150
160
        elif property.name == 'revision':
151
 
            return self.model.get_value(self.iter, treemodel.REVISION)
 
161
            return self.model.get_value(self.model.get_iter(self.path),
 
162
                                        treemodel.REVISION)
152
163
        elif property.name == 'revision-number':
153
 
            return self.model.get_value(self.iter, treemodel.REVNO)
 
164
            return self.model.get_value(self.model.get_iter(self.path),
 
165
                                        treemodel.REVNO)
154
166
        elif property.name == 'children':
155
 
            return self.model.get_value(self.iter, treemodel.CHILDREN)
 
167
            return self.model.get_value(self.model.get_iter(self.path),
 
168
                                        treemodel.CHILDREN)
156
169
        elif property.name == 'parents':
157
 
            return self.model.get_value(self.iter, treemodel.PARENTS)
 
170
            return self.model.get_value(self.model.get_iter(self.path),
 
171
                                        treemodel.PARENTS)
158
172
        else:
159
173
            raise AttributeError, 'unknown property %s' % property.name
160
174
 
180
194
        """Return revision id of currently selected revision, or None."""
181
195
        return self.get_property('revision')
182
196
 
 
197
    def has_revision_id(self, revision_id):
 
198
        return (revision_id in self.index)
 
199
 
183
200
    def set_revision(self, revision):
184
201
        self.set_property('revision', revision)
185
202
 
223
240
        self.emit('tag-added', tag, revid)
224
241
        
225
242
    def refresh(self):
226
 
        self.loading_msg_box.show()
227
243
        gobject.idle_add(self.populate, self.get_revision())
228
244
 
229
245
    def update(self):
277
293
                       should be broken.
278
294
        """
279
295
 
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
 
296
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
297
            # We'are using our own ui, let's tell it to use our widget.
 
298
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
 
299
        self.progress_bar = ui.ui_factory.nested_progress_bar()
 
300
        self.progress_bar.update("Loading ancestry graph", 0, 5)
 
301
 
 
302
        try:
 
303
            if self.compact:
 
304
                broken_line_length = 32
 
305
            else:
 
306
                broken_line_length = None
 
307
            
 
308
            show_graph = self.graph_column.get_visible()
 
309
 
 
310
            self.branch.lock_read()
 
311
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
 
312
                                                            self.start,
 
313
                                                            self.maxnum, 
 
314
                                                            broken_line_length,
 
315
                                                            show_graph,
 
316
                                                            self.mainline_only,
 
317
                                                            self.progress_bar)
 
318
 
 
319
            self.model = TreeModel(self.branch, linegraphdata)
 
320
            self.graph_cell.columns_len = columns_len
 
321
            width = self.graph_cell.get_size(self.treeview)[2]
 
322
            if width > 500:
 
323
                width = 500
 
324
            self.graph_column.set_fixed_width(width)
 
325
            self.graph_column.set_max_width(width)
 
326
            self.index = index
 
327
            self.treeview.set_model(self.model)
 
328
 
 
329
            if not revision or revision == NULL_REVISION:
 
330
                self.treeview.set_cursor(0)
 
331
            else:
 
332
                self.set_revision(revision)
 
333
 
 
334
            self.emit('refreshed')
 
335
            return False
 
336
        finally:
 
337
            self.progress_bar.finished()
313
338
 
314
339
    def construct_treeview(self):
315
340
        self.treeview = gtk.TreeView()
322
347
        if set_tooltip is not None:
323
348
            set_tooltip(treemodel.MESSAGE)
324
349
 
 
350
        self._prev_cursor_path = None
325
351
        self.treeview.connect("cursor-changed",
326
352
                self._on_selection_changed)
327
353
 
394
420
        
395
421
        return self.treeview
396
422
    
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
423
    def _on_selection_changed(self, treeview):
417
424
        """callback for when the treeview changes."""
418
425
        (path, focus) = treeview.get_cursor()
419
 
        if path is not None:
420
 
            self.iter = self.model.get_iter(path)
 
426
        if (path is not None) and (path != self._prev_cursor_path):
 
427
            self._prev_cursor_path = path # avoid emitting twice per click
 
428
            self.path = path
421
429
            self.emit('revision-selected')
422
430
 
423
431
    def _on_revision_selected(self, widget, event):
424
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
432
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
425
433
        if event.button == 3:
426
 
            menu = RevisionPopupMenu(self.branch.repository, 
 
434
            menu = RevisionMenu(self.branch.repository, 
427
435
                [self.get_revision().revision_id],
428
436
                self.branch)
429
437
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))