/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-27 16:55:09 UTC
  • mto: This revision was merged to the branch mainline in revision 506.
  • Revision ID: jelmer@samba.org-20080627165509-7b68w2chzvvgc8vz
Use helper script to open patches.

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
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
 
        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)
 
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())
118
114
 
119
115
        self.scrolled_window = gtk.ScrolledWindow()
120
116
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
124
120
        self.pack_start(self.scrolled_window, expand=True, fill=True)
125
121
 
126
122
        self.scrolled_window.add(self.construct_treeview())
 
123
        
127
124
 
128
 
        self.path = None
 
125
        self.iter = None
129
126
        self.branch = branch
130
127
        self.revision = None
131
 
        self.index = {}
132
128
 
133
129
        self.start = start
134
130
        self.maxnum = maxnum
136
132
 
137
133
        gobject.idle_add(self.populate)
138
134
 
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)
 
135
        self.connect("destroy", lambda x: self.branch.unlock())
146
136
 
147
137
    def do_get_property(self, property):
148
138
        if property.name == 'revno-column-visible':
158
148
        elif property.name == 'branch':
159
149
            return self.branch
160
150
        elif property.name == 'revision':
161
 
            return self.model.get_value(self.model.get_iter(self.path),
162
 
                                        treemodel.REVISION)
 
151
            return self.model.get_value(self.iter, treemodel.REVISION)
163
152
        elif property.name == 'revision-number':
164
 
            return self.model.get_value(self.model.get_iter(self.path),
165
 
                                        treemodel.REVNO)
 
153
            return self.model.get_value(self.iter, treemodel.REVNO)
166
154
        elif property.name == 'children':
167
 
            return self.model.get_value(self.model.get_iter(self.path),
168
 
                                        treemodel.CHILDREN)
 
155
            return self.model.get_value(self.iter, treemodel.CHILDREN)
169
156
        elif property.name == 'parents':
170
 
            return self.model.get_value(self.model.get_iter(self.path),
171
 
                                        treemodel.PARENTS)
 
157
            return self.model.get_value(self.iter, treemodel.PARENTS)
172
158
        else:
173
159
            raise AttributeError, 'unknown property %s' % property.name
174
160
 
194
180
        """Return revision id of currently selected revision, or None."""
195
181
        return self.get_property('revision')
196
182
 
197
 
    def has_revision_id(self, revision_id):
198
 
        return (revision_id in self.index)
199
 
 
200
183
    def set_revision(self, revision):
201
184
        self.set_property('revision', revision)
202
185
 
240
223
        self.emit('tag-added', tag, revid)
241
224
        
242
225
    def refresh(self):
 
226
        self.loading_msg_box.show()
243
227
        gobject.idle_add(self.populate, self.get_revision())
244
228
 
245
229
    def update(self):
293
277
                       should be broken.
294
278
        """
295
279
 
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()
 
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,
 
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
338
313
 
339
314
    def construct_treeview(self):
340
315
        self.treeview = gtk.TreeView()
347
322
        if set_tooltip is not None:
348
323
            set_tooltip(treemodel.MESSAGE)
349
324
 
350
 
        self._prev_cursor_path = None
351
325
        self.treeview.connect("cursor-changed",
352
326
                self._on_selection_changed)
353
327
 
420
394
        
421
395
        return self.treeview
422
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
 
423
416
    def _on_selection_changed(self, treeview):
424
417
        """callback for when the treeview changes."""
425
418
        (path, focus) = treeview.get_cursor()
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
 
419
        if path is not None:
 
420
            self.iter = self.model.get_iter(path)
429
421
            self.emit('revision-selected')
430
422
 
431
423
    def _on_revision_selected(self, widget, event):
432
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
 
424
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
433
425
        if event.button == 3:
434
 
            menu = RevisionMenu(self.branch.repository, 
 
426
            menu = RevisionPopupMenu(self.branch.repository, 
435
427
                [self.get_revision().revision_id],
436
428
                self.branch)
437
429
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))