/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
1
# -*- coding: UTF-8 -*-
2
"""Revision history view.
3
4
"""
5
486.1.1 by matkor at laptop-hp
Fix for presenting log in olive-gtk.
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
7
__author__    = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
8
9
import gtk
10
import gobject
11
import pango
724 by Jelmer Vernooij
Fix formatting, imports.
12
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
13
from bzrlib import ui
330.4.3 by Daniel Schierbeck
Switched to using NULL_REVISION instead of None.
14
from bzrlib.revision import NULL_REVISION
724 by Jelmer Vernooij
Fix formatting, imports.
15
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
16
from bzrlib.plugins.gtk import lock
724 by Jelmer Vernooij
Fix formatting, imports.
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
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
21
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
22
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
23
class TreeView(gtk.VBox):
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
24
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
25
    __gproperties__ = {
352 by Daniel Schierbeck
Added branch property to treeview.
26
        'branch': (gobject.TYPE_PYOBJECT,
27
                   'Branch',
28
                   'The Bazaar branch being visualized',
29
                   gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE),
30
356 by Daniel Schierbeck
Made revision a property on TreeView.
31
        'revision': (gobject.TYPE_PYOBJECT,
32
                     'Revision',
33
                     'The currently selected revision',
34
                     gobject.PARAM_READWRITE),
35
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
36
        'revision-number': (gobject.TYPE_STRING,
37
                            'Revision number',
38
                            'The number of the selected revision',
39
                            '',
40
                            gobject.PARAM_READABLE),
41
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
42
        'children': (gobject.TYPE_PYOBJECT,
43
                     'Child revisions',
44
                     'Children of the currently selected revision',
45
                     gobject.PARAM_READABLE),
46
47
        'parents': (gobject.TYPE_PYOBJECT,
48
                    'Parent revisions',
49
                    'Parents to the currently selected revision',
50
                    gobject.PARAM_READABLE),
51
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
52
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
53
                                 'Revision number column',
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
54
                                 'Show revision number column',
55
                                 True,
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
56
                                 gobject.PARAM_READWRITE),
57
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
58
        'graph-column-visible': (gobject.TYPE_BOOLEAN,
59
                                 'Graph column',
60
                                 'Show graph column',
61
                                 True,
62
                                 gobject.PARAM_READWRITE),
63
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
64
        'date-column-visible': (gobject.TYPE_BOOLEAN,
360 by Daniel Schierbeck
Fixed wrong text in date property.
65
                                 'Date',
66
                                 'Show date column',
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
67
                                 False,
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
68
                                 gobject.PARAM_READWRITE),
69
70
        'compact': (gobject.TYPE_BOOLEAN,
71
                    'Compact view',
72
                    'Break ancestry lines to save space',
73
                    True,
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
74
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
75
76
        'mainline-only': (gobject.TYPE_BOOLEAN,
77
                    'Mainline only',
78
                    'Only show the mainline history.',
79
                    False,
80
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
81
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
82
    }
83
307 by Daniel Schierbeck
Made load notification work again.
84
    __gsignals__ = {
345 by Daniel Schierbeck
Made treeview columns instance variables.
85
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
86
                              gobject.TYPE_NONE,
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
87
                              ()),
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
88
        'revision-activated': (gobject.SIGNAL_RUN_FIRST,
89
                              gobject.TYPE_NONE,
90
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
91
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
92
                              gobject.TYPE_NONE,
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
93
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
94
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
95
                              ())
307 by Daniel Schierbeck
Made load notification work again.
96
    }
97
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
98
    def __init__(self, branch, start, maxnum, compact=True):
322 by Jelmer Vernooij
Add docstrings.
99
        """Create a new TreeView.
100
101
        :param branch: Branch object for branch to show.
102
        :param start: Revision id of top revision.
103
        :param maxnum: Maximum number of revisions to display, 
104
                       None for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
105
        :param broken_line_length: After how much lines to break 
106
                                   branches.
322 by Jelmer Vernooij
Add docstrings.
107
        """
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
108
        gtk.VBox.__init__(self, spacing=0)
109
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
110
        self.progress_widget = ProgressPanel()
111
        self.pack_start(self.progress_widget, expand=False, fill=True)
645.1.5 by Vincent Ladeuil
Integrater Jelmer patch and implement a more robust solution.
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)
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
115
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
116
        self.scrolled_window = gtk.ScrolledWindow()
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
117
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
118
                                        gtk.POLICY_AUTOMATIC)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
119
        self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
120
        self.scrolled_window.show()
121
        self.pack_start(self.scrolled_window, expand=True, fill=True)
122
123
        self.scrolled_window.add(self.construct_treeview())
303 by Daniel Schierbeck
Made basic signaling work.
124
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
125
        self.path = None
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
126
        self.branch = branch
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
127
        self.revision = None
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
128
        self.index = {}
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
129
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
130
        self.start = start
131
        self.maxnum = maxnum
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
132
        self.compact = compact
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
133
134
        gobject.idle_add(self.populate)
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
135
645.1.5 by Vincent Ladeuil
Integrater Jelmer patch and implement a more robust solution.
136
        self.connect("destroy", self._on_destroy)
137
138
    def _on_destroy(self, *ignored):
139
        self.branch.unlock()
140
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
141
            # We'are using our own ui, let's tell it to stop using our widget.
142
            ui.ui_factory.set_progress_bar_widget(None)
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
143
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
144
    def do_get_property(self, property):
145
        if property.name == 'revno-column-visible':
352 by Daniel Schierbeck
Added branch property to treeview.
146
            return self.revno_column.get_visible()
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
147
        elif property.name == 'graph-column-visible':
148
            return self.graph_column.get_visible()
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
149
        elif property.name == 'date-column-visible':
150
            return self.date_column.get_visible()
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
151
        elif property.name == 'compact':
152
            return self.compact
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
153
        elif property.name == 'mainline-only':
154
            return self.mainline_only
352 by Daniel Schierbeck
Added branch property to treeview.
155
        elif property.name == 'branch':
156
            return self.branch
356 by Daniel Schierbeck
Made revision a property on TreeView.
157
        elif property.name == 'revision':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
158
            return self.model.get_value(self.model.get_iter(self.path),
159
                                        treemodel.REVISION)
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
160
        elif property.name == 'revision-number':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
161
            return self.model.get_value(self.model.get_iter(self.path),
162
                                        treemodel.REVNO)
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
163
        elif property.name == 'children':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
164
            return self.model.get_value(self.model.get_iter(self.path),
165
                                        treemodel.CHILDREN)
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
166
        elif property.name == 'parents':
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
167
            return self.model.get_value(self.model.get_iter(self.path),
168
                                        treemodel.PARENTS)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
169
        else:
170
            raise AttributeError, 'unknown property %s' % property.name
171
172
    def do_set_property(self, property, value):
173
        if property.name == 'revno-column-visible':
174
            self.revno_column.set_visible(value)
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
175
        elif property.name == 'graph-column-visible':
176
            self.graph_column.set_visible(value)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
177
        elif property.name == 'date-column-visible':
178
            self.date_column.set_visible(value)
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
179
        elif property.name == 'compact':
180
            self.compact = value
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
181
        elif property.name == 'mainline-only':
182
            self.mainline_only = value
352 by Daniel Schierbeck
Added branch property to treeview.
183
        elif property.name == 'branch':
184
            self.branch = value
356 by Daniel Schierbeck
Made revision a property on TreeView.
185
        elif property.name == 'revision':
186
            self.set_revision_id(value.revision_id)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
187
        else:
188
            raise AttributeError, 'unknown property %s' % property.name
189
303 by Daniel Schierbeck
Made basic signaling work.
190
    def get_revision(self):
322 by Jelmer Vernooij
Add docstrings.
191
        """Return revision id of currently selected revision, or None."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
192
        return self.get_property('revision')
193
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
194
    def has_revision_id(self, revision_id):
195
        return (revision_id in self.index)
196
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
197
    def set_revision(self, revision):
198
        self.set_property('revision', revision)
303 by Daniel Schierbeck
Made basic signaling work.
199
356 by Daniel Schierbeck
Made revision a property on TreeView.
200
    def set_revision_id(self, revid):
322 by Jelmer Vernooij
Add docstrings.
201
        """Change the currently selected revision.
202
203
        :param revid: Revision id of revision to display.
204
        """
305 by Daniel Schierbeck
Moved revision selection to the new view.
205
        self.treeview.set_cursor(self.index[revid])
206
        self.treeview.grab_focus()
207
303 by Daniel Schierbeck
Made basic signaling work.
208
    def get_children(self):
322 by Jelmer Vernooij
Add docstrings.
209
        """Return the children of the currently selected revision.
210
211
        :return: list of revision ids.
212
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
213
        return self.get_property('children')
303 by Daniel Schierbeck
Made basic signaling work.
214
215
    def get_parents(self):
322 by Jelmer Vernooij
Add docstrings.
216
        """Return the parents of the currently selected revision.
217
218
        :return: list of revision ids.
219
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
220
        return self.get_property('parents')
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
221
222
    def add_tag(self, tag, revid=None):
223
        if revid is None: revid = self.revision.revision_id
224
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
225
        if lock.release(self.branch):
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
226
            try:
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
227
                lock.acquire(self.branch, lock.WRITE)
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
228
                self.model.add_tag(tag, revid)
229
            finally:
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
230
                lock.release(self.branch)
231
232
            lock.acquire(self.branch, lock.READ)
233
234
            self.emit('tag-added', tag, revid)
724 by Jelmer Vernooij
Fix formatting, imports.
235
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
236
    def refresh(self):
237
        gobject.idle_add(self.populate, self.get_revision())
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
238
404 by Daniel Schierbeck
Made the refresh use proper locking.
239
    def update(self):
240
        try:
241
            self.branch.unlock()
242
            try:
243
                self.branch.lock_write()
244
                self.branch.update()
245
            finally:
246
                self.branch.unlock()
247
        finally:
248
            self.branch.lock_read()
249
304 by Daniel Schierbeck
Made forward/back buttons work again.
250
    def back(self):
322 by Jelmer Vernooij
Add docstrings.
251
        """Signal handler for the Back button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
252
        parents = self.get_parents()
304 by Daniel Schierbeck
Made forward/back buttons work again.
253
        if not len(parents):
254
            return
255
256
        for parent_id in parents:
257
            parent_index = self.index[parent_id]
258
            parent = self.model[parent_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
259
            if same_branch(self.get_revision(), parent):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
260
                self.set_revision(parent)
304 by Daniel Schierbeck
Made forward/back buttons work again.
261
                break
262
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
263
            self.set_revision_id(parents[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
264
265
    def forward(self):
322 by Jelmer Vernooij
Add docstrings.
266
        """Signal handler for the Forward button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
267
        children = self.get_children()
304 by Daniel Schierbeck
Made forward/back buttons work again.
268
        if not len(children):
269
            return
270
271
        for child_id in children:
272
            child_index = self.index[child_id]
273
            child = self.model[child_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
274
            if same_branch(child, self.get_revision()):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
275
                self.set_revision(child)
304 by Daniel Schierbeck
Made forward/back buttons work again.
276
                break
277
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
278
            self.set_revision_id(children[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
279
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
280
    def populate(self, revision=None):
322 by Jelmer Vernooij
Add docstrings.
281
        """Fill the treeview with contents.
282
283
        :param start: Revision id of revision to start with.
284
        :param maxnum: Maximum number of revisions to display, or None 
285
                       for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
286
        :param broken_line_length: After how much lines branches \
287
                       should be broken.
322 by Jelmer Vernooij
Add docstrings.
288
        """
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
289
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
290
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
291
            # We'are using our own ui, let's tell it to use our widget.
292
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
293
        self.progress_bar = ui.ui_factory.nested_progress_bar()
576.4.1 by Jelmer Vernooij
Avoid using explicit names for progress bar function arguments since they differ.
294
        self.progress_bar.update("Loading ancestry graph", 0, 5)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
295
296
        try:
297
            if self.compact:
298
                broken_line_length = 32
299
            else:
300
                broken_line_length = None
724 by Jelmer Vernooij
Fix formatting, imports.
301
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
302
            show_graph = self.graph_column.get_visible()
303
304
            self.branch.lock_read()
511.5.3 by Jelmer Vernooij
Merge Chad's progress bar in viz patch.
305
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
306
                                                            self.start,
307
                                                            self.maxnum, 
308
                                                            broken_line_length,
309
                                                            show_graph,
475.2.2 by Chad MILLER
Big diff, few changes. :(
310
                                                            self.mainline_only,
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
311
                                                            self.progress_bar)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
312
724 by Jelmer Vernooij
Fix formatting, imports.
313
            self.model = treemodel.TreeModel(self.branch, linegraphdata)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
314
            self.graph_cell.columns_len = columns_len
315
            width = self.graph_cell.get_size(self.treeview)[2]
316
            if width > 500:
317
                width = 500
318
            self.graph_column.set_fixed_width(width)
319
            self.graph_column.set_max_width(width)
320
            self.index = index
321
            self.treeview.set_model(self.model)
322
323
            if not revision or revision == NULL_REVISION:
324
                self.treeview.set_cursor(0)
325
            else:
326
                self.set_revision(revision)
327
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
328
            self.emit('refreshed')
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
329
            return False
330
        finally:
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
331
            self.progress_bar.finished()
304 by Daniel Schierbeck
Made forward/back buttons work again.
332
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
333
    def construct_treeview(self):
334
        self.treeview = gtk.TreeView()
335
336
        self.treeview.set_rules_hint(True)
330.1.2 by Daniel Schierbeck
Replaced literal column index with equivalent symbol.
337
        self.treeview.set_search_column(treemodel.REVNO)
724 by Jelmer Vernooij
Fix formatting, imports.
338
330.5.5 by Szilveszter Farkas (Phanatic)
Use better fix by John.
339
        # Fix old PyGTK bug - by JAM
340
        set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
341
        if set_tooltip is not None:
423.4.3 by Daniel Schierbeck
Made the MESSAGE column be the tooltip column.
342
            set_tooltip(treemodel.MESSAGE)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
343
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
344
        self._prev_cursor_path = None
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
345
        self.treeview.connect("cursor-changed",
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
346
                self._on_selection_changed)
347
348
        self.treeview.connect("row-activated", 
349
                self._on_revision_activated)
350
351
        self.treeview.connect("button-release-event", 
352
                self._on_revision_selected)
353
354
        self.treeview.set_property('fixed-height-mode', True)
355
356
        self.treeview.show()
357
358
        cell = gtk.CellRendererText()
359
        cell.set_property("width-chars", 15)
360
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
345 by Daniel Schierbeck
Made treeview columns instance variables.
361
        self.revno_column = gtk.TreeViewColumn("Revision No")
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
362
        self.revno_column.set_resizable(False)
345 by Daniel Schierbeck
Made treeview columns instance variables.
363
        self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
364
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
365
        self.revno_column.pack_start(cell, expand=True)
366
        self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
367
        self.treeview.append_column(self.revno_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
368
369
        self.graph_cell = CellRendererGraph()
370
        self.graph_column = gtk.TreeViewColumn()
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
371
        self.graph_column.set_resizable(False)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
372
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
373
        self.graph_column.pack_start(self.graph_cell, expand=True)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
374
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
423.5.1 by Ali Sabil
Added tags visualization in the graph
375
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
376
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
377
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
378
        self.treeview.append_column(self.graph_column)
379
380
        cell = gtk.CellRendererText()
381
        cell.set_property("width-chars", 65)
382
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
383
        self.summary_column = gtk.TreeViewColumn("Summary")
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
384
        self.summary_column.set_resizable(False)
385
        self.summary_column.set_expand(True)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
386
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
387
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
388
        self.summary_column.pack_start(cell, expand=True)
389
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
390
        self.treeview.append_column(self.summary_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
391
392
        cell = gtk.CellRendererText()
393
        cell.set_property("width-chars", 15)
394
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
395
        self.authors_column = gtk.TreeViewColumn("Author(s)")
396
        self.authors_column.set_resizable(False)
397
        self.authors_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
398
        self.authors_column.set_fixed_width(200)
399
        self.authors_column.pack_start(cell, expand=True)
400
        self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
401
        self.treeview.append_column(self.authors_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
402
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
403
        cell = gtk.CellRendererText()
359 by Daniel Schierbeck
Simplified date format.
404
        cell.set_property("width-chars", 20)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
405
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
406
        self.date_column = gtk.TreeViewColumn("Date")
407
        self.date_column.set_visible(False)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
408
        self.date_column.set_resizable(False)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
409
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
410
        self.date_column.set_fixed_width(130)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
411
        self.date_column.pack_start(cell, expand=True)
412
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
413
        self.treeview.append_column(self.date_column)
724 by Jelmer Vernooij
Fix formatting, imports.
414
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
415
        return self.treeview
724 by Jelmer Vernooij
Fix formatting, imports.
416
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
417
    def _on_selection_changed(self, treeview):
303 by Daniel Schierbeck
Made basic signaling work.
418
        """callback for when the treeview changes."""
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
419
        (path, focus) = treeview.get_cursor()
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
420
        if (path is not None) and (path != self._prev_cursor_path):
421
            self._prev_cursor_path = path # avoid emitting twice per click
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
422
            self.path = path
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
423
            self.emit('revision-selected')
424
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
425
    def _on_revision_selected(self, widget, event):
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
426
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
427
        if event.button == 3:
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
428
            menu = RevisionMenu(self.branch.repository, 
312 by Daniel Schierbeck
Made right-clicking work again.
429
                [self.get_revision().revision_id],
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
430
                self.branch)
423.7.8 by Daniel Schierbeck
Made the revision popup menu correctly add tags.
431
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
432
            menu.popup(None, None, None, event.button, event.get_time())
433
434
    def _on_revision_activated(self, widget, path, col):
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
435
        self.emit('revision-activated', path, col)