/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: Daniel Schierbeck
  • Date: 2008-04-07 20:34:51 UTC
  • mfrom: (450.6.13 bugs)
  • mto: (463.2.1 bug.78765)
  • mto: This revision was merged to the branch mainline in revision 462.
  • Revision ID: daniel.schierbeck@gmail.com-20080407203451-2i6el7jf9t0k9y64
Merged bug page improvements.

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
import sys
 
10
import string
9
11
import gtk
10
12
import gobject
11
13
import pango
 
14
import re
 
15
import treemodel
12
16
 
13
 
from bzrlib import ui
 
17
from linegraph import linegraph, same_branch
 
18
from graphcell import CellRendererGraph
 
19
from treemodel import TreeModel
14
20
from bzrlib.revision import NULL_REVISION
15
21
 
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
22
class TreeView(gtk.VBox):
24
23
 
25
24
    __gproperties__ = {
82
81
    }
83
82
 
84
83
    __gsignals__ = {
 
84
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
 
85
                             gobject.TYPE_NONE,
 
86
                             ()),
85
87
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
86
88
                              gobject.TYPE_NONE,
87
89
                              ()),
90
92
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
91
93
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
92
94
                              gobject.TYPE_NONE,
93
 
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
94
 
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
95
 
                              ())
 
95
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
96
96
    }
97
97
 
98
98
    def __init__(self, branch, start, maxnum, compact=True):
107
107
        """
108
108
        gtk.VBox.__init__(self, spacing=0)
109
109
 
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)
 
110
        self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
 
111
        self.connect('revisions-loaded', 
 
112
                lambda x: self.loading_msg_box.hide())
115
113
 
116
114
        self.scrolled_window = gtk.ScrolledWindow()
117
115
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
121
119
        self.pack_start(self.scrolled_window, expand=True, fill=True)
122
120
 
123
121
        self.scrolled_window.add(self.construct_treeview())
 
122
        
124
123
 
125
 
        self.path = None
 
124
        self.iter = None
126
125
        self.branch = branch
127
126
        self.revision = None
128
 
        self.index = {}
129
127
 
130
128
        self.start = start
131
129
        self.maxnum = maxnum
132
130
        self.compact = compact
133
131
 
134
 
        self.model = treemodel.TreeModel(self.branch, [])
135
132
        gobject.idle_add(self.populate)
136
133
 
137
 
        self.connect("destroy", self._on_destroy)
138
 
 
139
 
    def _on_destroy(self, *ignored):
140
 
        self.branch.unlock()
141
 
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
142
 
            # We'are using our own ui, let's tell it to stop using our widget.
143
 
            ui.ui_factory.set_progress_bar_widget(None)
 
134
        self.connect("destroy", lambda x: self.branch.unlock())
144
135
 
145
136
    def do_get_property(self, property):
146
137
        if property.name == 'revno-column-visible':
156
147
        elif property.name == 'branch':
157
148
            return self.branch
158
149
        elif property.name == 'revision':
159
 
            if self.path is None:
160
 
                return None
161
 
            return self.model.get_value(self.model.get_iter(self.path),
162
 
                                        treemodel.REVISION)
 
150
            return self.model.get_value(self.iter, treemodel.REVISION)
163
151
        elif property.name == 'revision-number':
164
 
            if self.path is None:
165
 
                return None
166
 
            return self.model.get_value(self.model.get_iter(self.path),
167
 
                                        treemodel.REVNO)
 
152
            return self.model.get_value(self.iter, treemodel.REVNO)
168
153
        elif property.name == 'children':
169
 
            if self.path is None:
170
 
                return None
171
 
            return self.model.get_value(self.model.get_iter(self.path),
172
 
                                        treemodel.CHILDREN)
 
154
            return self.model.get_value(self.iter, treemodel.CHILDREN)
173
155
        elif property.name == 'parents':
174
 
            if self.path is None:
175
 
                return None
176
 
            return self.model.get_value(self.model.get_iter(self.path),
177
 
                                        treemodel.PARENTS)
 
156
            return self.model.get_value(self.iter, treemodel.PARENTS)
178
157
        else:
179
158
            raise AttributeError, 'unknown property %s' % property.name
180
159
 
200
179
        """Return revision id of currently selected revision, or None."""
201
180
        return self.get_property('revision')
202
181
 
203
 
    def has_revision_id(self, revision_id):
204
 
        return (revision_id in self.index)
205
 
 
206
182
    def set_revision(self, revision):
207
183
        self.set_property('revision', revision)
208
184
 
231
207
    def add_tag(self, tag, revid=None):
232
208
        if revid is None: revid = self.revision.revision_id
233
209
 
234
 
        if lock.release(self.branch):
 
210
        try:
 
211
            self.branch.unlock()
 
212
 
235
213
            try:
236
 
                lock.acquire(self.branch, lock.WRITE)
 
214
                self.branch.lock_write()
237
215
                self.model.add_tag(tag, revid)
238
216
            finally:
239
 
                lock.release(self.branch)
240
 
 
241
 
            lock.acquire(self.branch, lock.READ)
242
 
 
243
 
            self.emit('tag-added', tag, revid)
244
 
 
 
217
                self.branch.unlock()
 
218
 
 
219
        finally:
 
220
            self.branch.lock_read()
 
221
 
 
222
        self.emit('tag-added', tag, revid)
 
223
        
245
224
    def refresh(self):
 
225
        self.loading_msg_box.show()
246
226
        gobject.idle_add(self.populate, self.get_revision())
247
227
 
248
228
    def update(self):
296
276
                       should be broken.
297
277
        """
298
278
 
299
 
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
300
 
            # We'are using our own ui, let's tell it to use our widget.
301
 
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
302
 
        self.progress_bar = ui.ui_factory.nested_progress_bar()
303
 
        self.progress_bar.update("Loading ancestry graph", 0, 5)
304
 
 
305
 
        try:
306
 
            if self.compact:
307
 
                broken_line_length = 32
308
 
            else:
309
 
                broken_line_length = None
310
 
 
311
 
            show_graph = self.graph_column.get_visible()
312
 
 
313
 
            self.branch.lock_read()
314
 
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
315
 
                                                            self.start,
316
 
                                                            self.maxnum, 
317
 
                                                            broken_line_length,
318
 
                                                            show_graph,
319
 
                                                            self.mainline_only,
320
 
                                                            self.progress_bar)
321
 
 
322
 
            self.model.line_graph_data = linegraphdata
323
 
            self.graph_cell.columns_len = columns_len
324
 
            width = self.graph_cell.get_size(self.treeview)[2]
325
 
            if width > 500:
326
 
                width = 500
327
 
            self.graph_column.set_fixed_width(width)
328
 
            self.graph_column.set_max_width(width)
329
 
            self.index = index
330
 
            self.treeview.set_model(self.model)
331
 
 
332
 
            if not revision or revision == NULL_REVISION:
333
 
                self.treeview.set_cursor(0)
334
 
            else:
335
 
                self.set_revision(revision)
336
 
 
337
 
            self.emit('refreshed')
338
 
            return False
339
 
        finally:
340
 
            self.progress_bar.finished()
 
279
        if self.compact:
 
280
            broken_line_length = 32
 
281
        else:
 
282
            broken_line_length = None
 
283
        
 
284
        show_graph = self.graph_column.get_visible()
 
285
 
 
286
        self.branch.lock_read()
 
287
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
 
288
                                                        self.start,
 
289
                                                        self.maxnum, 
 
290
                                                        broken_line_length,
 
291
                                                        show_graph,
 
292
                                                        self.mainline_only)
 
293
 
 
294
        self.model = TreeModel(self.branch, linegraphdata)
 
295
        self.graph_cell.columns_len = columns_len
 
296
        width = self.graph_cell.get_size(self.treeview)[2]
 
297
        if width > 500:
 
298
            width = 500
 
299
        self.graph_column.set_fixed_width(width)
 
300
        self.graph_column.set_max_width(width)
 
301
        self.index = index
 
302
        self.treeview.set_model(self.model)
 
303
 
 
304
        if revision is None:
 
305
            self.treeview.set_cursor(0)
 
306
        else:
 
307
            self.set_revision(revision)
 
308
 
 
309
        self.emit('revisions-loaded')
 
310
 
 
311
        return False
341
312
 
342
313
    def construct_treeview(self):
343
314
        self.treeview = gtk.TreeView()
344
315
 
345
316
        self.treeview.set_rules_hint(True)
346
 
        # combined revno/summary interactive search
347
 
        #
348
 
        # the row in a treemodel is considered "matched" if a REVNO *starts*
349
 
        # from the key (that is the key is found in a REVNO at the offset 0)
350
 
        # or if a MESSAGE *contains* the key anywhere (that is, the key is
351
 
        # found case insensitively in a MESSAGE at any offset)
352
 
        def search_equal_func(model, column, key, iter):
353
 
            return (model.get_value(iter, treemodel.REVNO).find(key) != 0
354
 
                and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
355
 
 
356
 
        self.treeview.set_search_equal_func(search_equal_func)
357
 
        self.treeview.set_enable_search(True)
358
 
 
 
317
        self.treeview.set_search_column(treemodel.REVNO)
 
318
        
359
319
        # Fix old PyGTK bug - by JAM
360
320
        set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
361
321
        if set_tooltip is not None:
362
322
            set_tooltip(treemodel.MESSAGE)
363
323
 
364
 
        self._prev_cursor_path = None
365
324
        self.treeview.connect("cursor-changed",
366
325
                self._on_selection_changed)
367
326
 
390
349
        self.graph_column = gtk.TreeViewColumn()
391
350
        self.graph_column.set_resizable(True)
392
351
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
393
 
        self.graph_column.pack_start(self.graph_cell, expand=True)
 
352
        self.graph_column.pack_start(self.graph_cell, expand=False)
394
353
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
395
354
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
396
355
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
402
361
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
403
362
        self.summary_column = gtk.TreeViewColumn("Summary")
404
363
        self.summary_column.set_resizable(True)
405
 
        self.summary_column.set_expand(True)
406
364
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
407
365
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
408
366
        self.summary_column.pack_start(cell, expand=True)
412
370
        cell = gtk.CellRendererText()
413
371
        cell.set_property("width-chars", 15)
414
372
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
415
 
        self.authors_column = gtk.TreeViewColumn("Author(s)")
416
 
        self.authors_column.set_resizable(False)
417
 
        self.authors_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
418
 
        self.authors_column.set_fixed_width(200)
419
 
        self.authors_column.pack_start(cell, expand=True)
420
 
        self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
421
 
        self.treeview.append_column(self.authors_column)
 
373
        self.committer_column = gtk.TreeViewColumn("Committer")
 
374
        self.committer_column.set_resizable(True)
 
375
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
376
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
377
        self.committer_column.pack_start(cell, expand=True)
 
378
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
 
379
        self.treeview.append_column(self.committer_column)
422
380
 
423
381
        cell = gtk.CellRendererText()
424
382
        cell.set_property("width-chars", 20)
427
385
        self.date_column.set_visible(False)
428
386
        self.date_column.set_resizable(True)
429
387
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
430
 
        self.date_column.set_fixed_width(130)
 
388
        self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])
431
389
        self.date_column.pack_start(cell, expand=True)
432
390
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
433
391
        self.treeview.append_column(self.date_column)
434
 
 
 
392
        
435
393
        return self.treeview
 
394
    
 
395
    def construct_loading_msg(self):
 
396
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
397
                                                 gtk.ICON_SIZE_BUTTON)
 
398
        image_loading.show()
 
399
        
 
400
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
 
401
        label_loading.set_alignment(0.0, 0.5)
 
402
        label_loading.show()
 
403
        
 
404
        self.loading_msg_box = gtk.HBox()
 
405
        self.loading_msg_box.set_spacing(5)
 
406
        self.loading_msg_box.set_border_width(5)        
 
407
        self.loading_msg_box.pack_start(image_loading, False, False)
 
408
        self.loading_msg_box.pack_start(label_loading, True, True)
 
409
        self.loading_msg_box.show()
 
410
        
 
411
        return self.loading_msg_box
436
412
 
437
413
    def _on_selection_changed(self, treeview):
438
414
        """callback for when the treeview changes."""
439
415
        (path, focus) = treeview.get_cursor()
440
 
        if (path is not None) and (path != self._prev_cursor_path):
441
 
            self._prev_cursor_path = path # avoid emitting twice per click
442
 
            self.path = path
 
416
        if path is not None:
 
417
            self.iter = self.model.get_iter(path)
443
418
            self.emit('revision-selected')
444
419
 
445
420
    def _on_revision_selected(self, widget, event):
446
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
 
421
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
447
422
        if event.button == 3:
448
 
            menu = RevisionMenu(self.branch.repository, 
 
423
            menu = RevisionPopupMenu(self.branch.repository, 
449
424
                [self.get_revision().revision_id],
450
425
                self.branch)
451
426
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))