/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: 2011-03-14 20:12:19 UTC
  • Revision ID: jelmer@samba.org-20110314201219-wo692nzwywu6mevh
Fix formatting, imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
7
7
__author__    = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
8
8
 
9
 
import sys
10
 
import string
11
9
import gtk
12
10
import gobject
13
11
import pango
14
 
import re
15
 
import treemodel
16
12
 
17
 
from bzrlib.plugins.gtk import _i18n
18
 
from linegraph import linegraph, same_branch
19
 
from graphcell import CellRendererGraph
20
 
from treemodel import TreeModel
 
13
from bzrlib import ui
21
14
from bzrlib.revision import NULL_REVISION
22
15
 
 
16
from bzrlib.plugins.gtk import lock
 
17
from bzrlib.plugins.gtk.ui import ProgressPanel
 
18
from bzrlib.plugins.gtk.branchview import treemodel
 
19
from bzrlib.plugins.gtk.branchview.linegraph import linegraph, same_branch
 
20
from bzrlib.plugins.gtk.branchview.graphcell import CellRendererGraph
 
21
 
 
22
 
23
23
class TreeView(gtk.VBox):
24
24
 
25
25
    __gproperties__ = {
82
82
    }
83
83
 
84
84
    __gsignals__ = {
85
 
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
86
 
                             gobject.TYPE_NONE,
87
 
                             ()),
88
85
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
89
86
                              gobject.TYPE_NONE,
90
87
                              ()),
93
90
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
94
91
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
95
92
                              gobject.TYPE_NONE,
96
 
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
 
93
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
 
94
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
 
95
                              ())
97
96
    }
98
97
 
99
98
    def __init__(self, branch, start, maxnum, compact=True):
108
107
        """
109
108
        gtk.VBox.__init__(self, spacing=0)
110
109
 
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())
 
110
        self.progress_widget = ProgressPanel()
 
111
        self.pack_start(self.progress_widget, expand=False, fill=True)
 
112
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
113
            # We'are using our own ui, let's tell it to use our widget.
 
114
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
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
132
133
 
133
134
        gobject.idle_add(self.populate)
134
135
 
135
 
        self.connect("destroy", lambda x: self.branch.unlock())
 
136
        self.connect("destroy", self._on_destroy)
 
137
 
 
138
    def _on_destroy(self, *ignored):
 
139
        self.branch.unlock()
 
140
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
141
            # We'are using our own ui, let's tell it to stop using our widget.
 
142
            ui.ui_factory.set_progress_bar_widget(None)
136
143
 
137
144
    def do_get_property(self, property):
138
145
        if property.name == 'revno-column-visible':
148
155
        elif property.name == 'branch':
149
156
            return self.branch
150
157
        elif property.name == 'revision':
151
 
            return self.model.get_value(self.iter, treemodel.REVISION)
 
158
            return self.model.get_value(self.model.get_iter(self.path),
 
159
                                        treemodel.REVISION)
152
160
        elif property.name == 'revision-number':
153
 
            return self.model.get_value(self.iter, treemodel.REVNO)
 
161
            return self.model.get_value(self.model.get_iter(self.path),
 
162
                                        treemodel.REVNO)
154
163
        elif property.name == 'children':
155
 
            return self.model.get_value(self.iter, treemodel.CHILDREN)
 
164
            return self.model.get_value(self.model.get_iter(self.path),
 
165
                                        treemodel.CHILDREN)
156
166
        elif property.name == 'parents':
157
 
            return self.model.get_value(self.iter, treemodel.PARENTS)
 
167
            return self.model.get_value(self.model.get_iter(self.path),
 
168
                                        treemodel.PARENTS)
158
169
        else:
159
170
            raise AttributeError, 'unknown property %s' % property.name
160
171
 
180
191
        """Return revision id of currently selected revision, or None."""
181
192
        return self.get_property('revision')
182
193
 
 
194
    def has_revision_id(self, revision_id):
 
195
        return (revision_id in self.index)
 
196
 
183
197
    def set_revision(self, revision):
184
198
        self.set_property('revision', revision)
185
199
 
208
222
    def add_tag(self, tag, revid=None):
209
223
        if revid is None: revid = self.revision.revision_id
210
224
 
211
 
        try:
212
 
            self.branch.unlock()
213
 
 
 
225
        if lock.release(self.branch):
214
226
            try:
215
 
                self.branch.lock_write()
 
227
                lock.acquire(self.branch, lock.WRITE)
216
228
                self.model.add_tag(tag, revid)
217
229
            finally:
218
 
                self.branch.unlock()
219
 
 
220
 
        finally:
221
 
            self.branch.lock_read()
222
 
 
223
 
        self.emit('tag-added', tag, revid)
224
 
        
 
230
                lock.release(self.branch)
 
231
 
 
232
            lock.acquire(self.branch, lock.READ)
 
233
 
 
234
            self.emit('tag-added', tag, revid)
 
235
 
225
236
    def refresh(self):
226
 
        self.loading_msg_box.show()
227
237
        gobject.idle_add(self.populate, self.get_revision())
228
238
 
229
239
    def update(self):
277
287
                       should be broken.
278
288
        """
279
289
 
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
 
290
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
291
            # We'are using our own ui, let's tell it to use our widget.
 
292
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
 
293
        self.progress_bar = ui.ui_factory.nested_progress_bar()
 
294
        self.progress_bar.update("Loading ancestry graph", 0, 5)
 
295
 
 
296
        try:
 
297
            if self.compact:
 
298
                broken_line_length = 32
 
299
            else:
 
300
                broken_line_length = None
 
301
 
 
302
            show_graph = self.graph_column.get_visible()
 
303
 
 
304
            self.branch.lock_read()
 
305
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
 
306
                                                            self.start,
 
307
                                                            self.maxnum, 
 
308
                                                            broken_line_length,
 
309
                                                            show_graph,
 
310
                                                            self.mainline_only,
 
311
                                                            self.progress_bar)
 
312
 
 
313
            self.model = treemodel.TreeModel(self.branch, linegraphdata)
 
314
            self.graph_cell.columns_len = columns_len
 
315
            width = self.graph_cell.get_size(self.treeview)[2]
 
316
            if width > 500:
 
317
                width = 500
 
318
            self.graph_column.set_fixed_width(width)
 
319
            self.graph_column.set_max_width(width)
 
320
            self.index = index
 
321
            self.treeview.set_model(self.model)
 
322
 
 
323
            if not revision or revision == NULL_REVISION:
 
324
                self.treeview.set_cursor(0)
 
325
            else:
 
326
                self.set_revision(revision)
 
327
 
 
328
            self.emit('refreshed')
 
329
            return False
 
330
        finally:
 
331
            self.progress_bar.finished()
313
332
 
314
333
    def construct_treeview(self):
315
334
        self.treeview = gtk.TreeView()
316
335
 
317
336
        self.treeview.set_rules_hint(True)
318
337
        self.treeview.set_search_column(treemodel.REVNO)
319
 
        
 
338
 
320
339
        # Fix old PyGTK bug - by JAM
321
340
        set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
322
341
        if set_tooltip is not None:
323
342
            set_tooltip(treemodel.MESSAGE)
324
343
 
 
344
        self._prev_cursor_path = None
325
345
        self.treeview.connect("cursor-changed",
326
346
                self._on_selection_changed)
327
347
 
372
392
        cell = gtk.CellRendererText()
373
393
        cell.set_property("width-chars", 15)
374
394
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
375
 
        self.committer_column = gtk.TreeViewColumn("Committer")
376
 
        self.committer_column.set_resizable(False)
377
 
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
378
 
        self.committer_column.set_fixed_width(200)
379
 
        self.committer_column.pack_start(cell, expand=True)
380
 
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
381
 
        self.treeview.append_column(self.committer_column)
 
395
        self.authors_column = gtk.TreeViewColumn("Author(s)")
 
396
        self.authors_column.set_resizable(False)
 
397
        self.authors_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
398
        self.authors_column.set_fixed_width(200)
 
399
        self.authors_column.pack_start(cell, expand=True)
 
400
        self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
 
401
        self.treeview.append_column(self.authors_column)
382
402
 
383
403
        cell = gtk.CellRendererText()
384
404
        cell.set_property("width-chars", 20)
391
411
        self.date_column.pack_start(cell, expand=True)
392
412
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
393
413
        self.treeview.append_column(self.date_column)
394
 
        
 
414
 
395
415
        return self.treeview
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
416
 
416
417
    def _on_selection_changed(self, treeview):
417
418
        """callback for when the treeview changes."""
418
419
        (path, focus) = treeview.get_cursor()
419
 
        if path is not None:
420
 
            self.iter = self.model.get_iter(path)
 
420
        if (path is not None) and (path != self._prev_cursor_path):
 
421
            self._prev_cursor_path = path # avoid emitting twice per click
 
422
            self.path = path
421
423
            self.emit('revision-selected')
422
424
 
423
425
    def _on_revision_selected(self, widget, event):
424
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
426
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
425
427
        if event.button == 3:
426
 
            menu = RevisionPopupMenu(self.branch.repository, 
 
428
            menu = RevisionMenu(self.branch.repository, 
427
429
                [self.get_revision().revision_id],
428
430
                self.branch)
429
431
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))