/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: Vincent Ladeuil
  • Date: 2008-05-05 18:16:46 UTC
  • mto: (487.1.1 gtk)
  • mto: This revision was merged to the branch mainline in revision 490.
  • Revision ID: v.ladeuil+lp@free.fr-20080505181646-n95l8ltw2u6jtr26
Fix bug #187283 fix replacing _() by _i18n().

* genpot.sh 
Remove duplication. Add the ability to specify the genrated pot
file on command-line for debugging purposes.

* po/olive-gtk.pot:
Regenerated.

* __init__.py, branch.py, branchview/treeview.py, checkout.py,
commit.py, conflicts.py, diff.py, errors.py, initialize.py,
merge.py, nautilus-bzr.py, olive/__init__.py, olive/add.py,
olive/bookmark.py, olive/guifiles.py, olive/info.py,
olive/menu.py, olive/mkdir.py, olive/move.py, olive/remove.py,
olive/rename.py, push.py, revbrowser.py, status.py, tags.py:
Replace all calls to _() by calls to _i18n(), the latter being
defined in __init__.py and imported in the other modules from
there. This fix the problem encountered countless times when
running bzr selftest and getting silly error messages about
boolean not being callables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import re
15
15
import treemodel
16
16
 
 
17
from bzrlib.plugins.gtk import _i18n
17
18
from linegraph import linegraph, same_branch
18
19
from graphcell import CellRendererGraph
19
20
from treemodel import TreeModel
20
21
from bzrlib.revision import NULL_REVISION
21
22
 
22
 
class TreeView(gtk.ScrolledWindow):
 
23
class TreeView(gtk.VBox):
23
24
 
24
25
    __gproperties__ = {
25
26
        'branch': (gobject.TYPE_PYOBJECT,
49
50
                    gobject.PARAM_READABLE),
50
51
 
51
52
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
52
 
                                 'Revision number',
 
53
                                 'Revision number column',
53
54
                                 'Show revision number column',
54
55
                                 True,
55
56
                                 gobject.PARAM_READWRITE),
56
57
 
 
58
        'graph-column-visible': (gobject.TYPE_BOOLEAN,
 
59
                                 'Graph column',
 
60
                                 'Show graph column',
 
61
                                 True,
 
62
                                 gobject.PARAM_READWRITE),
 
63
 
57
64
        'date-column-visible': (gobject.TYPE_BOOLEAN,
58
65
                                 'Date',
59
66
                                 'Show date column',
64
71
                    'Compact view',
65
72
                    'Break ancestry lines to save space',
66
73
                    True,
67
 
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE)
 
74
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
 
75
 
 
76
        'mainline-only': (gobject.TYPE_BOOLEAN,
 
77
                    'Mainline only',
 
78
                    'Only show the mainline history.',
 
79
                    False,
 
80
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
68
81
 
69
82
    }
70
83
 
74
87
                             ()),
75
88
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
76
89
                              gobject.TYPE_NONE,
77
 
                              ())
 
90
                              ()),
 
91
        'revision-activated': (gobject.SIGNAL_RUN_FIRST,
 
92
                              gobject.TYPE_NONE,
 
93
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
 
94
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
 
95
                              gobject.TYPE_NONE,
 
96
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
78
97
    }
79
98
 
80
99
    def __init__(self, branch, start, maxnum, compact=True):
87
106
        :param broken_line_length: After how much lines to break 
88
107
                                   branches.
89
108
        """
90
 
        gtk.ScrolledWindow.__init__(self)
91
 
 
92
 
        self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
93
 
        self.set_shadow_type(gtk.SHADOW_IN)
94
 
 
95
 
        self.construct_treeview()
96
 
 
97
 
        self.iter   = None
 
109
        gtk.VBox.__init__(self, spacing=0)
 
110
 
 
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
 
 
115
        self.scrolled_window = gtk.ScrolledWindow()
 
116
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
 
117
                                        gtk.POLICY_AUTOMATIC)
 
118
        self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
 
119
        self.scrolled_window.show()
 
120
        self.pack_start(self.scrolled_window, expand=True, fill=True)
 
121
 
 
122
        self.scrolled_window.add(self.construct_treeview())
 
123
        
 
124
 
 
125
        self.iter = None
98
126
        self.branch = branch
 
127
        self.revision = None
99
128
 
100
129
        self.start = start
101
130
        self.maxnum = maxnum
108
137
    def do_get_property(self, property):
109
138
        if property.name == 'revno-column-visible':
110
139
            return self.revno_column.get_visible()
 
140
        elif property.name == 'graph-column-visible':
 
141
            return self.graph_column.get_visible()
111
142
        elif property.name == 'date-column-visible':
112
143
            return self.date_column.get_visible()
113
144
        elif property.name == 'compact':
114
145
            return self.compact
 
146
        elif property.name == 'mainline-only':
 
147
            return self.mainline_only
115
148
        elif property.name == 'branch':
116
149
            return self.branch
117
150
        elif property.name == 'revision':
128
161
    def do_set_property(self, property, value):
129
162
        if property.name == 'revno-column-visible':
130
163
            self.revno_column.set_visible(value)
 
164
        elif property.name == 'graph-column-visible':
 
165
            self.graph_column.set_visible(value)
131
166
        elif property.name == 'date-column-visible':
132
167
            self.date_column.set_visible(value)
133
168
        elif property.name == 'compact':
134
169
            self.compact = value
 
170
        elif property.name == 'mainline-only':
 
171
            self.mainline_only = value
135
172
        elif property.name == 'branch':
136
173
            self.branch = value
137
174
        elif property.name == 'revision':
167
204
        :return: list of revision ids.
168
205
        """
169
206
        return self.get_property('parents')
 
207
 
 
208
    def add_tag(self, tag, revid=None):
 
209
        if revid is None: revid = self.revision.revision_id
 
210
 
 
211
        try:
 
212
            self.branch.unlock()
 
213
 
 
214
            try:
 
215
                self.branch.lock_write()
 
216
                self.model.add_tag(tag, revid)
 
217
            finally:
 
218
                self.branch.unlock()
 
219
 
 
220
        finally:
 
221
            self.branch.lock_read()
 
222
 
 
223
        self.emit('tag-added', tag, revid)
170
224
        
171
225
    def refresh(self):
 
226
        self.loading_msg_box.show()
172
227
        gobject.idle_add(self.populate, self.get_revision())
173
228
 
174
229
    def update(self):
226
281
            broken_line_length = 32
227
282
        else:
228
283
            broken_line_length = None
 
284
        
 
285
        show_graph = self.graph_column.get_visible()
229
286
 
230
287
        self.branch.lock_read()
231
288
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
232
289
                                                        self.start,
233
290
                                                        self.maxnum, 
234
 
                                                        broken_line_length)
 
291
                                                        broken_line_length,
 
292
                                                        show_graph,
 
293
                                                        self.mainline_only)
235
294
 
236
 
        self.model = TreeModel(self.branch.repository, linegraphdata)
 
295
        self.model = TreeModel(self.branch, linegraphdata)
237
296
        self.graph_cell.columns_len = columns_len
238
297
        width = self.graph_cell.get_size(self.treeview)[2]
239
298
        if width > 500:
243
302
        self.index = index
244
303
        self.treeview.set_model(self.model)
245
304
 
246
 
        if revision is None:
 
305
        if not revision or revision == NULL_REVISION:
247
306
            self.treeview.set_cursor(0)
248
307
        else:
249
308
            self.set_revision(revision)
252
311
 
253
312
        return False
254
313
 
255
 
    def show_diff(self, revid=None, parentid=None):
256
 
        """Open a new window to show a diff between the given revisions."""
257
 
        from bzrlib.plugins.gtk.diff import DiffWindow
258
 
        window = DiffWindow(parent=self)
259
 
 
260
 
        parents = self.get_parents()
261
 
 
262
 
        if revid is None:
263
 
            revid = self.get_revision().revision_id
264
 
 
265
 
            if parentid is None and len(parents) > 0:
266
 
                parentid = parents[0]
267
 
 
268
 
        if parentid is None:
269
 
            parentid = NULL_REVISION
270
 
 
271
 
        rev_tree    = self.branch.repository.revision_tree(revid)
272
 
        parent_tree = self.branch.repository.revision_tree(parentid)
273
 
 
274
 
        description = revid + " - " + self.branch.nick
275
 
        window.set_diff(description, rev_tree, parent_tree)
276
 
        window.show()
277
 
 
278
314
    def construct_treeview(self):
279
315
        self.treeview = gtk.TreeView()
280
316
 
297
333
 
298
334
        self.treeview.set_property('fixed-height-mode', True)
299
335
 
300
 
        self.add(self.treeview)
301
336
        self.treeview.show()
302
337
 
303
338
        cell = gtk.CellRendererText()
317
352
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
318
353
        self.graph_column.pack_start(self.graph_cell, expand=False)
319
354
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
 
355
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
320
356
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
321
357
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
322
358
        self.treeview.append_column(self.graph_column)
324
360
        cell = gtk.CellRendererText()
325
361
        cell.set_property("width-chars", 65)
326
362
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
327
 
        self.msg_column = gtk.TreeViewColumn("Message")
328
 
        self.msg_column.set_resizable(True)
329
 
        self.msg_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
330
 
        self.msg_column.set_fixed_width(cell.get_size(self.treeview)[2])
331
 
        self.msg_column.pack_start(cell, expand=True)
332
 
        self.msg_column.add_attribute(cell, "text", treemodel.MESSAGE)
333
 
        self.treeview.append_column(self.msg_column)
 
363
        self.summary_column = gtk.TreeViewColumn("Summary")
 
364
        self.summary_column.set_resizable(True)
 
365
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
366
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
 
367
        self.summary_column.pack_start(cell, expand=True)
 
368
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
 
369
        self.treeview.append_column(self.summary_column)
334
370
 
335
371
        cell = gtk.CellRendererText()
336
372
        cell.set_property("width-chars", 15)
340
376
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
341
377
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
342
378
        self.committer_column.pack_start(cell, expand=True)
343
 
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITER)
 
379
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
344
380
        self.treeview.append_column(self.committer_column)
345
381
 
346
382
        cell = gtk.CellRendererText()
354
390
        self.date_column.pack_start(cell, expand=True)
355
391
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
356
392
        self.treeview.append_column(self.date_column)
 
393
        
 
394
        return self.treeview
 
395
    
 
396
    def construct_loading_msg(self):
 
397
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
398
                                                 gtk.ICON_SIZE_BUTTON)
 
399
        image_loading.show()
 
400
        
 
401
        label_loading = gtk.Label(
 
402
            _i18n("Please wait, loading ancestral graph..."))
 
403
        label_loading.set_alignment(0.0, 0.5)
 
404
        label_loading.show()
 
405
        
 
406
        self.loading_msg_box = gtk.HBox()
 
407
        self.loading_msg_box.set_spacing(5)
 
408
        self.loading_msg_box.set_border_width(5)        
 
409
        self.loading_msg_box.pack_start(image_loading, False, False)
 
410
        self.loading_msg_box.pack_start(label_loading, True, True)
 
411
        self.loading_msg_box.show()
 
412
        
 
413
        return self.loading_msg_box
357
414
 
358
415
    def _on_selection_changed(self, treeview):
359
416
        """callback for when the treeview changes."""
368
425
            menu = RevisionPopupMenu(self.branch.repository, 
369
426
                [self.get_revision().revision_id],
370
427
                self.branch)
 
428
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
371
429
            menu.popup(None, None, None, event.button, event.get_time())
372
430
 
373
431
    def _on_revision_activated(self, widget, path, col):
374
 
        # TODO: more than one parent
375
 
        """Callback for when a treeview row gets activated."""
376
 
        revision_id = self.model[path][treemodel.REVID]
377
 
        parents = self.model[path][treemodel.PARENTS]
378
 
 
379
 
        if len(parents) == 0:
380
 
            parent_id = None
381
 
        else:
382
 
            parent_id = parents[0]
383
 
 
384
 
        self.show_diff(revision_id, parent_id)
385
 
        self.treeview.grab_focus()
 
432
        self.emit('revision-activated', path, col)