/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: Gustav Hartvigsson
  • Date: 2014-11-25 15:34:07 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20141125153407-827k8g7qy9u5byd5
* Fixed bzr-gtk's viz util, using the new Gtk Inspector.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import time
18
18
 
19
19
from gi.repository import GObject
 
20
from gi.repository import Gdk
20
21
from gi.repository import Gtk
21
22
from gi.repository import Pango
22
23
import re
26
27
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
27
28
 
28
29
from bzrlib.plugins.gtk.annotate.colormap import AnnotateColorSaturation
 
30
from bzrlib.plugins.gtk.i18n import _i18n
29
31
from bzrlib.plugins.gtk.revisionview import RevisionView
30
32
from bzrlib.plugins.gtk.window import Window
31
33
 
48
50
        self.plain = plain
49
51
        self._branch = branch
50
52
 
51
 
        Window.__init__(self, parent)
 
53
        super(GAnnotateWindow, self).__init__(parent=parent)
52
54
 
53
 
        self.set_icon(self.render_icon(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
 
55
        self.set_icon(
 
56
            self.render_icon_pixbuf(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
54
57
        self.annotate_colormap = AnnotateColorSaturation()
55
58
 
56
59
        self._create()
127
130
        else:
128
131
            row = lineno - 1
129
132
 
130
 
        self.annoview.set_cursor(row)
131
 
        self.annoview.scroll_to_cell(row, use_align=True)
132
 
 
 
133
        tree_path = Gtk.TreePath(path=row)
 
134
        self.annoview.set_cursor(tree_path, None, False)
 
135
        self.annoview.scroll_to_cell(tree_path, use_align=True)
133
136
 
134
137
    def _annotate(self, tree, file_id):
135
138
        current_revision = FakeRevision(CURRENT_REVISION)
165
168
    def _highlight_annotation(self, model, path, iter, now):
166
169
        revision_id, = model.get(iter, REVISION_ID_COL)
167
170
        revision = self.revisions[revision_id]
168
 
        model.set(iter, HIGHLIGHT_COLOR_COL,
169
 
                  self.annotate_colormap.get_color(revision, now))
 
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)
170
174
 
171
175
    def _selected_revision(self):
172
176
        (path, col) = self.annoview.get_cursor()
191
195
        self.revisionview = self._create_log_view()
192
196
        self.annoview = self._create_annotate_view()
193
197
 
194
 
        vbox = Gtk.VBox(False)
 
198
        vbox = Gtk.VBox(homogeneous=False, spacing=0)
195
199
        vbox.show()
196
200
 
197
201
        sw = Gtk.ScrolledWindow()
205
209
        swbox.pack_start(sw, True, True, 0)
206
210
        swbox.show()
207
211
 
208
 
        hbox = Gtk.HBox(False, 6)
 
212
        hbox = Gtk.HBox(homogeneous=False, spacing=6)
209
213
        self.back_button = self._create_back_button()
210
 
        hbox.pack_start(self.back_button, expand=False, fill=True)
 
214
        hbox.pack_start(self.back_button, False, True, 0)
211
215
        self.forward_button = self._create_forward_button()
212
 
        hbox.pack_start(self.forward_button, expand=False, fill=True)
 
216
        hbox.pack_start(self.forward_button, False, True, 0)
213
217
        self.find_button = self._create_find_button()
214
 
        hbox.pack_start(self.find_button, expand=False, fill=True)
 
218
        hbox.pack_start(self.find_button, False, True, 0)
215
219
        self.goto_button = self._create_goto_button()
216
 
        hbox.pack_start(self.goto_button, expand=False, fill=True)
 
220
        hbox.pack_start(self.goto_button, False, True, 0)
217
221
        hbox.show()
218
 
        vbox.pack_start(hbox, expand=False, fill=True)
 
222
        vbox.pack_start(hbox, False, True, 0)
219
223
 
220
 
        self.pane = pane = Gtk.VPaned()
 
224
        self.pane = pane = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
221
225
        pane.add1(swbox)
222
226
        pane.add2(self.revisionview)
223
227
        pane.show()
224
 
        vbox.pack_start(pane, expand=True, fill=True)
 
228
        vbox.pack_start(pane, True, True, 0)
225
229
 
226
230
        self._search = SearchBox()
227
 
        swbox.pack_start(self._search, expand=False, fill=True)
 
231
        swbox.pack_start(self._search, False, True, 0)
228
232
        accels = Gtk.AccelGroup()
229
 
        accels.connect_group(Gdk.KEY_f, Gdk.EventMask.CONTROL_MASK,
230
 
                             Gtk.ACCEL_LOCKED,
 
233
        accels.connect(Gdk.KEY_f, Gdk.ModifierType.CONTROL_MASK,
 
234
                             Gtk.AccelFlags.LOCKED,
231
235
                             self._search_by_text)
232
 
        accels.connect_group(Gdk.KEY_g, Gdk.EventMask.CONTROL_MASK,
233
 
                             Gtk.ACCEL_LOCKED,
 
236
        accels.connect(Gdk.KEY_g, Gdk.ModifierType.CONTROL_MASK,
 
237
                             Gtk.AccelFlags.LOCKED,
234
238
                             self._search_by_line)
235
239
        self.add_accel_group(accels)
236
240
 
245
249
        self._search.set_target(self.annoview, LINE_NUM_COL)
246
250
 
247
251
    def line_diff(self, tv, path, tvc):
248
 
        row = path[0]
 
252
        row = path.get_indices()[0]
249
253
        revision = self.annotations[row]
250
254
        repository = self.branch.repository
251
255
        if revision.revision_id == CURRENT_REVISION:
275
279
        cell.set_property("xalign", 1.0)
276
280
        cell.set_property("ypad", 0)
277
281
        cell.set_property("family", "Monospace")
278
 
        cell.set_property("cell-background-gdk",
279
 
                          tv.get_style().bg[Gtk.StateType.NORMAL])
 
282
        cell.set_property(
 
283
            "cell-background-rgba",
 
284
            tv.get_style_context().get_background_color(Gtk.StateType.NORMAL))
280
285
        col = Gtk.TreeViewColumn()
281
286
        col.set_resizable(False)
282
 
        col.pack_start(cell, True, True, 0)
 
287
        col.pack_start(cell, True)
283
288
        col.add_attribute(cell, "text", LINE_NUM_COL)
284
289
        tv.append_column(col)
285
290
 
 
291
        style_context = self.get_style_context()
 
292
 
286
293
        cell = Gtk.CellRendererText()
287
294
        cell.set_property("ypad", 0)
288
295
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
289
 
        cell.set_property("cell-background-gdk",
290
 
                          self.get_style().bg[Gtk.StateType.NORMAL])
 
296
        cell.set_property(
 
297
            "cell-background-rgba",
 
298
            style_context.get_background_color(Gtk.StateType.NORMAL))
291
299
        col = Gtk.TreeViewColumn("Committer")
292
300
        col.set_resizable(True)
293
 
        col.pack_start(cell, True, True, 0)
 
301
        col.pack_start(cell, True)
294
302
        col.add_attribute(cell, "text", COMMITTER_COL)
295
303
        tv.append_column(col)
296
304
 
297
305
        cell = Gtk.CellRendererText()
298
306
        cell.set_property("xalign", 1.0)
299
307
        cell.set_property("ypad", 0)
300
 
        cell.set_property("cell-background-gdk",
301
 
                          self.get_style().bg[Gtk.StateType.NORMAL])
 
308
        cell.set_property(
 
309
            "cell-background-rgba",
 
310
            style_context.get_background_color(Gtk.StateType.NORMAL))
302
311
        col = Gtk.TreeViewColumn("Revno")
303
312
        col.set_resizable(False)
304
 
        col.pack_start(cell, True, True, 0)
 
313
        col.pack_start(cell, True)
305
314
        col.add_attribute(cell, "markup", REVNO_COL)
306
315
        tv.append_column(col)
307
316
 
310
319
        cell.set_property("family", "Monospace")
311
320
        col = Gtk.TreeViewColumn()
312
321
        col.set_resizable(False)
313
 
        col.pack_start(cell, True, True, 0)
 
322
        col.pack_start(cell, True)
314
323
#        col.add_attribute(cell, "foreground", HIGHLIGHT_COLOR_COL)
315
324
        col.add_attribute(cell, "background", HIGHLIGHT_COLOR_COL)
316
325
        col.add_attribute(cell, "text", TEXT_LINE_COL)
321
330
            return model.get_value(iter, TEXT_LINE_COL).lower().find(key.lower()) == -1
322
331
 
323
332
        tv.set_enable_search(True)
324
 
        tv.set_search_equal_func(search_equal_func)
 
333
        tv.set_search_equal_func(search_equal_func, None)
325
334
 
326
335
        return tv
327
336
 
394
403
        rev_id = self._selected_revision()
395
404
        if self.file_id in target_tree:
396
405
            offset = self.get_scroll_offset(target_tree)
397
 
            (row,), col = self.annoview.get_cursor()
 
406
            path, col = self.annoview.get_cursor()
 
407
            (row,) = path.get_indices()
398
408
            self.annotate(target_tree, self.branch, self.file_id)
399
409
            new_row = row+offset
400
410
            if new_row < 0:
401
411
                new_row = 0
402
 
            self.annoview.set_cursor(new_row)
 
412
            new_path = Gtk.TreePath(path=new_row)
 
413
            self.annoview.set_cursor(new_path, None, False)
403
414
            return True
404
415
        else:
405
416
            return False
407
418
    def get_scroll_offset(self, tree):
408
419
        old = self.tree.get_file(self.file_id)
409
420
        new = tree.get_file(self.file_id)
410
 
        (row,), col = self.annoview.get_cursor()
 
421
        path, col = self.annoview.get_cursor()
 
422
        (row,) = path.get_indices()
411
423
        matcher = patiencediff.PatienceSequenceMatcher(None, old.readlines(),
412
424
                                                       new.readlines())
413
425
        for i, j, n in matcher.get_matching_blocks():
450
462
            self.__cache[revision_id] = revision
451
463
        return self.__cache[revision_id]
452
464
 
 
465
 
453
466
class SearchBox(Gtk.HBox):
454
467
    """A button box for searching in text or lines of annotations"""
455
468
    def __init__(self):
456
 
        GObject.GObject.__init__(self, False, 6)
 
469
        super(SearchBox, self).__init__(homogeneous=False, spacing=6)
457
470
 
458
471
        # Close button
459
472
        button = Gtk.Button()
461
474
        image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
462
475
        button.set_image(image)
463
476
        button.set_relief(Gtk.ReliefStyle.NONE)
464
 
        button.connect("clicked", lambda w: self.hide_all())
465
 
        self.pack_start(button, expand=False, fill=False)
 
477
        button.connect("clicked", lambda w: self.hide())
 
478
        self.pack_start(button, False, False, 0)
466
479
 
467
480
        # Search entry
468
481
        label = Gtk.Label()
469
482
        self._label = label
470
 
        self.pack_start(label, expand=False, fill=False)
 
483
        self.pack_start(label, False, False, 0)
471
484
 
472
485
        entry = Gtk.Entry()
473
486
        self._entry = entry
474
487
        entry.connect("activate", lambda w, d: self._do_search(d),
475
488
                      'forward')
476
 
        self.pack_start(entry, expand=False, fill=False)
 
489
        self.pack_start(entry, False, False, 0)
477
490
 
478
491
        # Next/previous buttons
479
 
        button = Gtk.Button('_Next')
 
492
        button = Gtk.Button(_i18n('_Next'), use_underline=True)
480
493
        image = Gtk.Image()
481
494
        image.set_from_stock('gtk-go-forward', Gtk.IconSize.BUTTON)
482
495
        button.set_image(image)
483
496
        button.connect("clicked", lambda w, d: self._do_search(d),
484
497
                       'forward')
485
 
        self.pack_start(button, expand=False, fill=False)
 
498
        self.pack_start(button, False, False, 0)
486
499
 
487
 
        button = Gtk.Button('_Previous')
 
500
        button = Gtk.Button(_i18n('_Previous'), use_underline=True)
488
501
        image = Gtk.Image()
489
502
        image.set_from_stock('gtk-go-back', Gtk.IconSize.BUTTON)
490
503
        button.set_image(image)
491
504
        button.connect("clicked", lambda w, d: self._do_search(d),
492
505
                       'backward')
493
 
        self.pack_start(button, expand=False, fill=False)
 
506
        self.pack_start(button, False, False, 0)
494
507
 
495
508
        # Search options
496
509
        check = Gtk.CheckButton('Match case')
497
510
        self._match_case = check
498
 
        self.pack_start(check, expand=False, fill=False)
 
511
        self.pack_start(check, False, False, 0)
499
512
 
500
513
        check = Gtk.CheckButton('Regexp')
501
514
        check.connect("toggled", lambda w: self._set_label())
502
515
        self._regexp = check
503
 
        self.pack_start(check, expand=False, fill=False)
 
516
        self.pack_start(check, False, False, 0)
504
517
 
505
518
        self._view = None
506
519
        self._column = None
586
599
        for row in iterate(model, start):
587
600
            if self._match(model, row, self._column):
588
601
                path = model.get_path(row)
589
 
                self._view.set_cursor(path)
 
602
                self._view.set_cursor(path, None, False)
590
603
                self._view.scroll_to_cell(path, use_align=True)
591
604
                break