/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
 
22
 
class TreeView(gtk.ScrolledWindow):
 
25
 
 
26
class TreeView(gtk.VBox):
23
27
 
24
28
    __gproperties__ = {
25
29
        'branch': (gobject.TYPE_PYOBJECT,
49
53
                    gobject.PARAM_READABLE),
50
54
 
51
55
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
52
 
                                 'Revision number',
 
56
                                 'Revision number column',
53
57
                                 'Show revision number column',
54
58
                                 True,
55
59
                                 gobject.PARAM_READWRITE),
56
60
 
 
61
        'graph-column-visible': (gobject.TYPE_BOOLEAN,
 
62
                                 'Graph column',
 
63
                                 'Show graph column',
 
64
                                 True,
 
65
                                 gobject.PARAM_READWRITE),
 
66
 
57
67
        'date-column-visible': (gobject.TYPE_BOOLEAN,
58
68
                                 'Date',
59
69
                                 'Show date column',
60
70
                                 False,
61
 
                                 gobject.PARAM_READWRITE)
 
71
                                 gobject.PARAM_READWRITE),
 
72
 
 
73
        'compact': (gobject.TYPE_BOOLEAN,
 
74
                    'Compact view',
 
75
                    'Break ancestry lines to save space',
 
76
                    True,
 
77
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
 
78
 
 
79
        'mainline-only': (gobject.TYPE_BOOLEAN,
 
80
                    'Mainline only',
 
81
                    'Only show the mainline history.',
 
82
                    False,
 
83
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
62
84
 
63
85
    }
64
86
 
65
87
    __gsignals__ = {
66
 
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
67
 
                             gobject.TYPE_NONE,
68
 
                             ()),
69
88
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
70
89
                              gobject.TYPE_NONE,
71
 
                              ())
 
90
                              ()),
 
91
        'revision-activated': (gobject.SIGNAL_RUN_FIRST,
 
92
                              gobject.TYPE_NONE,
 
93
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
 
94
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
 
95
                              gobject.TYPE_NONE,
 
96
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
72
97
    }
73
98
 
74
 
    def __init__(self, branch, start, maxnum, broken_line_length=None):
 
99
    def __init__(self, branch, start, maxnum, compact=True):
75
100
        """Create a new TreeView.
76
101
 
77
102
        :param branch: Branch object for branch to show.
81
106
        :param broken_line_length: After how much lines to break 
82
107
                                   branches.
83
108
        """
84
 
        gtk.ScrolledWindow.__init__(self)
85
 
 
86
 
        self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
87
 
        self.set_shadow_type(gtk.SHADOW_IN)
88
 
 
89
 
        self.construct_treeview()
90
 
 
91
 
        self.iter   = None
 
109
        gtk.VBox.__init__(self, spacing=0)
 
110
 
 
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)
 
114
 
 
115
        self.scrolled_window = gtk.ScrolledWindow()
 
116
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
 
117
                                        gtk.POLICY_AUTOMATIC)
 
118
        self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
 
119
        self.scrolled_window.show()
 
120
        self.pack_start(self.scrolled_window, expand=True, fill=True)
 
121
 
 
122
        self.scrolled_window.add(self.construct_treeview())
 
123
 
 
124
        self.iter = None
92
125
        self.branch = branch
93
 
 
94
 
        gobject.idle_add(self.populate, start, maxnum, 
95
 
                         broken_line_length)
 
126
        self.revision = None
 
127
 
 
128
        self.start = start
 
129
        self.maxnum = maxnum
 
130
        self.compact = compact
 
131
 
 
132
        gobject.idle_add(self.populate)
96
133
 
97
134
        self.connect("destroy", lambda x: self.branch.unlock())
98
135
 
99
136
    def do_get_property(self, property):
100
137
        if property.name == 'revno-column-visible':
101
138
            return self.revno_column.get_visible()
 
139
        elif property.name == 'graph-column-visible':
 
140
            return self.graph_column.get_visible()
102
141
        elif property.name == 'date-column-visible':
103
142
            return self.date_column.get_visible()
 
143
        elif property.name == 'compact':
 
144
            return self.compact
 
145
        elif property.name == 'mainline-only':
 
146
            return self.mainline_only
104
147
        elif property.name == 'branch':
105
148
            return self.branch
106
149
        elif property.name == 'revision':
117
160
    def do_set_property(self, property, value):
118
161
        if property.name == 'revno-column-visible':
119
162
            self.revno_column.set_visible(value)
 
163
        elif property.name == 'graph-column-visible':
 
164
            self.graph_column.set_visible(value)
120
165
        elif property.name == 'date-column-visible':
121
166
            self.date_column.set_visible(value)
 
167
        elif property.name == 'compact':
 
168
            self.compact = value
 
169
        elif property.name == 'mainline-only':
 
170
            self.mainline_only = value
122
171
        elif property.name == 'branch':
123
172
            self.branch = value
124
173
        elif property.name == 'revision':
154
203
        :return: list of revision ids.
155
204
        """
156
205
        return self.get_property('parents')
 
206
 
 
207
    def add_tag(self, tag, revid=None):
 
208
        if revid is None: revid = self.revision.revision_id
 
209
 
 
210
        try:
 
211
            self.branch.unlock()
 
212
 
 
213
            try:
 
214
                self.branch.lock_write()
 
215
                self.model.add_tag(tag, revid)
 
216
            finally:
 
217
                self.branch.unlock()
 
218
 
 
219
        finally:
 
220
            self.branch.lock_read()
 
221
 
 
222
        self.emit('tag-added', tag, revid)
157
223
        
 
224
    def refresh(self):
 
225
        gobject.idle_add(self.populate, self.get_revision())
 
226
 
 
227
    def update(self):
 
228
        try:
 
229
            self.branch.unlock()
 
230
            try:
 
231
                self.branch.lock_write()
 
232
                self.branch.update()
 
233
            finally:
 
234
                self.branch.unlock()
 
235
        finally:
 
236
            self.branch.lock_read()
 
237
 
158
238
    def back(self):
159
239
        """Signal handler for the Back button."""
160
240
        parents = self.get_parents()
185
265
        else:
186
266
            self.set_revision_id(children[0])
187
267
 
188
 
    def populate(self, start, maxnum, broken_line_length=None):
 
268
    def populate(self, revision=None):
189
269
        """Fill the treeview with contents.
190
270
 
191
271
        :param start: Revision id of revision to start with.
194
274
        :param broken_line_length: After how much lines branches \
195
275
                       should be broken.
196
276
        """
197
 
        self.branch.lock_read()
198
 
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
199
 
                                                        start,
200
 
                                                        maxnum, 
201
 
                                                        broken_line_length)
202
 
 
203
 
        self.model = TreeModel(self.branch.repository, linegraphdata)
204
 
        self.graph_cell.columns_len = columns_len
205
 
        width = self.graph_cell.get_size(self.treeview)[2]
206
 
        self.graph_column.set_fixed_width(width)
207
 
        self.graph_column.set_max_width(width)
208
 
        self.index = index
209
 
        self.treeview.set_model(self.model)
210
 
        self.treeview.set_cursor(0)
211
 
        self.emit('revisions-loaded')
212
 
 
213
 
        return False
214
 
 
215
 
    def show_diff(self, revid=None, parentid=None):
216
 
        """Open a new window to show a diff between the given revisions."""
217
 
        from bzrlib.plugins.gtk.diff import DiffWindow
218
 
        window = DiffWindow(parent=self)
219
 
 
220
 
        parents = self.get_parents()
221
 
 
222
 
        if revid is None:
223
 
            revid = self.get_revision().revision_id
224
 
 
225
 
            if parentid is None and len(parents) > 0:
226
 
                parentid = parents[0]
227
 
 
228
 
        if parentid is None:
229
 
            parentid = NULL_REVISION
230
 
 
231
 
        rev_tree    = self.branch.repository.revision_tree(revid)
232
 
        parent_tree = self.branch.repository.revision_tree(parentid)
233
 
 
234
 
        description = revid + " - " + self.branch.nick
235
 
        window.set_diff(description, rev_tree, parent_tree)
236
 
        window.show()
 
277
 
 
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()
237
316
 
238
317
    def construct_treeview(self):
239
318
        self.treeview = gtk.TreeView()
257
336
 
258
337
        self.treeview.set_property('fixed-height-mode', True)
259
338
 
260
 
        self.add(self.treeview)
261
339
        self.treeview.show()
262
340
 
263
341
        cell = gtk.CellRendererText()
264
342
        cell.set_property("width-chars", 15)
265
343
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
266
344
        self.revno_column = gtk.TreeViewColumn("Revision No")
267
 
        self.revno_column.set_resizable(True)
 
345
        self.revno_column.set_resizable(False)
268
346
        self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
269
347
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
270
348
        self.revno_column.pack_start(cell, expand=True)
273
351
 
274
352
        self.graph_cell = CellRendererGraph()
275
353
        self.graph_column = gtk.TreeViewColumn()
276
 
        self.graph_column.set_resizable(True)
 
354
        self.graph_column.set_resizable(False)
277
355
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
278
 
        self.graph_column.pack_start(self.graph_cell, expand=False)
 
356
        self.graph_column.pack_start(self.graph_cell, expand=True)
279
357
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
 
358
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
280
359
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
281
360
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
282
361
        self.treeview.append_column(self.graph_column)
284
363
        cell = gtk.CellRendererText()
285
364
        cell.set_property("width-chars", 65)
286
365
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
287
 
        self.msg_column = gtk.TreeViewColumn("Message")
288
 
        self.msg_column.set_resizable(True)
289
 
        self.msg_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
290
 
        self.msg_column.set_fixed_width(cell.get_size(self.treeview)[2])
291
 
        self.msg_column.pack_start(cell, expand=True)
292
 
        self.msg_column.add_attribute(cell, "text", treemodel.MESSAGE)
293
 
        self.treeview.append_column(self.msg_column)
 
366
        self.summary_column = gtk.TreeViewColumn("Summary")
 
367
        self.summary_column.set_resizable(False)
 
368
        self.summary_column.set_expand(True)
 
369
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
370
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
371
        self.summary_column.pack_start(cell, expand=True)
 
372
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
 
373
        self.treeview.append_column(self.summary_column)
294
374
 
295
375
        cell = gtk.CellRendererText()
296
376
        cell.set_property("width-chars", 15)
297
377
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
298
378
        self.committer_column = gtk.TreeViewColumn("Committer")
299
 
        self.committer_column.set_resizable(True)
 
379
        self.committer_column.set_resizable(False)
300
380
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
301
 
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
381
        self.committer_column.set_fixed_width(200)
302
382
        self.committer_column.pack_start(cell, expand=True)
303
 
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITER)
 
383
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
304
384
        self.treeview.append_column(self.committer_column)
305
385
 
306
386
        cell = gtk.CellRendererText()
308
388
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
309
389
        self.date_column = gtk.TreeViewColumn("Date")
310
390
        self.date_column.set_visible(False)
311
 
        self.date_column.set_resizable(True)
 
391
        self.date_column.set_resizable(False)
312
392
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
313
 
        self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
393
        self.date_column.set_fixed_width(130)
314
394
        self.date_column.pack_start(cell, expand=True)
315
395
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
316
396
        self.treeview.append_column(self.date_column)
317
 
 
 
397
        
 
398
        return self.treeview
 
399
    
318
400
    def _on_selection_changed(self, treeview):
319
401
        """callback for when the treeview changes."""
320
402
        (path, focus) = treeview.get_cursor()
328
410
            menu = RevisionPopupMenu(self.branch.repository, 
329
411
                [self.get_revision().revision_id],
330
412
                self.branch)
 
413
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
331
414
            menu.popup(None, None, None, event.button, event.get_time())
332
415
 
333
416
    def _on_revision_activated(self, widget, path, col):
334
 
        # TODO: more than one parent
335
 
        """Callback for when a treeview row gets activated."""
336
 
        revision_id = self.model[path][treemodel.REVID]
337
 
        parents = self.model[path][treemodel.PARENTS]
338
 
 
339
 
        if len(parents) == 0:
340
 
            parent_id = None
341
 
        else:
342
 
            parent_id = parents[0]
343
 
 
344
 
        self.show_diff(revision_id, parent_id)
345
 
        self.treeview.grab_focus()
 
417
        self.emit('revision-activated', path, col)