/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',
60
67
                                 False,
61
 
                                 gobject.PARAM_READWRITE)
 
68
                                 gobject.PARAM_READWRITE),
 
69
 
 
70
        'compact': (gobject.TYPE_BOOLEAN,
 
71
                    'Compact view',
 
72
                    'Break ancestry lines to save space',
 
73
                    True,
 
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),
62
81
 
63
82
    }
64
83
 
68
87
                             ()),
69
88
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
70
89
                              gobject.TYPE_NONE,
71
 
                              ())
 
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))
72
97
    }
73
98
 
74
 
    def __init__(self, branch, start, maxnum, broken_line_length=None):
 
99
    def __init__(self, branch, start, maxnum, compact=True):
75
100
        """Create a new TreeView.
76
101
 
77
102
        :param branch: Branch object for branch to show.
81
106
        :param broken_line_length: After how much lines to break 
82
107
                                   branches.
83
108
        """
84
 
        gtk.ScrolledWindow.__init__(self)
85
 
 
86
 
        self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
87
 
        self.set_shadow_type(gtk.SHADOW_IN)
88
 
 
89
 
        self.construct_treeview()
90
 
 
91
 
        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
92
126
        self.branch = branch
93
 
 
94
 
        gobject.idle_add(self.populate, start, maxnum, 
95
 
                         broken_line_length)
 
127
        self.revision = None
 
128
 
 
129
        self.start = start
 
130
        self.maxnum = maxnum
 
131
        self.compact = compact
 
132
 
 
133
        gobject.idle_add(self.populate)
96
134
 
97
135
        self.connect("destroy", lambda x: self.branch.unlock())
98
136
 
99
137
    def do_get_property(self, property):
100
138
        if property.name == 'revno-column-visible':
101
139
            return self.revno_column.get_visible()
 
140
        elif property.name == 'graph-column-visible':
 
141
            return self.graph_column.get_visible()
102
142
        elif property.name == 'date-column-visible':
103
143
            return self.date_column.get_visible()
 
144
        elif property.name == 'compact':
 
145
            return self.compact
 
146
        elif property.name == 'mainline-only':
 
147
            return self.mainline_only
104
148
        elif property.name == 'branch':
105
149
            return self.branch
106
150
        elif property.name == 'revision':
117
161
    def do_set_property(self, property, value):
118
162
        if property.name == 'revno-column-visible':
119
163
            self.revno_column.set_visible(value)
 
164
        elif property.name == 'graph-column-visible':
 
165
            self.graph_column.set_visible(value)
120
166
        elif property.name == 'date-column-visible':
121
167
            self.date_column.set_visible(value)
 
168
        elif property.name == 'compact':
 
169
            self.compact = value
 
170
        elif property.name == 'mainline-only':
 
171
            self.mainline_only = value
122
172
        elif property.name == 'branch':
123
173
            self.branch = value
124
174
        elif property.name == 'revision':
154
204
        :return: list of revision ids.
155
205
        """
156
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)
157
224
        
 
225
    def refresh(self):
 
226
        self.loading_msg_box.show()
 
227
        gobject.idle_add(self.populate, self.get_revision())
 
228
 
 
229
    def update(self):
 
230
        try:
 
231
            self.branch.unlock()
 
232
            try:
 
233
                self.branch.lock_write()
 
234
                self.branch.update()
 
235
            finally:
 
236
                self.branch.unlock()
 
237
        finally:
 
238
            self.branch.lock_read()
 
239
 
158
240
    def back(self):
159
241
        """Signal handler for the Back button."""
160
242
        parents = self.get_parents()
185
267
        else:
186
268
            self.set_revision_id(children[0])
187
269
 
188
 
    def populate(self, start, maxnum, broken_line_length=None):
 
270
    def populate(self, revision=None):
189
271
        """Fill the treeview with contents.
190
272
 
191
273
        :param start: Revision id of revision to start with.
194
276
        :param broken_line_length: After how much lines branches \
195
277
                       should be broken.
196
278
        """
 
279
 
 
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
 
197
287
        self.branch.lock_read()
198
288
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
199
 
                                                        start,
200
 
                                                        maxnum, 
201
 
                                                        broken_line_length)
 
289
                                                        self.start,
 
290
                                                        self.maxnum, 
 
291
                                                        broken_line_length,
 
292
                                                        show_graph,
 
293
                                                        self.mainline_only)
202
294
 
203
 
        self.model = TreeModel(self.branch.repository, linegraphdata)
 
295
        self.model = TreeModel(self.branch, linegraphdata)
204
296
        self.graph_cell.columns_len = columns_len
205
297
        width = self.graph_cell.get_size(self.treeview)[2]
 
298
        if width > 500:
 
299
            width = 500
206
300
        self.graph_column.set_fixed_width(width)
207
301
        self.graph_column.set_max_width(width)
208
302
        self.index = index
209
303
        self.treeview.set_model(self.model)
210
 
        self.treeview.set_cursor(0)
 
304
 
 
305
        if not revision or revision == NULL_REVISION:
 
306
            self.treeview.set_cursor(0)
 
307
        else:
 
308
            self.set_revision(revision)
 
309
 
211
310
        self.emit('revisions-loaded')
212
311
 
213
312
        return False
214
313
 
215
 
    def show_diff(self, revid=None, parentid=None):
216
 
        """Open a new window to show a diff between the given revisions."""
217
 
        from bzrlib.plugins.gtk.diff import DiffWindow
218
 
        window = DiffWindow(parent=self)
219
 
 
220
 
        parents = self.get_parents()
221
 
 
222
 
        if revid is None:
223
 
            revid = self.get_revision().revision_id
224
 
 
225
 
            if parentid is None and len(parents) > 0:
226
 
                parentid = parents[0]
227
 
 
228
 
        if parentid is None:
229
 
            parentid = NULL_REVISION
230
 
 
231
 
        rev_tree    = self.branch.repository.revision_tree(revid)
232
 
        parent_tree = self.branch.repository.revision_tree(parentid)
233
 
 
234
 
        description = revid + " - " + self.branch.nick
235
 
        window.set_diff(description, rev_tree, parent_tree)
236
 
        window.show()
237
 
 
238
314
    def construct_treeview(self):
239
315
        self.treeview = gtk.TreeView()
240
316
 
257
333
 
258
334
        self.treeview.set_property('fixed-height-mode', True)
259
335
 
260
 
        self.add(self.treeview)
261
336
        self.treeview.show()
262
337
 
263
338
        cell = gtk.CellRendererText()
277
352
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
278
353
        self.graph_column.pack_start(self.graph_cell, expand=False)
279
354
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
 
355
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
280
356
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
281
357
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
282
358
        self.treeview.append_column(self.graph_column)
284
360
        cell = gtk.CellRendererText()
285
361
        cell.set_property("width-chars", 65)
286
362
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
287
 
        self.msg_column = gtk.TreeViewColumn("Message")
288
 
        self.msg_column.set_resizable(True)
289
 
        self.msg_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
290
 
        self.msg_column.set_fixed_width(cell.get_size(self.treeview)[2])
291
 
        self.msg_column.pack_start(cell, expand=True)
292
 
        self.msg_column.add_attribute(cell, "text", treemodel.MESSAGE)
293
 
        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)
294
370
 
295
371
        cell = gtk.CellRendererText()
296
372
        cell.set_property("width-chars", 15)
300
376
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
301
377
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
302
378
        self.committer_column.pack_start(cell, expand=True)
303
 
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITER)
 
379
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
304
380
        self.treeview.append_column(self.committer_column)
305
381
 
306
382
        cell = gtk.CellRendererText()
314
390
        self.date_column.pack_start(cell, expand=True)
315
391
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
316
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
317
414
 
318
415
    def _on_selection_changed(self, treeview):
319
416
        """callback for when the treeview changes."""
328
425
            menu = RevisionPopupMenu(self.branch.repository, 
329
426
                [self.get_revision().revision_id],
330
427
                self.branch)
 
428
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
331
429
            menu.popup(None, None, None, event.button, event.get_time())
332
430
 
333
431
    def _on_revision_activated(self, widget, path, col):
334
 
        # TODO: more than one parent
335
 
        """Callback for when a treeview row gets activated."""
336
 
        revision_id = self.model[path][treemodel.REVID]
337
 
        parents = self.model[path][treemodel.PARENTS]
338
 
 
339
 
        if len(parents) == 0:
340
 
            parent_id = None
341
 
        else:
342
 
            parent_id = parents[0]
343
 
 
344
 
        self.show_diff(revision_id, parent_id)
345
 
        self.treeview.grab_focus()
 
432
        self.emit('revision-activated', path, col)