/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: Adrian Wilkins
  • Date: 2008-04-24 15:26:14 UTC
  • mto: This revision was merged to the branch mainline in revision 470.
  • Revision ID: adrian.wilkins@gmail.com-20080424152614-2rnnljbro6vzqvf7
Detect the reserved null: revision in appropriate places. 

This removes a huge shower of stack traces that get dumped to console when 
you look at the bottom of a log.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from treemodel import TreeModel
20
20
from bzrlib.revision import NULL_REVISION
21
21
 
22
 
class TreeView(gtk.ScrolledWindow):
 
22
class TreeView(gtk.VBox):
23
23
 
24
24
    __gproperties__ = {
25
25
        'branch': (gobject.TYPE_PYOBJECT,
49
49
                    gobject.PARAM_READABLE),
50
50
 
51
51
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
52
 
                                 'Revision number',
 
52
                                 'Revision number column',
53
53
                                 'Show revision number column',
54
54
                                 True,
55
55
                                 gobject.PARAM_READWRITE),
56
56
 
 
57
        'graph-column-visible': (gobject.TYPE_BOOLEAN,
 
58
                                 'Graph column',
 
59
                                 'Show graph column',
 
60
                                 True,
 
61
                                 gobject.PARAM_READWRITE),
 
62
 
57
63
        'date-column-visible': (gobject.TYPE_BOOLEAN,
58
64
                                 'Date',
59
65
                                 'Show date column',
60
66
                                 False,
61
 
                                 gobject.PARAM_READWRITE)
 
67
                                 gobject.PARAM_READWRITE),
 
68
 
 
69
        'compact': (gobject.TYPE_BOOLEAN,
 
70
                    'Compact view',
 
71
                    'Break ancestry lines to save space',
 
72
                    True,
 
73
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
 
74
 
 
75
        'mainline-only': (gobject.TYPE_BOOLEAN,
 
76
                    'Mainline only',
 
77
                    'Only show the mainline history.',
 
78
                    False,
 
79
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
62
80
 
63
81
    }
64
82
 
68
86
                             ()),
69
87
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
70
88
                              gobject.TYPE_NONE,
71
 
                              ())
 
89
                              ()),
 
90
        'revision-activated': (gobject.SIGNAL_RUN_FIRST,
 
91
                              gobject.TYPE_NONE,
 
92
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
 
93
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
 
94
                              gobject.TYPE_NONE,
 
95
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
72
96
    }
73
97
 
74
 
    def __init__(self, branch, start, maxnum, broken_line_length=None):
 
98
    def __init__(self, branch, start, maxnum, compact=True):
75
99
        """Create a new TreeView.
76
100
 
77
101
        :param branch: Branch object for branch to show.
81
105
        :param broken_line_length: After how much lines to break 
82
106
                                   branches.
83
107
        """
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
 
108
        gtk.VBox.__init__(self, spacing=0)
 
109
 
 
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())
 
113
 
 
114
        self.scrolled_window = gtk.ScrolledWindow()
 
115
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
 
116
                                        gtk.POLICY_AUTOMATIC)
 
117
        self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
 
118
        self.scrolled_window.show()
 
119
        self.pack_start(self.scrolled_window, expand=True, fill=True)
 
120
 
 
121
        self.scrolled_window.add(self.construct_treeview())
 
122
        
 
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
        self.loading_msg_box.show()
 
226
        gobject.idle_add(self.populate, self.get_revision())
 
227
 
 
228
    def update(self):
 
229
        try:
 
230
            self.branch.unlock()
 
231
            try:
 
232
                self.branch.lock_write()
 
233
                self.branch.update()
 
234
            finally:
 
235
                self.branch.unlock()
 
236
        finally:
 
237
            self.branch.lock_read()
 
238
 
158
239
    def back(self):
159
240
        """Signal handler for the Back button."""
160
241
        parents = self.get_parents()
185
266
        else:
186
267
            self.set_revision_id(children[0])
187
268
 
188
 
    def populate(self, start, maxnum, broken_line_length=None):
 
269
    def populate(self, revision=None):
189
270
        """Fill the treeview with contents.
190
271
 
191
272
        :param start: Revision id of revision to start with.
194
275
        :param broken_line_length: After how much lines branches \
195
276
                       should be broken.
196
277
        """
 
278
 
 
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
 
197
286
        self.branch.lock_read()
198
287
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
199
 
                                                        start,
200
 
                                                        maxnum, 
201
 
                                                        broken_line_length)
 
288
                                                        self.start,
 
289
                                                        self.maxnum, 
 
290
                                                        broken_line_length,
 
291
                                                        show_graph,
 
292
                                                        self.mainline_only)
202
293
 
203
 
        self.model = TreeModel(self.branch.repository, linegraphdata)
 
294
        self.model = TreeModel(self.branch, linegraphdata)
204
295
        self.graph_cell.columns_len = columns_len
205
296
        width = self.graph_cell.get_size(self.treeview)[2]
 
297
        if width > 500:
 
298
            width = 500
206
299
        self.graph_column.set_fixed_width(width)
207
300
        self.graph_column.set_max_width(width)
208
301
        self.index = index
209
302
        self.treeview.set_model(self.model)
210
 
        self.treeview.set_cursor(0)
 
303
 
 
304
        if not revision or revision == NULL_REVISION:
 
305
            self.treeview.set_cursor(0)
 
306
        else:
 
307
            self.set_revision(revision)
 
308
 
211
309
        self.emit('revisions-loaded')
212
310
 
213
311
        return False
214
312
 
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()
237
 
 
238
313
    def construct_treeview(self):
239
314
        self.treeview = gtk.TreeView()
240
315
 
257
332
 
258
333
        self.treeview.set_property('fixed-height-mode', True)
259
334
 
260
 
        self.add(self.treeview)
261
335
        self.treeview.show()
262
336
 
263
337
        cell = gtk.CellRendererText()
277
351
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
278
352
        self.graph_column.pack_start(self.graph_cell, expand=False)
279
353
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
 
354
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
280
355
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
281
356
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
282
357
        self.treeview.append_column(self.graph_column)
284
359
        cell = gtk.CellRendererText()
285
360
        cell.set_property("width-chars", 65)
286
361
        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)
 
362
        self.summary_column = gtk.TreeViewColumn("Summary")
 
363
        self.summary_column.set_resizable(True)
 
364
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
365
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
366
        self.summary_column.pack_start(cell, expand=True)
 
367
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
 
368
        self.treeview.append_column(self.summary_column)
294
369
 
295
370
        cell = gtk.CellRendererText()
296
371
        cell.set_property("width-chars", 15)
300
375
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
301
376
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
302
377
        self.committer_column.pack_start(cell, expand=True)
303
 
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITER)
 
378
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
304
379
        self.treeview.append_column(self.committer_column)
305
380
 
306
381
        cell = gtk.CellRendererText()
314
389
        self.date_column.pack_start(cell, expand=True)
315
390
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
316
391
        self.treeview.append_column(self.date_column)
 
392
        
 
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
317
412
 
318
413
    def _on_selection_changed(self, treeview):
319
414
        """callback for when the treeview changes."""
328
423
            menu = RevisionPopupMenu(self.branch.repository, 
329
424
                [self.get_revision().revision_id],
330
425
                self.branch)
 
426
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
331
427
            menu.popup(None, None, None, event.button, event.get_time())
332
428
 
333
429
    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()
 
430
        self.emit('revision-activated', path, col)