/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
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
9
from gi.repository import Gtk
10
from gi.repository import GObject
11
from gi.repository 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
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
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__ = {
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
26
        'branch': (GObject.TYPE_PYOBJECT,
352 by Daniel Schierbeck
Added branch property to treeview.
27
                   'Branch',
28
                   'The Bazaar branch being visualized',
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
29
                   GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE),
352 by Daniel Schierbeck
Added branch property to treeview.
30
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
31
        'revision': (GObject.TYPE_PYOBJECT,
356 by Daniel Schierbeck
Made revision a property on TreeView.
32
                     'Revision',
33
                     'The currently selected revision',
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
34
                     GObject.PARAM_READWRITE),
356 by Daniel Schierbeck
Made revision a property on TreeView.
35
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
36
        'revision-number': (GObject.TYPE_STRING,
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
37
                            'Revision number',
38
                            'The number of the selected revision',
39
                            '',
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
40
                            GObject.PARAM_READABLE),
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
41
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
42
        'children': (GObject.TYPE_PYOBJECT,
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
43
                     'Child revisions',
44
                     'Children of the currently selected revision',
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
45
                     GObject.PARAM_READABLE),
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
46
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
47
        'parents': (GObject.TYPE_PYOBJECT,
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
48
                    'Parent revisions',
49
                    'Parents to the currently selected revision',
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
50
                    GObject.PARAM_READABLE),
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
51
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
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,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
56
                                 GObject.PARAM_READWRITE),
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
57
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
58
        'graph-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.
59
                                 'Graph column',
60
                                 'Show graph column',
61
                                 True,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
62
                                 GObject.PARAM_READWRITE),
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.
63
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
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,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
68
                                 GObject.PARAM_READWRITE),
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
69
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
70
        'compact': (GObject.TYPE_BOOLEAN,
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
71
                    'Compact view',
72
                    'Break ancestry lines to save space',
73
                    True,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
74
                    GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
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.
75
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
76
        'mainline-only': (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.
77
                    'Mainline only',
78
                    'Only show the mainline history.',
79
                    False,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
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__ = {
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
85
        'revision-selected': (GObject.SignalFlags.RUN_FIRST,
86
                              None,
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
87
                              ()),
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
88
        'revision-activated': (GObject.SignalFlags.RUN_FIRST,
89
                              None,
90
                              (GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT)),
91
        'tag-added': (GObject.SignalFlags.RUN_FIRST,
92
                              None,
93
                              (GObject.TYPE_STRING, GObject.TYPE_STRING)),
94
        'refreshed': (GObject.SignalFlags.RUN_FIRST, None,
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
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
        """
734.1.51 by Curtis Hovey
Fix the initializer for many classes.
108
        super(TreeView, self).__init__(homogeneous=False, spacing=0)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
109
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
110
        self.progress_widget = ProgressPanel()
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
111
        self.pack_start(self.progress_widget, False, True, 0)
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
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
116
        self.scrolled_window = Gtk.ScrolledWindow()
117
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
118
                                        Gtk.PolicyType.AUTOMATIC)
119
        self.scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
120
        self.scrolled_window.show()
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
121
        self.pack_start(self.scrolled_window, True, True, 0)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
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
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
134
        self.model = treemodel.BranchTreeModel(self.branch, [])
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
135
        GObject.idle_add(self.populate)
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
136
645.1.5 by Vincent Ladeuil
Integrater Jelmer patch and implement a more robust solution.
137
        self.connect("destroy", self._on_destroy)
138
139
    def _on_destroy(self, *ignored):
140
        self.branch.unlock()
141
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
142
            # We'are using our own ui, let's tell it to stop using our widget.
143
            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.
144
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
145
    def do_get_property(self, property):
146
        if property.name == 'revno-column-visible':
352 by Daniel Schierbeck
Added branch property to treeview.
147
            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.
148
        elif property.name == 'graph-column-visible':
149
            return self.graph_column.get_visible()
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
150
        elif property.name == 'date-column-visible':
151
            return self.date_column.get_visible()
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
152
        elif property.name == 'compact':
153
            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.
154
        elif property.name == 'mainline-only':
155
            return self.mainline_only
352 by Daniel Schierbeck
Added branch property to treeview.
156
        elif property.name == 'branch':
157
            return self.branch
356 by Daniel Schierbeck
Made revision a property on TreeView.
158
        elif property.name == 'revision':
713.2.6 by Jelmer Vernooij
Fix signal handling.
159
            if self.path is None:
160
                return None
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.REVISION)
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
163
        elif property.name == 'revision-number':
713.2.6 by Jelmer Vernooij
Fix signal handling.
164
            if self.path is None:
165
                return None
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
166
            return self.model.get_value(self.model.get_iter(self.path),
167
                                        treemodel.REVNO)
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
168
        elif property.name == 'children':
713.2.6 by Jelmer Vernooij
Fix signal handling.
169
            if self.path is None:
170
                return None
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
171
            return self.model.get_value(self.model.get_iter(self.path),
172
                                        treemodel.CHILDREN)
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
173
        elif property.name == 'parents':
713.2.6 by Jelmer Vernooij
Fix signal handling.
174
            if self.path is None:
175
                return None
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
176
            return self.model.get_value(self.model.get_iter(self.path),
177
                                        treemodel.PARENTS)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
178
        else:
179
            raise AttributeError, 'unknown property %s' % property.name
180
181
    def do_set_property(self, property, value):
182
        if property.name == 'revno-column-visible':
183
            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.
184
        elif property.name == 'graph-column-visible':
185
            self.graph_column.set_visible(value)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
186
        elif property.name == 'date-column-visible':
187
            self.date_column.set_visible(value)
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
188
        elif property.name == 'compact':
189
            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.
190
        elif property.name == 'mainline-only':
191
            self.mainline_only = value
352 by Daniel Schierbeck
Added branch property to treeview.
192
        elif property.name == 'branch':
193
            self.branch = value
356 by Daniel Schierbeck
Made revision a property on TreeView.
194
        elif property.name == 'revision':
195
            self.set_revision_id(value.revision_id)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
196
        else:
197
            raise AttributeError, 'unknown property %s' % property.name
198
303 by Daniel Schierbeck
Made basic signaling work.
199
    def get_revision(self):
322 by Jelmer Vernooij
Add docstrings.
200
        """Return revision id of currently selected revision, or None."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
201
        return self.get_property('revision')
202
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
203
    def has_revision_id(self, revision_id):
204
        return (revision_id in self.index)
205
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
206
    def set_revision(self, revision):
207
        self.set_property('revision', revision)
303 by Daniel Schierbeck
Made basic signaling work.
208
356 by Daniel Schierbeck
Made revision a property on TreeView.
209
    def set_revision_id(self, revid):
322 by Jelmer Vernooij
Add docstrings.
210
        """Change the currently selected revision.
211
212
        :param revid: Revision id of revision to display.
213
        """
734.1.23 by Curtis Hovey
Always pass a Gtk.TreePath instead of an int or tuple.
214
        self.treeview.set_cursor(
215
            Gtk.TreePath(path=self.index[revid]), None, False)
305 by Daniel Schierbeck
Moved revision selection to the new view.
216
        self.treeview.grab_focus()
217
303 by Daniel Schierbeck
Made basic signaling work.
218
    def get_children(self):
322 by Jelmer Vernooij
Add docstrings.
219
        """Return the children of the currently selected revision.
220
221
        :return: list of revision ids.
222
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
223
        return self.get_property('children')
303 by Daniel Schierbeck
Made basic signaling work.
224
225
    def get_parents(self):
322 by Jelmer Vernooij
Add docstrings.
226
        """Return the parents of the currently selected revision.
227
228
        :return: list of revision ids.
229
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
230
        return self.get_property('parents')
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
231
232
    def add_tag(self, tag, revid=None):
233
        if revid is None: revid = self.revision.revision_id
234
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
235
        if lock.release(self.branch):
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
236
            try:
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
237
                lock.acquire(self.branch, lock.WRITE)
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
238
                self.model.add_tag(tag, revid)
239
            finally:
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
240
                lock.release(self.branch)
241
242
            lock.acquire(self.branch, lock.READ)
243
244
            self.emit('tag-added', tag, revid)
724 by Jelmer Vernooij
Fix formatting, imports.
245
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
246
    def refresh(self):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
247
        GObject.idle_add(self.populate, self.get_revision())
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
248
404 by Daniel Schierbeck
Made the refresh use proper locking.
249
    def update(self):
250
        try:
251
            self.branch.unlock()
252
            try:
253
                self.branch.lock_write()
254
                self.branch.update()
255
            finally:
256
                self.branch.unlock()
257
        finally:
258
            self.branch.lock_read()
259
304 by Daniel Schierbeck
Made forward/back buttons work again.
260
    def back(self):
322 by Jelmer Vernooij
Add docstrings.
261
        """Signal handler for the Back button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
262
        parents = self.get_parents()
734.1.37 by Curtis Hovey
parents and children can be None or a list.
263
        if not parents:
304 by Daniel Schierbeck
Made forward/back buttons work again.
264
            return
265
266
        for parent_id in parents:
267
            parent_index = self.index[parent_id]
268
            parent = self.model[parent_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
269
            if same_branch(self.get_revision(), parent):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
270
                self.set_revision(parent)
304 by Daniel Schierbeck
Made forward/back buttons work again.
271
                break
272
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
273
            self.set_revision_id(parents[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
274
275
    def forward(self):
322 by Jelmer Vernooij
Add docstrings.
276
        """Signal handler for the Forward button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
277
        children = self.get_children()
734.1.37 by Curtis Hovey
parents and children can be None or a list.
278
        if not children:
304 by Daniel Schierbeck
Made forward/back buttons work again.
279
            return
280
281
        for child_id in children:
282
            child_index = self.index[child_id]
283
            child = self.model[child_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
284
            if same_branch(child, self.get_revision()):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
285
                self.set_revision(child)
304 by Daniel Schierbeck
Made forward/back buttons work again.
286
                break
287
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
288
            self.set_revision_id(children[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
289
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
290
    def populate(self, revision=None):
322 by Jelmer Vernooij
Add docstrings.
291
        """Fill the treeview with contents.
292
293
        :param start: Revision id of revision to start with.
294
        :param maxnum: Maximum number of revisions to display, or None 
295
                       for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
296
        :param broken_line_length: After how much lines branches \
297
                       should be broken.
322 by Jelmer Vernooij
Add docstrings.
298
        """
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
299
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
300
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
301
            # We'are using our own ui, let's tell it to use our widget.
302
            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.
303
        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.
304
        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.
305
306
        try:
307
            if self.compact:
308
                broken_line_length = 32
309
            else:
310
                broken_line_length = None
724 by Jelmer Vernooij
Fix formatting, imports.
311
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
312
            show_graph = self.graph_column.get_visible()
313
314
            self.branch.lock_read()
734.1.41 by Curtis Hovey
Save point trying to make a graph visible.
315
            (linegraphdata, index, columns_len) = linegraph(
316
                self.branch.repository.get_graph(),
317
                self.start,
318
                self.maxnum, 
319
                broken_line_length,
320
                show_graph,
321
                self.mainline_only,
322
                self.progress_bar)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
323
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
324
            self.model.set_line_graph_data(linegraphdata)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
325
            self.graph_cell.columns_len = columns_len
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
326
            width = self.graph_cell.get_preferred_width(self.treeview)[1]
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
327
            if width > 500:
328
                width = 500
734.1.26 by Curtis Hovey
inlined PANGO_PIXELS macro because it is not public.
329
            elif width == 0:
330
                # The get_preferred_width() call got an insane value.
331
                width = 200
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
332
            self.graph_column.set_fixed_width(width)
333
            self.graph_column.set_max_width(width)
334
            self.index = index
335
            self.treeview.set_model(self.model)
336
337
            if not revision or revision == NULL_REVISION:
734.1.23 by Curtis Hovey
Always pass a Gtk.TreePath instead of an int or tuple.
338
                self.treeview.set_cursor(Gtk.TreePath(path=0), None, False)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
339
            else:
340
                self.set_revision(revision)
341
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
342
            self.emit('refreshed')
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
343
            return False
344
        finally:
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
345
            self.progress_bar.finished()
304 by Daniel Schierbeck
Made forward/back buttons work again.
346
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
347
    def construct_treeview(self):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
348
        self.treeview = Gtk.TreeView()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
349
350
        self.treeview.set_rules_hint(True)
723.1.1 by Sergei Golubchik
interactive substring search in gannotate
351
        # combined revno/summary interactive search
352
        #
353
        # the row in a treemodel is considered "matched" if a REVNO *starts*
354
        # from the key (that is the key is found in a REVNO at the offset 0)
355
        # or if a MESSAGE *contains* the key anywhere (that is, the key is
356
        # found case insensitively in a MESSAGE at any offset)
357
        def search_equal_func(model, column, key, iter):
358
            return (model.get_value(iter, treemodel.REVNO).find(key) != 0
359
                and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
360
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
361
        self.treeview.set_search_equal_func(search_equal_func, None)
723.1.1 by Sergei Golubchik
interactive substring search in gannotate
362
        self.treeview.set_enable_search(True)
724 by Jelmer Vernooij
Fix formatting, imports.
363
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
364
        self.treeview.set_tooltip_column(treemodel.MESSAGE)
734.1.41 by Curtis Hovey
Save point trying to make a graph visible.
365
        self.treeview.set_headers_visible(True)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
366
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
367
        self._prev_cursor_path = None
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
368
        self.treeview.connect("cursor-changed",
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
369
                self._on_selection_changed)
370
371
        self.treeview.connect("row-activated", 
372
                self._on_revision_activated)
373
374
        self.treeview.connect("button-release-event", 
375
                self._on_revision_selected)
376
377
        self.treeview.set_property('fixed-height-mode', True)
378
379
        self.treeview.show()
380
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
381
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
382
        cell.set_property("width-chars", 15)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
383
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
384
        self.revno_column = Gtk.TreeViewColumn("Revision No")
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
385
        self.revno_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
386
        self.revno_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
387
        self.revno_column.set_fixed_width(
388
            cell.get_preferred_width(self.treeview)[1])
389
        self.revno_column.pack_start(cell, True)
345 by Daniel Schierbeck
Made treeview columns instance variables.
390
        self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
391
        self.treeview.append_column(self.revno_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
392
393
        self.graph_cell = CellRendererGraph()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
394
        self.graph_column = Gtk.TreeViewColumn()
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
395
        self.graph_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
396
        self.graph_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
397
        self.graph_column.pack_start(self.graph_cell, True)
734.1.42 by Curtis Hovey
Small performance improvement.
398
        self.graph_column.add_attribute(
399
            self.graph_cell, "node", treemodel.NODE)
400
        self.graph_column.add_attribute(
401
            self.graph_cell, "tags", treemodel.TAGS)
402
        self.graph_column.add_attribute(
403
            self.graph_cell, "in-lines", treemodel.LAST_LINES)
404
        self.graph_column.add_attribute(
405
            self.graph_cell, "out-lines", treemodel.LINES)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
406
        self.treeview.append_column(self.graph_column)
407
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
408
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
409
        cell.set_property("width-chars", 65)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
410
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
411
        self.summary_column = Gtk.TreeViewColumn("Summary")
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
412
        self.summary_column.set_resizable(True)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
413
        self.summary_column.set_expand(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
414
        self.summary_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
415
        self.summary_column.set_fixed_width(
416
            cell.get_preferred_width(self.treeview)[1])
417
        self.summary_column.pack_start(cell, True)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
418
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
419
        self.treeview.append_column(self.summary_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
420
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
421
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
422
        cell.set_property("width-chars", 15)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
423
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
424
        self.authors_column = Gtk.TreeViewColumn("Author(s)")
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
425
        self.authors_column.set_resizable(False)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
426
        self.authors_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
427
        self.authors_column.set_fixed_width(200)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
428
        self.authors_column.pack_start(cell, True)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
429
        self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
430
        self.treeview.append_column(self.authors_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
431
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
432
        cell = Gtk.CellRendererText()
359 by Daniel Schierbeck
Simplified date format.
433
        cell.set_property("width-chars", 20)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
434
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
435
        self.date_column = Gtk.TreeViewColumn("Date")
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
436
        self.date_column.set_visible(False)
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
437
        self.date_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
438
        self.date_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
439
        self.date_column.set_fixed_width(130)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
440
        self.date_column.pack_start(cell, True)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
441
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
442
        self.treeview.append_column(self.date_column)
724 by Jelmer Vernooij
Fix formatting, imports.
443
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
444
        return self.treeview
724 by Jelmer Vernooij
Fix formatting, imports.
445
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
446
    def _on_selection_changed(self, treeview):
303 by Daniel Schierbeck
Made basic signaling work.
447
        """callback for when the treeview changes."""
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
448
        (path, focus) = treeview.get_cursor()
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
449
        if (path is not None) and (path != self._prev_cursor_path):
450
            self._prev_cursor_path = path # avoid emitting twice per click
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
451
            self.path = path
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
452
            self.emit('revision-selected')
453
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
454
    def _on_revision_selected(self, widget, event):
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
455
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
456
        if event.button == 3:
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
457
            menu = RevisionMenu(self.branch.repository, 
312 by Daniel Schierbeck
Made right-clicking work again.
458
                [self.get_revision().revision_id],
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
459
                self.branch)
423.7.8 by Daniel Schierbeck
Made the revision popup menu correctly add tags.
460
            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.
461
            menu.popup(None, None, None, event.button, event.get_time())
462
463
    def _on_revision_activated(self, widget, path, col):
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
464
        self.emit('revision-activated', path, col)