/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 viz/treeview.py

  • Committer: Daniel Schierbeck
  • Date: 2007-11-21 23:49:58 UTC
  • Revision ID: daniel.schierbeck@gmail.com-20071121234958-pvxq0dk51dscqzep
Made the push dialog close when the cancel button is clicked.

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