/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.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
108
        GObject.GObject.__init__(self, 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()
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
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()
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
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
        """
305 by Daniel Schierbeck
Moved revision selection to the new view.
214
        self.treeview.set_cursor(self.index[revid])
215
        self.treeview.grab_focus()
216
303 by Daniel Schierbeck
Made basic signaling work.
217
    def get_children(self):
322 by Jelmer Vernooij
Add docstrings.
218
        """Return the children of the currently selected revision.
219
220
        :return: list of revision ids.
221
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
222
        return self.get_property('children')
303 by Daniel Schierbeck
Made basic signaling work.
223
224
    def get_parents(self):
322 by Jelmer Vernooij
Add docstrings.
225
        """Return the parents of the currently selected revision.
226
227
        :return: list of revision ids.
228
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
229
        return self.get_property('parents')
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
230
231
    def add_tag(self, tag, revid=None):
232
        if revid is None: revid = self.revision.revision_id
233
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
234
        if lock.release(self.branch):
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
235
            try:
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
236
                lock.acquire(self.branch, lock.WRITE)
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
237
                self.model.add_tag(tag, revid)
238
            finally:
452.5.2 by Daniel Schierbeck
Added generalized locking functionality in lock.py.
239
                lock.release(self.branch)
240
241
            lock.acquire(self.branch, lock.READ)
242
243
            self.emit('tag-added', tag, revid)
724 by Jelmer Vernooij
Fix formatting, imports.
244
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
245
    def refresh(self):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
246
        GObject.idle_add(self.populate, self.get_revision())
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
247
404 by Daniel Schierbeck
Made the refresh use proper locking.
248
    def update(self):
249
        try:
250
            self.branch.unlock()
251
            try:
252
                self.branch.lock_write()
253
                self.branch.update()
254
            finally:
255
                self.branch.unlock()
256
        finally:
257
            self.branch.lock_read()
258
304 by Daniel Schierbeck
Made forward/back buttons work again.
259
    def back(self):
322 by Jelmer Vernooij
Add docstrings.
260
        """Signal handler for the Back button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
261
        parents = self.get_parents()
304 by Daniel Schierbeck
Made forward/back buttons work again.
262
        if not len(parents):
263
            return
264
265
        for parent_id in parents:
266
            parent_index = self.index[parent_id]
267
            parent = self.model[parent_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
268
            if same_branch(self.get_revision(), parent):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
269
                self.set_revision(parent)
304 by Daniel Schierbeck
Made forward/back buttons work again.
270
                break
271
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
272
            self.set_revision_id(parents[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
273
274
    def forward(self):
322 by Jelmer Vernooij
Add docstrings.
275
        """Signal handler for the Forward button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
276
        children = self.get_children()
304 by Daniel Schierbeck
Made forward/back buttons work again.
277
        if not len(children):
278
            return
279
280
        for child_id in children:
281
            child_index = self.index[child_id]
282
            child = self.model[child_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
283
            if same_branch(child, self.get_revision()):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
284
                self.set_revision(child)
304 by Daniel Schierbeck
Made forward/back buttons work again.
285
                break
286
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
287
            self.set_revision_id(children[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
288
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
289
    def populate(self, revision=None):
322 by Jelmer Vernooij
Add docstrings.
290
        """Fill the treeview with contents.
291
292
        :param start: Revision id of revision to start with.
293
        :param maxnum: Maximum number of revisions to display, or None 
294
                       for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
295
        :param broken_line_length: After how much lines branches \
296
                       should be broken.
322 by Jelmer Vernooij
Add docstrings.
297
        """
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
298
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
299
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
300
            # We'are using our own ui, let's tell it to use our widget.
301
            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.
302
        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.
303
        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.
304
305
        try:
306
            if self.compact:
307
                broken_line_length = 32
308
            else:
309
                broken_line_length = None
724 by Jelmer Vernooij
Fix formatting, imports.
310
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
311
            show_graph = self.graph_column.get_visible()
312
313
            self.branch.lock_read()
511.5.3 by Jelmer Vernooij
Merge Chad's progress bar in viz patch.
314
            (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.
315
                                                            self.start,
316
                                                            self.maxnum, 
317
                                                            broken_line_length,
318
                                                            show_graph,
475.2.2 by Chad MILLER
Big diff, few changes. :(
319
                                                            self.mainline_only,
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
320
                                                            self.progress_bar)
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
321
713.2.5 by Jelmer Vernooij
Construct model early.
322
            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.
323
            self.graph_cell.columns_len = columns_len
324
            width = self.graph_cell.get_size(self.treeview)[2]
325
            if width > 500:
326
                width = 500
327
            self.graph_column.set_fixed_width(width)
328
            self.graph_column.set_max_width(width)
329
            self.index = index
330
            self.treeview.set_model(self.model)
331
332
            if not revision or revision == NULL_REVISION:
333
                self.treeview.set_cursor(0)
334
            else:
335
                self.set_revision(revision)
336
576.5.1 by Jelmer Vernooij
Disable the ability to click on tags that are not available in the current view.
337
            self.emit('refreshed')
475.2.1 by Chad MILLER
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
338
            return False
339
        finally:
511.5.6 by Jelmer Vernooij
Simplify progress bar code, use embedded progress bar inside viz window.
340
            self.progress_bar.finished()
304 by Daniel Schierbeck
Made forward/back buttons work again.
341
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
342
    def construct_treeview(self):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
343
        self.treeview = Gtk.TreeView()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
344
345
        self.treeview.set_rules_hint(True)
723.1.1 by Sergei Golubchik
interactive substring search in gannotate
346
        # combined revno/summary interactive search
347
        #
348
        # the row in a treemodel is considered "matched" if a REVNO *starts*
349
        # from the key (that is the key is found in a REVNO at the offset 0)
350
        # or if a MESSAGE *contains* the key anywhere (that is, the key is
351
        # found case insensitively in a MESSAGE at any offset)
352
        def search_equal_func(model, column, key, iter):
353
            return (model.get_value(iter, treemodel.REVNO).find(key) != 0
354
                and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
355
356
        self.treeview.set_search_equal_func(search_equal_func)
357
        self.treeview.set_enable_search(True)
724 by Jelmer Vernooij
Fix formatting, imports.
358
734.1.2 by Curtis Hovey
Removed import_pygtk because gi does not impicitly call Main(). Inlined checks for gtk availablility.
359
        set_tooltip(treemodel.MESSAGE)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
360
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
361
        self._prev_cursor_path = None
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
362
        self.treeview.connect("cursor-changed",
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
363
                self._on_selection_changed)
364
365
        self.treeview.connect("row-activated", 
366
                self._on_revision_activated)
367
368
        self.treeview.connect("button-release-event", 
369
                self._on_revision_selected)
370
371
        self.treeview.set_property('fixed-height-mode', True)
372
373
        self.treeview.show()
374
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
375
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
376
        cell.set_property("width-chars", 15)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
377
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
378
        self.revno_column = Gtk.TreeViewColumn("Revision No")
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
379
        self.revno_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
380
        self.revno_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
345 by Daniel Schierbeck
Made treeview columns instance variables.
381
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
382
        self.revno_column.pack_start(cell, True, True, 0)
345 by Daniel Schierbeck
Made treeview columns instance variables.
383
        self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
384
        self.treeview.append_column(self.revno_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
385
386
        self.graph_cell = CellRendererGraph()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
387
        self.graph_column = Gtk.TreeViewColumn()
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
388
        self.graph_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
389
        self.graph_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
390
        self.graph_column.pack_start(self.graph_cell, True, True, 0)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
391
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
423.5.1 by Ali Sabil
Added tags visualization in the graph
392
        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.
393
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
394
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
395
        self.treeview.append_column(self.graph_column)
396
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
397
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
398
        cell.set_property("width-chars", 65)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
399
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
400
        self.summary_column = Gtk.TreeViewColumn("Summary")
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
401
        self.summary_column.set_resizable(True)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
402
        self.summary_column.set_expand(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
403
        self.summary_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
404
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
405
        self.summary_column.pack_start(cell, True, True, 0)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
406
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
407
        self.treeview.append_column(self.summary_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
408
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
409
        cell = Gtk.CellRendererText()
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
410
        cell.set_property("width-chars", 15)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
411
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
412
        self.authors_column = Gtk.TreeViewColumn("Author(s)")
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
413
        self.authors_column.set_resizable(False)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
414
        self.authors_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
415
        self.authors_column.set_fixed_width(200)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
416
        self.authors_column.pack_start(cell, True, True, 0)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
417
        self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
418
        self.treeview.append_column(self.authors_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
419
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
420
        cell = Gtk.CellRendererText()
359 by Daniel Schierbeck
Simplified date format.
421
        cell.set_property("width-chars", 20)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
422
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
423
        self.date_column = Gtk.TreeViewColumn("Date")
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
424
        self.date_column.set_visible(False)
713.2.1 by Ximin Luo
Add option to use 'bzr viz' with a vertical layout.
425
        self.date_column.set_resizable(True)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
426
        self.date_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
496.2.1 by Daniel Schierbeck
Made the columns have more suitable sizes.
427
        self.date_column.set_fixed_width(130)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
428
        self.date_column.pack_start(cell, True, True, 0)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
429
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
430
        self.treeview.append_column(self.date_column)
724 by Jelmer Vernooij
Fix formatting, imports.
431
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
432
        return self.treeview
724 by Jelmer Vernooij
Fix formatting, imports.
433
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
434
    def _on_selection_changed(self, treeview):
303 by Daniel Schierbeck
Made basic signaling work.
435
        """callback for when the treeview changes."""
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
436
        (path, focus) = treeview.get_cursor()
531.7.4 by Scott Scriven
The 'vis' treeview was updating twice per cursor motion. Fixed.
437
        if (path is not None) and (path != self._prev_cursor_path):
438
            self._prev_cursor_path = path # avoid emitting twice per click
645.1.4 by Vincent Ladeuil
Fix refresh warnings and progress widget usage.
439
            self.path = path
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
440
            self.emit('revision-selected')
441
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
442
    def _on_revision_selected(self, widget, event):
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
443
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
444
        if event.button == 3:
523.3.1 by Jelmer Vernooij
Rename RevisionPopupMenu -> RevisionMenu.
445
            menu = RevisionMenu(self.branch.repository, 
312 by Daniel Schierbeck
Made right-clicking work again.
446
                [self.get_revision().revision_id],
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
447
                self.branch)
423.7.8 by Daniel Schierbeck
Made the revision popup menu correctly add tags.
448
            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.
449
            menu.popup(None, None, None, event.button, event.get_time())
450
451
    def _on_revision_activated(self, widget, path, col):
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
452
        self.emit('revision-activated', path, col)