/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: 2011-08-12 20:25:28 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110812202528-4xf4a2t23urx50d2
Updated gst to gtk3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
28
28
 
29
29
from bzrlib.plugins.gtk.annotate.colormap import AnnotateColorSaturation
30
 
from bzrlib.plugins.gtk.i18n import _i18n
31
30
from bzrlib.plugins.gtk.revisionview import RevisionView
32
31
from bzrlib.plugins.gtk.window import Window
33
32
 
50
49
        self.plain = plain
51
50
        self._branch = branch
52
51
 
53
 
        super(GAnnotateWindow, self).__init__(parent=parent)
 
52
        Window.__init__(self, parent)
54
53
 
55
54
        self.set_icon(
56
55
            self.render_icon_pixbuf(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
130
129
        else:
131
130
            row = lineno - 1
132
131
 
133
 
        tree_path = Gtk.TreePath(path=row)
134
 
        self.annoview.set_cursor(tree_path, None, False)
 
132
        tree_path = Gtk.TreePath.new_from_string(str(row))
 
133
        self.annoview.set_cursor(tree_path, None, None)
135
134
        self.annoview.scroll_to_cell(tree_path, use_align=True)
136
135
 
 
136
 
137
137
    def _annotate(self, tree, file_id):
138
138
        current_revision = FakeRevision(CURRENT_REVISION)
139
139
        current_revision.committer = self.branch.get_config().username()
168
168
    def _highlight_annotation(self, model, path, iter, now):
169
169
        revision_id, = model.get(iter, REVISION_ID_COL)
170
170
        revision = self.revisions[revision_id]
171
 
        # XXX sinzui 2011-08-12: What does get_color return?
172
 
        color = self.annotate_colormap.get_color(revision, now)
173
 
        model.set_value(iter, HIGHLIGHT_COLOR_COL, color)
 
171
        model.set(iter, HIGHLIGHT_COLOR_COL,
 
172
                  self.annotate_colormap.get_color(revision, now))
174
173
 
175
174
    def _selected_revision(self):
176
175
        (path, col) = self.annoview.get_cursor()
221
220
        hbox.show()
222
221
        vbox.pack_start(hbox, False, True, 0)
223
222
 
224
 
        self.pane = pane = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
 
223
        self.pane = pane = Gtk.VPaned()
225
224
        pane.add1(swbox)
226
225
        pane.add2(self.revisionview)
227
226
        pane.show()
249
248
        self._search.set_target(self.annoview, LINE_NUM_COL)
250
249
 
251
250
    def line_diff(self, tv, path, tvc):
252
 
        row = path.get_indices()[0]
 
251
        row = path[0]
253
252
        revision = self.annotations[row]
254
253
        repository = self.branch.repository
255
254
        if revision.revision_id == CURRENT_REVISION:
279
278
        cell.set_property("xalign", 1.0)
280
279
        cell.set_property("ypad", 0)
281
280
        cell.set_property("family", "Monospace")
282
 
        cell.set_property(
283
 
            "cell-background-rgba",
284
 
            tv.get_style_context().get_background_color(Gtk.StateType.NORMAL))
 
281
        cell.set_property("cell-background-gdk",
 
282
                          tv.get_style().bg[Gtk.StateType.NORMAL])
285
283
        col = Gtk.TreeViewColumn()
286
284
        col.set_resizable(False)
287
285
        col.pack_start(cell, True)
288
286
        col.add_attribute(cell, "text", LINE_NUM_COL)
289
287
        tv.append_column(col)
290
288
 
291
 
        style_context = self.get_style_context()
292
 
 
293
289
        cell = Gtk.CellRendererText()
294
290
        cell.set_property("ypad", 0)
295
291
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
296
 
        cell.set_property(
297
 
            "cell-background-rgba",
298
 
            style_context.get_background_color(Gtk.StateType.NORMAL))
 
292
        cell.set_property("cell-background-gdk",
 
293
                          self.get_style().bg[Gtk.StateType.NORMAL])
299
294
        col = Gtk.TreeViewColumn("Committer")
300
295
        col.set_resizable(True)
301
296
        col.pack_start(cell, True)
305
300
        cell = Gtk.CellRendererText()
306
301
        cell.set_property("xalign", 1.0)
307
302
        cell.set_property("ypad", 0)
308
 
        cell.set_property(
309
 
            "cell-background-rgba",
310
 
            style_context.get_background_color(Gtk.StateType.NORMAL))
 
303
        cell.set_property("cell-background-gdk",
 
304
                          self.get_style().bg[Gtk.StateType.NORMAL])
311
305
        col = Gtk.TreeViewColumn("Revno")
312
306
        col.set_resizable(False)
313
307
        col.pack_start(cell, True)
403
397
        rev_id = self._selected_revision()
404
398
        if self.file_id in target_tree:
405
399
            offset = self.get_scroll_offset(target_tree)
406
 
            path, col = self.annoview.get_cursor()
407
 
            (row,) = path.get_indices()
 
400
            (row,), col = self.annoview.get_cursor()
408
401
            self.annotate(target_tree, self.branch, self.file_id)
409
402
            new_row = row+offset
410
403
            if new_row < 0:
411
404
                new_row = 0
412
 
            new_path = Gtk.TreePath(path=new_row)
413
 
            self.annoview.set_cursor(new_path, None, False)
 
405
            self.annoview.set_cursor(new_row)
414
406
            return True
415
407
        else:
416
408
            return False
418
410
    def get_scroll_offset(self, tree):
419
411
        old = self.tree.get_file(self.file_id)
420
412
        new = tree.get_file(self.file_id)
421
 
        path, col = self.annoview.get_cursor()
422
 
        (row,) = path.get_indices()
 
413
        (row,), col = self.annoview.get_cursor()
423
414
        matcher = patiencediff.PatienceSequenceMatcher(None, old.readlines(),
424
415
                                                       new.readlines())
425
416
        for i, j, n in matcher.get_matching_blocks():
462
453
            self.__cache[revision_id] = revision
463
454
        return self.__cache[revision_id]
464
455
 
465
 
 
466
456
class SearchBox(Gtk.HBox):
467
457
    """A button box for searching in text or lines of annotations"""
468
458
    def __init__(self):
469
 
        super(SearchBox, self).__init__(homogeneous=False, spacing=6)
 
459
        Gtk.HBox.__init__(self, homogeneous=False, spacing=6)
470
460
 
471
461
        # Close button
472
462
        button = Gtk.Button()
474
464
        image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
475
465
        button.set_image(image)
476
466
        button.set_relief(Gtk.ReliefStyle.NONE)
477
 
        button.connect("clicked", lambda w: self.hide())
 
467
        button.connect("clicked", lambda w: self.hide_all())
478
468
        self.pack_start(button, False, False, 0)
479
469
 
480
470
        # Search entry
489
479
        self.pack_start(entry, False, False, 0)
490
480
 
491
481
        # Next/previous buttons
492
 
        button = Gtk.Button(_i18n('_Next'), use_underline=True)
 
482
        button = Gtk.Button('_Next')
493
483
        image = Gtk.Image()
494
484
        image.set_from_stock('gtk-go-forward', Gtk.IconSize.BUTTON)
495
485
        button.set_image(image)
497
487
                       'forward')
498
488
        self.pack_start(button, False, False, 0)
499
489
 
500
 
        button = Gtk.Button(_i18n('_Previous'), use_underline=True)
 
490
        button = Gtk.Button('_Previous')
501
491
        image = Gtk.Image()
502
492
        image.set_from_stock('gtk-go-back', Gtk.IconSize.BUTTON)
503
493
        button.set_image(image)
599
589
        for row in iterate(model, start):
600
590
            if self._match(model, row, self._column):
601
591
                path = model.get_path(row)
602
 
                self._view.set_cursor(path, None, False)
 
592
                self._view.set_cursor(path)
603
593
                self._view.scroll_to_cell(path, use_align=True)
604
594
                break