/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-29 18:12:29 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629181229-1l2m4cf7vvbyh8qg
Simplify progress bar code, use embedded progress bar inside viz window.

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
16
17
 
 
18
from bzrlib.plugins.gtk import _i18n
 
19
from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
17
20
from linegraph import linegraph, same_branch
18
21
from graphcell import CellRendererGraph
19
22
from treemodel import TreeModel
20
23
from bzrlib.revision import NULL_REVISION
21
24
 
 
25
 
22
26
class TreeView(gtk.VBox):
23
27
 
24
28
    __gproperties__ = {
81
85
    }
82
86
 
83
87
    __gsignals__ = {
84
 
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
85
 
                             gobject.TYPE_NONE,
86
 
                             ()),
87
88
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
88
89
                              gobject.TYPE_NONE,
89
90
                              ()),
107
108
        """
108
109
        gtk.VBox.__init__(self, spacing=0)
109
110
 
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())
 
111
        loading_msg_widget = ProgressPanel()
 
112
        ui.ui_factory.set_nested_progress_bar_widget(loading_msg_widget.get_progress_bar)
 
113
        self.pack_start(loading_msg_widget, expand=False, fill=True)
113
114
 
114
115
        self.scrolled_window = gtk.ScrolledWindow()
115
116
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
119
120
        self.pack_start(self.scrolled_window, expand=True, fill=True)
120
121
 
121
122
        self.scrolled_window.add(self.construct_treeview())
122
 
        
123
123
 
124
124
        self.iter = None
125
125
        self.branch = branch
222
222
        self.emit('tag-added', tag, revid)
223
223
        
224
224
    def refresh(self):
225
 
        self.loading_msg_box.show()
226
225
        gobject.idle_add(self.populate, self.get_revision())
227
226
 
228
227
    def update(self):
276
275
                       should be broken.
277
276
        """
278
277
 
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
 
278
        self.progress_bar = ui.ui_factory.nested_progress_bar()
 
279
        self.progress_bar.update(msg="Loading ancestry graph", total_cnt=5)
 
280
 
 
281
        try:
 
282
            if self.compact:
 
283
                broken_line_length = 32
 
284
            else:
 
285
                broken_line_length = None
 
286
            
 
287
            show_graph = self.graph_column.get_visible()
 
288
 
 
289
            self.branch.lock_read()
 
290
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
 
291
                                                            self.start,
 
292
                                                            self.maxnum, 
 
293
                                                            broken_line_length,
 
294
                                                            show_graph,
 
295
                                                            self.mainline_only,
 
296
                                                            self.progress_bar)
 
297
 
 
298
            self.model = TreeModel(self.branch, linegraphdata)
 
299
            self.graph_cell.columns_len = columns_len
 
300
            width = self.graph_cell.get_size(self.treeview)[2]
 
301
            if width > 500:
 
302
                width = 500
 
303
            self.graph_column.set_fixed_width(width)
 
304
            self.graph_column.set_max_width(width)
 
305
            self.index = index
 
306
            self.treeview.set_model(self.model)
 
307
 
 
308
            if not revision or revision == NULL_REVISION:
 
309
                self.treeview.set_cursor(0)
 
310
            else:
 
311
                self.set_revision(revision)
 
312
 
 
313
            return False
 
314
        finally:
 
315
            self.progress_bar.finished()
312
316
 
313
317
    def construct_treeview(self):
314
318
        self.treeview = gtk.TreeView()
338
342
        cell.set_property("width-chars", 15)
339
343
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
340
344
        self.revno_column = gtk.TreeViewColumn("Revision No")
341
 
        self.revno_column.set_resizable(True)
 
345
        self.revno_column.set_resizable(False)
342
346
        self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
343
347
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
344
348
        self.revno_column.pack_start(cell, expand=True)
347
351
 
348
352
        self.graph_cell = CellRendererGraph()
349
353
        self.graph_column = gtk.TreeViewColumn()
350
 
        self.graph_column.set_resizable(True)
 
354
        self.graph_column.set_resizable(False)
351
355
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
352
 
        self.graph_column.pack_start(self.graph_cell, expand=False)
 
356
        self.graph_column.pack_start(self.graph_cell, expand=True)
353
357
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
354
358
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
355
359
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
360
364
        cell.set_property("width-chars", 65)
361
365
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
362
366
        self.summary_column = gtk.TreeViewColumn("Summary")
363
 
        self.summary_column.set_resizable(True)
 
367
        self.summary_column.set_resizable(False)
 
368
        self.summary_column.set_expand(True)
364
369
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
365
370
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
366
371
        self.summary_column.pack_start(cell, expand=True)
371
376
        cell.set_property("width-chars", 15)
372
377
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
373
378
        self.committer_column = gtk.TreeViewColumn("Committer")
374
 
        self.committer_column.set_resizable(True)
 
379
        self.committer_column.set_resizable(False)
375
380
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
376
 
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
381
        self.committer_column.set_fixed_width(200)
377
382
        self.committer_column.pack_start(cell, expand=True)
378
383
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
379
384
        self.treeview.append_column(self.committer_column)
383
388
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
384
389
        self.date_column = gtk.TreeViewColumn("Date")
385
390
        self.date_column.set_visible(False)
386
 
        self.date_column.set_resizable(True)
 
391
        self.date_column.set_resizable(False)
387
392
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
388
 
        self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
393
        self.date_column.set_fixed_width(130)
389
394
        self.date_column.pack_start(cell, expand=True)
390
395
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
391
396
        self.treeview.append_column(self.date_column)
392
397
        
393
398
        return self.treeview
394
399
    
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
412
 
 
413
400
    def _on_selection_changed(self, treeview):
414
401
        """callback for when the treeview changes."""
415
402
        (path, focus) = treeview.get_cursor()