/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to branchview/treeview.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-18 11:53:18 UTC
  • mfrom: (452.5.2 viz-locks)
  • Revision ID: jelmer@samba.org-20110218115318-xgsxhn13fd3m6nj9
Add lock dialog. (Daniel Schierbeck)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
import pango
14
14
import re
15
15
import treemodel
 
16
from bzrlib import ui
16
17
 
17
18
from bzrlib.plugins.gtk import _i18n
 
19
from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
18
20
from linegraph import linegraph, same_branch
19
21
from graphcell import CellRendererGraph
20
22
from treemodel import TreeModel
21
23
from bzrlib.revision import NULL_REVISION
 
24
from bzrlib.plugins.gtk import lock
 
25
 
22
26
 
23
27
class TreeView(gtk.VBox):
24
28
 
82
86
    }
83
87
 
84
88
    __gsignals__ = {
85
 
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
86
 
                             gobject.TYPE_NONE,
87
 
                             ()),
88
89
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
89
90
                              gobject.TYPE_NONE,
90
91
                              ()),
93
94
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
94
95
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
95
96
                              gobject.TYPE_NONE,
96
 
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
 
97
                              (gobject.TYPE_STRING, gobject.TYPE_STRING)),
 
98
        'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
 
99
                              ())
97
100
    }
98
101
 
99
102
    def __init__(self, branch, start, maxnum, compact=True):
108
111
        """
109
112
        gtk.VBox.__init__(self, spacing=0)
110
113
 
111
 
        self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
112
 
        self.connect('revisions-loaded', 
113
 
                lambda x: self.loading_msg_box.hide())
 
114
        self.progress_widget = ProgressPanel()
 
115
        self.pack_start(self.progress_widget, expand=False, fill=True)
 
116
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
117
            # We'are using our own ui, let's tell it to use our widget.
 
118
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
114
119
 
115
120
        self.scrolled_window = gtk.ScrolledWindow()
116
121
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
120
125
        self.pack_start(self.scrolled_window, expand=True, fill=True)
121
126
 
122
127
        self.scrolled_window.add(self.construct_treeview())
123
 
        
124
128
 
125
 
        self.iter = None
 
129
        self.path = None
126
130
        self.branch = branch
127
131
        self.revision = None
 
132
        self.index = {}
128
133
 
129
134
        self.start = start
130
135
        self.maxnum = maxnum
132
137
 
133
138
        gobject.idle_add(self.populate)
134
139
 
135
 
        self.connect("destroy", lambda x: self.branch.unlock())
 
140
        self.connect("destroy", self._on_destroy)
 
141
 
 
142
    def _on_destroy(self, *ignored):
 
143
        self.branch.unlock()
 
144
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
145
            # We'are using our own ui, let's tell it to stop using our widget.
 
146
            ui.ui_factory.set_progress_bar_widget(None)
136
147
 
137
148
    def do_get_property(self, property):
138
149
        if property.name == 'revno-column-visible':
148
159
        elif property.name == 'branch':
149
160
            return self.branch
150
161
        elif property.name == 'revision':
151
 
            return self.model.get_value(self.iter, treemodel.REVISION)
 
162
            return self.model.get_value(self.model.get_iter(self.path),
 
163
                                        treemodel.REVISION)
152
164
        elif property.name == 'revision-number':
153
 
            return self.model.get_value(self.iter, treemodel.REVNO)
 
165
            return self.model.get_value(self.model.get_iter(self.path),
 
166
                                        treemodel.REVNO)
154
167
        elif property.name == 'children':
155
 
            return self.model.get_value(self.iter, treemodel.CHILDREN)
 
168
            return self.model.get_value(self.model.get_iter(self.path),
 
169
                                        treemodel.CHILDREN)
156
170
        elif property.name == 'parents':
157
 
            return self.model.get_value(self.iter, treemodel.PARENTS)
 
171
            return self.model.get_value(self.model.get_iter(self.path),
 
172
                                        treemodel.PARENTS)
158
173
        else:
159
174
            raise AttributeError, 'unknown property %s' % property.name
160
175
 
180
195
        """Return revision id of currently selected revision, or None."""
181
196
        return self.get_property('revision')
182
197
 
 
198
    def has_revision_id(self, revision_id):
 
199
        return (revision_id in self.index)
 
200
 
183
201
    def set_revision(self, revision):
184
202
        self.set_property('revision', revision)
185
203
 
208
226
    def add_tag(self, tag, revid=None):
209
227
        if revid is None: revid = self.revision.revision_id
210
228
 
211
 
        try:
212
 
            self.branch.unlock()
213
 
 
 
229
        if lock.release(self.branch):
214
230
            try:
215
 
                self.branch.lock_write()
 
231
                lock.acquire(self.branch, lock.WRITE)
216
232
                self.model.add_tag(tag, revid)
217
233
            finally:
218
 
                self.branch.unlock()
219
 
 
220
 
        finally:
221
 
            self.branch.lock_read()
222
 
 
223
 
        self.emit('tag-added', tag, revid)
 
234
                lock.release(self.branch)
 
235
 
 
236
            lock.acquire(self.branch, lock.READ)
 
237
 
 
238
            self.emit('tag-added', tag, revid)
224
239
        
225
240
    def refresh(self):
226
 
        self.loading_msg_box.show()
227
241
        gobject.idle_add(self.populate, self.get_revision())
228
242
 
229
243
    def update(self):
277
291
                       should be broken.
278
292
        """
279
293
 
280
 
        if self.compact:
281
 
            broken_line_length = 32
282
 
        else:
283
 
            broken_line_length = None
284
 
        
285
 
        show_graph = self.graph_column.get_visible()
286
 
 
287
 
        self.branch.lock_read()
288
 
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
289
 
                                                        (self.start,) , # Sequence of start revisions
290
 
                                                        self.maxnum, 
291
 
                                                        broken_line_length,
292
 
                                                        show_graph,
293
 
                                                        self.mainline_only)
294
 
 
295
 
        self.model = TreeModel(self.branch, linegraphdata)
296
 
        self.graph_cell.columns_len = columns_len
297
 
        width = self.graph_cell.get_size(self.treeview)[2]
298
 
        if width > 500:
299
 
            width = 500
300
 
        self.graph_column.set_fixed_width(width)
301
 
        self.graph_column.set_max_width(width)
302
 
        self.index = index
303
 
        self.treeview.set_model(self.model)
304
 
 
305
 
        if not revision or revision == NULL_REVISION:
306
 
            self.treeview.set_cursor(0)
307
 
        else:
308
 
            self.set_revision(revision)
309
 
 
310
 
        self.emit('revisions-loaded')
311
 
 
312
 
        return False
 
294
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
295
            # We'are using our own ui, let's tell it to use our widget.
 
296
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
 
297
        self.progress_bar = ui.ui_factory.nested_progress_bar()
 
298
        self.progress_bar.update("Loading ancestry graph", 0, 5)
 
299
 
 
300
        try:
 
301
            if self.compact:
 
302
                broken_line_length = 32
 
303
            else:
 
304
                broken_line_length = None
 
305
            
 
306
            show_graph = self.graph_column.get_visible()
 
307
 
 
308
            self.branch.lock_read()
 
309
            (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
 
310
                                                            self.start,
 
311
                                                            self.maxnum, 
 
312
                                                            broken_line_length,
 
313
                                                            show_graph,
 
314
                                                            self.mainline_only,
 
315
                                                            self.progress_bar)
 
316
 
 
317
            self.model = TreeModel(self.branch, linegraphdata)
 
318
            self.graph_cell.columns_len = columns_len
 
319
            width = self.graph_cell.get_size(self.treeview)[2]
 
320
            if width > 500:
 
321
                width = 500
 
322
            self.graph_column.set_fixed_width(width)
 
323
            self.graph_column.set_max_width(width)
 
324
            self.index = index
 
325
            self.treeview.set_model(self.model)
 
326
 
 
327
            if not revision or revision == NULL_REVISION:
 
328
                self.treeview.set_cursor(0)
 
329
            else:
 
330
                self.set_revision(revision)
 
331
 
 
332
            self.emit('refreshed')
 
333
            return False
 
334
        finally:
 
335
            self.progress_bar.finished()
313
336
 
314
337
    def construct_treeview(self):
315
338
        self.treeview = gtk.TreeView()
322
345
        if set_tooltip is not None:
323
346
            set_tooltip(treemodel.MESSAGE)
324
347
 
 
348
        self._prev_cursor_path = None
325
349
        self.treeview.connect("cursor-changed",
326
350
                self._on_selection_changed)
327
351
 
394
418
        
395
419
        return self.treeview
396
420
    
397
 
    def construct_loading_msg(self):
398
 
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
399
 
                                                 gtk.ICON_SIZE_BUTTON)
400
 
        image_loading.show()
401
 
        
402
 
        label_loading = gtk.Label(
403
 
            _i18n("Please wait, loading ancestral graph..."))
404
 
        label_loading.set_alignment(0.0, 0.5)
405
 
        label_loading.show()
406
 
        
407
 
        self.loading_msg_box = gtk.HBox()
408
 
        self.loading_msg_box.set_spacing(5)
409
 
        self.loading_msg_box.set_border_width(5)        
410
 
        self.loading_msg_box.pack_start(image_loading, False, False)
411
 
        self.loading_msg_box.pack_start(label_loading, True, True)
412
 
        self.loading_msg_box.show()
413
 
        
414
 
        return self.loading_msg_box
415
 
 
416
421
    def _on_selection_changed(self, treeview):
417
422
        """callback for when the treeview changes."""
418
423
        (path, focus) = treeview.get_cursor()
419
 
        if path is not None:
420
 
            self.iter = self.model.get_iter(path)
 
424
        if (path is not None) and (path != self._prev_cursor_path):
 
425
            self._prev_cursor_path = path # avoid emitting twice per click
 
426
            self.path = path
421
427
            self.emit('revision-selected')
422
428
 
423
429
    def _on_revision_selected(self, widget, event):
424
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
430
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
425
431
        if event.button == 3:
426
 
            menu = RevisionPopupMenu(self.branch.repository, 
 
432
            menu = RevisionMenu(self.branch.repository, 
427
433
                [self.get_revision().revision_id],
428
434
                self.branch)
429
435
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))