/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 annotate/gannotate.py

  • Committer: Curtis Hovey
  • Date: 2012-02-09 03:43:01 UTC
  • mto: This revision was merged to the branch mainline in revision 776.
  • Revision ID: sinzui.is@verizon.net-20120209034301-0uwkobbb0d64ugrw
Switched from Gtk.VPaned to Gtk.Paned.new(Gtk.Orientation.VERTICAL).

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import time
18
18
 
19
 
import pygtk
20
 
pygtk.require("2.0")
21
 
import gobject
22
 
import gtk
23
 
import pango
 
19
from gi.repository import GObject
 
20
from gi.repository import Gdk
 
21
from gi.repository import Gtk
 
22
from gi.repository import Pango
24
23
import re
25
24
 
26
25
from bzrlib import patiencediff
50
49
        self.plain = plain
51
50
        self._branch = branch
52
51
 
53
 
        Window.__init__(self, parent)
 
52
        super(GAnnotateWindow, self).__init__(parent=parent)
54
53
 
55
 
        self.set_icon(self.render_icon(gtk.STOCK_FIND, gtk.ICON_SIZE_BUTTON))
 
54
        self.set_icon(
 
55
            self.render_icon_pixbuf(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
56
56
        self.annotate_colormap = AnnotateColorSaturation()
57
57
 
58
58
        self._create()
70
70
                                   lambda: CURRENT_REVISION)()
71
71
 
72
72
        # [revision id, line number, author, revno, highlight color, line]
73
 
        self.annomodel = gtk.ListStore(gobject.TYPE_STRING,
74
 
                                       gobject.TYPE_INT,
75
 
                                       gobject.TYPE_STRING,
76
 
                                       gobject.TYPE_STRING,
77
 
                                       gobject.TYPE_STRING,
78
 
                                       gobject.TYPE_STRING)
 
73
        self.annomodel = Gtk.ListStore(GObject.TYPE_STRING,
 
74
                                       GObject.TYPE_INT,
 
75
                                       GObject.TYPE_STRING,
 
76
                                       GObject.TYPE_STRING,
 
77
                                       GObject.TYPE_STRING,
 
78
                                       GObject.TYPE_STRING)
79
79
 
80
80
        last_seen = None
81
81
        try:
129
129
        else:
130
130
            row = lineno - 1
131
131
 
132
 
        self.annoview.set_cursor(row)
133
 
        self.annoview.scroll_to_cell(row, use_align=True)
134
 
 
 
132
        tree_path = Gtk.TreePath(path=row)
 
133
        self.annoview.set_cursor(tree_path, None, False)
 
134
        self.annoview.scroll_to_cell(tree_path, use_align=True)
135
135
 
136
136
    def _annotate(self, tree, file_id):
137
137
        current_revision = FakeRevision(CURRENT_REVISION)
167
167
    def _highlight_annotation(self, model, path, iter, now):
168
168
        revision_id, = model.get(iter, REVISION_ID_COL)
169
169
        revision = self.revisions[revision_id]
170
 
        model.set(iter, HIGHLIGHT_COLOR_COL,
171
 
                  self.annotate_colormap.get_color(revision, now))
 
170
        # XXX sinzui 2011-08-12: What does get_color return?
 
171
        color = self.annotate_colormap.get_color(revision, now)
 
172
        model.set_value(iter, HIGHLIGHT_COLOR_COL, color)
172
173
 
173
174
    def _selected_revision(self):
174
175
        (path, col) = self.annoview.get_cursor()
193
194
        self.revisionview = self._create_log_view()
194
195
        self.annoview = self._create_annotate_view()
195
196
 
196
 
        vbox = gtk.VBox(False)
 
197
        vbox = Gtk.VBox(homogeneous=False, spacing=0)
197
198
        vbox.show()
198
199
 
199
 
        sw = gtk.ScrolledWindow()
200
 
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
201
 
        sw.set_shadow_type(gtk.SHADOW_IN)
 
200
        sw = Gtk.ScrolledWindow()
 
201
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
 
202
        sw.set_shadow_type(Gtk.ShadowType.IN)
202
203
        sw.add(self.annoview)
203
204
        self.annoview.gwindow = self
204
205
        sw.show()
205
206
 
206
 
        swbox = gtk.VBox()
207
 
        swbox.pack_start(sw)
 
207
        swbox = Gtk.VBox()
 
208
        swbox.pack_start(sw, True, True, 0)
208
209
        swbox.show()
209
210
 
210
 
        hbox = gtk.HBox(False, 6)
 
211
        hbox = Gtk.HBox(homogeneous=False, spacing=6)
211
212
        self.back_button = self._create_back_button()
212
 
        hbox.pack_start(self.back_button, expand=False, fill=True)
 
213
        hbox.pack_start(self.back_button, False, True, 0)
213
214
        self.forward_button = self._create_forward_button()
214
 
        hbox.pack_start(self.forward_button, expand=False, fill=True)
 
215
        hbox.pack_start(self.forward_button, False, True, 0)
215
216
        self.find_button = self._create_find_button()
216
 
        hbox.pack_start(self.find_button, expand=False, fill=True)
 
217
        hbox.pack_start(self.find_button, False, True, 0)
217
218
        self.goto_button = self._create_goto_button()
218
 
        hbox.pack_start(self.goto_button, expand=False, fill=True)
 
219
        hbox.pack_start(self.goto_button, False, True, 0)
219
220
        hbox.show()
220
 
        vbox.pack_start(hbox, expand=False, fill=True)
 
221
        vbox.pack_start(hbox, False, True, 0)
221
222
 
222
 
        self.pane = pane = gtk.VPaned()
 
223
        self.pane = pane = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
223
224
        pane.add1(swbox)
224
225
        pane.add2(self.revisionview)
225
226
        pane.show()
226
 
        vbox.pack_start(pane, expand=True, fill=True)
 
227
        vbox.pack_start(pane, True, True, 0)
227
228
 
228
229
        self._search = SearchBox()
229
 
        swbox.pack_start(self._search, expand=False, fill=True)
230
 
        accels = gtk.AccelGroup()
231
 
        accels.connect_group(gtk.keysyms.f, gtk.gdk.CONTROL_MASK,
232
 
                             gtk.ACCEL_LOCKED,
 
230
        swbox.pack_start(self._search, False, True, 0)
 
231
        accels = Gtk.AccelGroup()
 
232
        accels.connect(Gdk.KEY_f, Gdk.ModifierType.CONTROL_MASK,
 
233
                             Gtk.AccelFlags.LOCKED,
233
234
                             self._search_by_text)
234
 
        accels.connect_group(gtk.keysyms.g, gtk.gdk.CONTROL_MASK,
235
 
                             gtk.ACCEL_LOCKED,
 
235
        accels.connect(Gdk.KEY_g, Gdk.ModifierType.CONTROL_MASK,
 
236
                             Gtk.AccelFlags.LOCKED,
236
237
                             self._search_by_line)
237
238
        self.add_accel_group(accels)
238
239
 
247
248
        self._search.set_target(self.annoview, LINE_NUM_COL)
248
249
 
249
250
    def line_diff(self, tv, path, tvc):
250
 
        row = path[0]
 
251
        row = path.get_indices()[0]
251
252
        revision = self.annotations[row]
252
253
        repository = self.branch.repository
253
254
        if revision.revision_id == CURRENT_REVISION:
267
268
 
268
269
 
269
270
    def _create_annotate_view(self):
270
 
        tv = gtk.TreeView()
 
271
        tv = Gtk.TreeView()
271
272
        tv.set_rules_hint(False)
272
273
        tv.connect("cursor-changed", self._activate_selected_revision)
273
274
        tv.show()
274
275
        tv.connect("row-activated", self.line_diff)
275
276
 
276
 
        cell = gtk.CellRendererText()
 
277
        cell = Gtk.CellRendererText()
277
278
        cell.set_property("xalign", 1.0)
278
279
        cell.set_property("ypad", 0)
279
280
        cell.set_property("family", "Monospace")
280
281
        cell.set_property("cell-background-gdk",
281
 
                          tv.get_style().bg[gtk.STATE_NORMAL])
282
 
        col = gtk.TreeViewColumn()
 
282
                          tv.get_style().bg[Gtk.StateType.NORMAL])
 
283
        col = Gtk.TreeViewColumn()
283
284
        col.set_resizable(False)
284
 
        col.pack_start(cell, expand=True)
 
285
        col.pack_start(cell, True)
285
286
        col.add_attribute(cell, "text", LINE_NUM_COL)
286
287
        tv.append_column(col)
287
288
 
288
 
        cell = gtk.CellRendererText()
 
289
        cell = Gtk.CellRendererText()
289
290
        cell.set_property("ypad", 0)
290
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
291
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
291
292
        cell.set_property("cell-background-gdk",
292
 
                          self.get_style().bg[gtk.STATE_NORMAL])
293
 
        col = gtk.TreeViewColumn("Committer")
 
293
                          self.get_style().bg[Gtk.StateType.NORMAL])
 
294
        col = Gtk.TreeViewColumn("Committer")
294
295
        col.set_resizable(True)
295
 
        col.pack_start(cell, expand=True)
 
296
        col.pack_start(cell, True)
296
297
        col.add_attribute(cell, "text", COMMITTER_COL)
297
298
        tv.append_column(col)
298
299
 
299
 
        cell = gtk.CellRendererText()
 
300
        cell = Gtk.CellRendererText()
300
301
        cell.set_property("xalign", 1.0)
301
302
        cell.set_property("ypad", 0)
302
303
        cell.set_property("cell-background-gdk",
303
 
                          self.get_style().bg[gtk.STATE_NORMAL])
304
 
        col = gtk.TreeViewColumn("Revno")
 
304
                          self.get_style().bg[Gtk.StateType.NORMAL])
 
305
        col = Gtk.TreeViewColumn("Revno")
305
306
        col.set_resizable(False)
306
 
        col.pack_start(cell, expand=True)
 
307
        col.pack_start(cell, True)
307
308
        col.add_attribute(cell, "markup", REVNO_COL)
308
309
        tv.append_column(col)
309
310
 
310
 
        cell = gtk.CellRendererText()
 
311
        cell = Gtk.CellRendererText()
311
312
        cell.set_property("ypad", 0)
312
313
        cell.set_property("family", "Monospace")
313
 
        col = gtk.TreeViewColumn()
 
314
        col = Gtk.TreeViewColumn()
314
315
        col.set_resizable(False)
315
 
        col.pack_start(cell, expand=True)
 
316
        col.pack_start(cell, True)
316
317
#        col.add_attribute(cell, "foreground", HIGHLIGHT_COLOR_COL)
317
318
        col.add_attribute(cell, "background", HIGHLIGHT_COLOR_COL)
318
319
        col.add_attribute(cell, "text", TEXT_LINE_COL)
323
324
            return model.get_value(iter, TEXT_LINE_COL).lower().find(key.lower()) == -1
324
325
 
325
326
        tv.set_enable_search(True)
326
 
        tv.set_search_equal_func(search_equal_func)
 
327
        tv.set_search_equal_func(search_equal_func, None)
327
328
 
328
329
        return tv
329
330
 
333
334
        return lv
334
335
 
335
336
    def _create_back_button(self):
336
 
        button = gtk.Button()
 
337
        button = Gtk.Button()
337
338
        button.set_use_stock(True)
338
339
        button.set_label("gtk-go-back")
339
340
        button.connect("clicked", lambda w: self.go_back())
340
 
        button.set_relief(gtk.RELIEF_NONE)
 
341
        button.set_relief(Gtk.ReliefStyle.NONE)
341
342
        button.show()
342
343
        return button
343
344
 
344
345
    def _create_forward_button(self):
345
 
        button = gtk.Button()
 
346
        button = Gtk.Button()
346
347
        button.set_use_stock(True)
347
348
        button.set_label("gtk-go-forward")
348
349
        button.connect("clicked", lambda w: self.go_forward())
349
 
        button.set_relief(gtk.RELIEF_NONE)
 
350
        button.set_relief(Gtk.ReliefStyle.NONE)
350
351
        button.show()
351
352
        button.set_sensitive(False)
352
353
        return button
353
354
 
354
355
    def _create_find_button(self):
355
 
        button = gtk.Button()
 
356
        button = Gtk.Button()
356
357
        button.set_use_stock(True)
357
358
        button.set_label("gtk-find")
358
359
        button.set_tooltip_text("Search for text (Ctrl+F)")
359
360
        button.connect("clicked", self._search_by_text)
360
 
        button.set_relief(gtk.RELIEF_NONE)
 
361
        button.set_relief(Gtk.ReliefStyle.NONE)
361
362
        button.show()
362
363
        button.set_sensitive(True)
363
364
        return button
364
365
 
365
366
    def _create_goto_button(self):
366
 
        button = gtk.Button()
 
367
        button = Gtk.Button()
367
368
        button.set_label("Goto Line")
368
369
        button.set_tooltip_text("Scroll to a line by entering its number (Ctrl+G)")
369
370
        button.connect("clicked", self._search_by_line)
370
 
        button.set_relief(gtk.RELIEF_NONE)
 
371
        button.set_relief(Gtk.ReliefStyle.NONE)
371
372
        button.show()
372
373
        button.set_sensitive(True)
373
374
        return button
396
397
        rev_id = self._selected_revision()
397
398
        if self.file_id in target_tree:
398
399
            offset = self.get_scroll_offset(target_tree)
399
 
            (row,), col = self.annoview.get_cursor()
 
400
            path, col = self.annoview.get_cursor()
 
401
            (row,) = path.get_indices()
400
402
            self.annotate(target_tree, self.branch, self.file_id)
401
403
            new_row = row+offset
402
404
            if new_row < 0:
403
405
                new_row = 0
404
 
            self.annoview.set_cursor(new_row)
 
406
            new_path = Gtk.TreePath(path=new_row)
 
407
            self.annoview.set_cursor(new_path, None, False)
405
408
            return True
406
409
        else:
407
410
            return False
409
412
    def get_scroll_offset(self, tree):
410
413
        old = self.tree.get_file(self.file_id)
411
414
        new = tree.get_file(self.file_id)
412
 
        (row,), col = self.annoview.get_cursor()
 
415
        path, col = self.annoview.get_cursor()
 
416
        (row,) = path.get_indices()
413
417
        matcher = patiencediff.PatienceSequenceMatcher(None, old.readlines(),
414
418
                                                       new.readlines())
415
419
        for i, j, n in matcher.get_matching_blocks():
452
456
            self.__cache[revision_id] = revision
453
457
        return self.__cache[revision_id]
454
458
 
455
 
class SearchBox(gtk.HBox):
 
459
 
 
460
class SearchBox(Gtk.HBox):
456
461
    """A button box for searching in text or lines of annotations"""
457
462
    def __init__(self):
458
 
        gtk.HBox.__init__(self, False, 6)
 
463
        super(SearchBox, self).__init__(homogeneous=False, spacing=6)
459
464
 
460
465
        # Close button
461
 
        button = gtk.Button()
462
 
        image = gtk.Image()
463
 
        image.set_from_stock('gtk-stop', gtk.ICON_SIZE_BUTTON)
 
466
        button = Gtk.Button()
 
467
        image = Gtk.Image()
 
468
        image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
464
469
        button.set_image(image)
465
 
        button.set_relief(gtk.RELIEF_NONE)
466
 
        button.connect("clicked", lambda w: self.hide_all())
467
 
        self.pack_start(button, expand=False, fill=False)
 
470
        button.set_relief(Gtk.ReliefStyle.NONE)
 
471
        button.connect("clicked", lambda w: self.hide())
 
472
        self.pack_start(button, False, False, 0)
468
473
 
469
474
        # Search entry
470
 
        label = gtk.Label()
 
475
        label = Gtk.Label()
471
476
        self._label = label
472
 
        self.pack_start(label, expand=False, fill=False)
 
477
        self.pack_start(label, False, False, 0)
473
478
 
474
 
        entry = gtk.Entry()
 
479
        entry = Gtk.Entry()
475
480
        self._entry = entry
476
481
        entry.connect("activate", lambda w, d: self._do_search(d),
477
482
                      'forward')
478
 
        self.pack_start(entry, expand=False, fill=False)
 
483
        self.pack_start(entry, False, False, 0)
479
484
 
480
485
        # Next/previous buttons
481
 
        button = gtk.Button('_Next')
482
 
        image = gtk.Image()
483
 
        image.set_from_stock('gtk-go-forward', gtk.ICON_SIZE_BUTTON)
 
486
        button = Gtk.Button('_Next')
 
487
        image = Gtk.Image()
 
488
        image.set_from_stock('gtk-go-forward', Gtk.IconSize.BUTTON)
484
489
        button.set_image(image)
485
490
        button.connect("clicked", lambda w, d: self._do_search(d),
486
491
                       'forward')
487
 
        self.pack_start(button, expand=False, fill=False)
 
492
        self.pack_start(button, False, False, 0)
488
493
 
489
 
        button = gtk.Button('_Previous')
490
 
        image = gtk.Image()
491
 
        image.set_from_stock('gtk-go-back', gtk.ICON_SIZE_BUTTON)
 
494
        button = Gtk.Button('_Previous')
 
495
        image = Gtk.Image()
 
496
        image.set_from_stock('gtk-go-back', Gtk.IconSize.BUTTON)
492
497
        button.set_image(image)
493
498
        button.connect("clicked", lambda w, d: self._do_search(d),
494
499
                       'backward')
495
 
        self.pack_start(button, expand=False, fill=False)
 
500
        self.pack_start(button, False, False, 0)
496
501
 
497
502
        # Search options
498
 
        check = gtk.CheckButton('Match case')
 
503
        check = Gtk.CheckButton('Match case')
499
504
        self._match_case = check
500
 
        self.pack_start(check, expand=False, fill=False)
 
505
        self.pack_start(check, False, False, 0)
501
506
 
502
 
        check = gtk.CheckButton('Regexp')
 
507
        check = Gtk.CheckButton('Regexp')
503
508
        check.connect("toggled", lambda w: self._set_label())
504
509
        self._regexp = check
505
 
        self.pack_start(check, expand=False, fill=False)
 
510
        self.pack_start(check, False, False, 0)
506
511
 
507
512
        self._view = None
508
513
        self._column = None
588
593
        for row in iterate(model, start):
589
594
            if self._match(model, row, self._column):
590
595
                path = model.get_path(row)
591
 
                self._view.set_cursor(path)
 
596
                self._view.set_cursor(path, None, False)
592
597
                self._view.scroll_to_cell(path, use_align=True)
593
598
                break