/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.21 by Curtis Hovey
Replaced the missing GenericCellRenderer with CellRenderer.
108
        Gtk.VBox.__init__(self, 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
713.2.5 by Jelmer Vernooij
Construct model early.
134
        self.model = treemodel.TreeModel(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()
304 by Daniel Schierbeck
Made forward/back buttons work again.
263
        if not len(parents):
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()
304 by Daniel Schierbeck
Made forward/back buttons work again.
278
        if not len(children):
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()
511.5.3 by Jelmer Vernooij
Merge Chad's progress bar in viz patch.
315
            (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.
316
                                                            self.start,
317
                                                            self.maxnum, 
318
                                                            broken_line_length,
319
                                                            show_graph,
475.2.2 by Chad MILLER
Big diff, few changes. :(
320
                                                            self.mainline_only,
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
321
                                                            self.progress_bar)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
322
713.2.5 by Jelmer Vernooij
Construct model early.
323
            self.model.line_graph_data = linegraphdata
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
324
            self.graph_cell.columns_len = columns_len
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
325
            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.
326
            if width > 500:
327
                width = 500
328
            self.graph_column.set_fixed_width(width)
329
            self.graph_column.set_max_width(width)
330
            self.index = index
331
            self.treeview.set_model(self.model)
332
333
            if not revision or revision == NULL_REVISION:
734.1.23 by Curtis Hovey
Always pass a Gtk.TreePath instead of an int or tuple.
334
                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.
335
            else:
336
                self.set_revision(revision)
337
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
338
            self.emit('refreshed')
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
339
            return False
340
        finally:
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
341
            self.progress_bar.finished()
304 by Daniel Schierbeck
Made forward/back buttons work again.
342
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
343
    def construct_treeview(self):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
344
        self.treeview = Gtk.TreeView()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
345
346
        self.treeview.set_rules_hint(True)
723.1.1 by Sergei Golubchik
interactive substring search in gannotate
347
        # combined revno/summary interactive search
348
        #
349
        # the row in a treemodel is considered "matched" if a REVNO *starts*
350
        # from the key (that is the key is found in a REVNO at the offset 0)
351
        # or if a MESSAGE *contains* the key anywhere (that is, the key is
352
        # found case insensitively in a MESSAGE at any offset)
353
        def search_equal_func(model, column, key, iter):
354
            return (model.get_value(iter, treemodel.REVNO).find(key) != 0
355
                and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
356
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
357
        self.treeview.set_search_equal_func(search_equal_func, None)
723.1.1 by Sergei Golubchik
interactive substring search in gannotate
358
        self.treeview.set_enable_search(True)
724 by Jelmer Vernooij
Fix formatting, imports.
359
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
360
        self.treeview.set_tooltip_column(treemodel.MESSAGE)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
361
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
362
        self._prev_cursor_path = None
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
363
        self.treeview.connect("cursor-changed",
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
364
                self._on_selection_changed)
365
366
        self.treeview.connect("row-activated", 
367
                self._on_revision_activated)
368
369
        self.treeview.connect("button-release-event", 
370
                self._on_revision_selected)
371
372
        self.treeview.set_property('fixed-height-mode', True)
373
374
        self.treeview.show()
375
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
376
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
377
        cell.set_property("width-chars", 15)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
378
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
379
        self.revno_column = Gtk.TreeViewColumn("Revision No")
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
380
        self.revno_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
381
        self.revno_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
382
        self.revno_column.set_fixed_width(
383
            cell.get_preferred_width(self.treeview)[1])
384
        self.revno_column.pack_start(cell, True)
345 by Daniel Schierbeck
Made treeview columns instance variables.
385
        self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
386
        self.treeview.append_column(self.revno_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
387
388
        self.graph_cell = CellRendererGraph()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
389
        self.graph_column = Gtk.TreeViewColumn()
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
390
        self.graph_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
391
        self.graph_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
392
        self.graph_column.pack_start(self.graph_cell, True)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
393
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
423.5.1 by Ali Sabil
Added tags visualization in the graph
394
        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.
395
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
396
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
397
        self.treeview.append_column(self.graph_column)
398
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
399
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
400
        cell.set_property("width-chars", 65)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
401
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
402
        self.summary_column = Gtk.TreeViewColumn("Summary")
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
403
        self.summary_column.set_resizable(True)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
404
        self.summary_column.set_expand(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
405
        self.summary_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
406
        self.summary_column.set_fixed_width(
407
            cell.get_preferred_width(self.treeview)[1])
408
        self.summary_column.pack_start(cell, True)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
409
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
410
        self.treeview.append_column(self.summary_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
411
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
412
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
413
        cell.set_property("width-chars", 15)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
414
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
415
        self.authors_column = Gtk.TreeViewColumn("Author(s)")
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
416
        self.authors_column.set_resizable(False)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
417
        self.authors_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
418
        self.authors_column.set_fixed_width(200)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
419
        self.authors_column.pack_start(cell, True)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
420
        self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
421
        self.treeview.append_column(self.authors_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
422
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
423
        cell = Gtk.CellRendererText()
359 by Daniel Schierbeck
Simplified date format.
424
        cell.set_property("width-chars", 20)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
425
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
426
        self.date_column = Gtk.TreeViewColumn("Date")
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
427
        self.date_column.set_visible(False)
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
428
        self.date_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
429
        self.date_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
430
        self.date_column.set_fixed_width(130)
734.1.24 by Curtis Hovey
Updated most of BranchView to gtk3.
431
        self.date_column.pack_start(cell, True)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
432
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
433
        self.treeview.append_column(self.date_column)
724 by Jelmer Vernooij
Fix formatting, imports.
434
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
435
        return self.treeview
724 by Jelmer Vernooij
Fix formatting, imports.
436
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
437
    def _on_selection_changed(self, treeview):
303 by Daniel Schierbeck
Made basic signaling work.
438
        """callback for when the treeview changes."""
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
439
        (path, focus) = treeview.get_cursor()
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
440
        if (path is not None) and (path != self._prev_cursor_path):
441
            self._prev_cursor_path = path # avoid emitting twice per click
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
442
            self.path = path
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
443
            self.emit('revision-selected')
444
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
445
    def _on_revision_selected(self, widget, event):
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
446
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
447
        if event.button == 3:
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
448
            menu = RevisionMenu(self.branch.repository, 
312 by Daniel Schierbeck
Made right-clicking work again.
449
                [self.get_revision().revision_id],
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
450
                self.branch)
423.7.8 by Daniel Schierbeck
Made the revision popup menu correctly add tags.
451
            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.
452
            menu.popup(None, None, None, event.button, event.get_time())
453
454
    def _on_revision_activated(self, widget, path, col):
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
455
        self.emit('revision-activated', path, col)