/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: Jelmer Vernooij
  • Date: 2011-04-10 18:44:39 UTC
  • mto: This revision was merged to the branch mainline in revision 730.
  • Revision ID: jelmer@samba.org-20110410184439-g7hqaacexqtviq13
Move i18n support to a separate file, so gettext files aren't loaded unless bzr-gtk is used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import time
18
18
 
19
 
from gi.repository import GObject
20
 
from gi.repository import Gtk
21
 
from gi.repository import Pango
 
19
import pygtk
 
20
pygtk.require("2.0")
 
21
import gobject
 
22
import gtk
 
23
import pango
22
24
import re
23
25
 
24
26
from bzrlib import patiencediff
50
52
 
51
53
        Window.__init__(self, parent)
52
54
 
53
 
        self.set_icon(self.render_icon(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
 
55
        self.set_icon(self.render_icon(gtk.STOCK_FIND, gtk.ICON_SIZE_BUTTON))
54
56
        self.annotate_colormap = AnnotateColorSaturation()
55
57
 
56
58
        self._create()
68
70
                                   lambda: CURRENT_REVISION)()
69
71
 
70
72
        # [revision id, line number, author, revno, highlight color, line]
71
 
        self.annomodel = Gtk.ListStore(GObject.TYPE_STRING,
72
 
                                       GObject.TYPE_INT,
73
 
                                       GObject.TYPE_STRING,
74
 
                                       GObject.TYPE_STRING,
75
 
                                       GObject.TYPE_STRING,
76
 
                                       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)
77
79
 
78
80
        last_seen = None
79
81
        try:
191
193
        self.revisionview = self._create_log_view()
192
194
        self.annoview = self._create_annotate_view()
193
195
 
194
 
        vbox = Gtk.VBox(False)
 
196
        vbox = gtk.VBox(False)
195
197
        vbox.show()
196
198
 
197
 
        sw = Gtk.ScrolledWindow()
198
 
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
199
 
        sw.set_shadow_type(Gtk.ShadowType.IN)
 
199
        sw = gtk.ScrolledWindow()
 
200
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
 
201
        sw.set_shadow_type(gtk.SHADOW_IN)
200
202
        sw.add(self.annoview)
201
203
        self.annoview.gwindow = self
202
204
        sw.show()
203
205
 
204
 
        swbox = Gtk.VBox()
205
 
        swbox.pack_start(sw, True, True, 0)
 
206
        swbox = gtk.VBox()
 
207
        swbox.pack_start(sw)
206
208
        swbox.show()
207
209
 
208
 
        hbox = Gtk.HBox(False, 6)
 
210
        hbox = gtk.HBox(False, 6)
209
211
        self.back_button = self._create_back_button()
210
212
        hbox.pack_start(self.back_button, expand=False, fill=True)
211
213
        self.forward_button = self._create_forward_button()
217
219
        hbox.show()
218
220
        vbox.pack_start(hbox, expand=False, fill=True)
219
221
 
220
 
        self.pane = pane = Gtk.VPaned()
 
222
        self.pane = pane = gtk.VPaned()
221
223
        pane.add1(swbox)
222
224
        pane.add2(self.revisionview)
223
225
        pane.show()
225
227
 
226
228
        self._search = SearchBox()
227
229
        swbox.pack_start(self._search, expand=False, fill=True)
228
 
        accels = Gtk.AccelGroup()
229
 
        accels.connect_group(Gdk.KEY_f, Gdk.EventMask.CONTROL_MASK,
230
 
                             Gtk.ACCEL_LOCKED,
 
230
        accels = gtk.AccelGroup()
 
231
        accels.connect_group(gtk.keysyms.f, gtk.gdk.CONTROL_MASK,
 
232
                             gtk.ACCEL_LOCKED,
231
233
                             self._search_by_text)
232
 
        accels.connect_group(Gdk.KEY_g, Gdk.EventMask.CONTROL_MASK,
233
 
                             Gtk.ACCEL_LOCKED,
 
234
        accels.connect_group(gtk.keysyms.g, gtk.gdk.CONTROL_MASK,
 
235
                             gtk.ACCEL_LOCKED,
234
236
                             self._search_by_line)
235
237
        self.add_accel_group(accels)
236
238
 
265
267
 
266
268
 
267
269
    def _create_annotate_view(self):
268
 
        tv = Gtk.TreeView()
 
270
        tv = gtk.TreeView()
269
271
        tv.set_rules_hint(False)
270
272
        tv.connect("cursor-changed", self._activate_selected_revision)
271
273
        tv.show()
272
274
        tv.connect("row-activated", self.line_diff)
273
275
 
274
 
        cell = Gtk.CellRendererText()
 
276
        cell = gtk.CellRendererText()
275
277
        cell.set_property("xalign", 1.0)
276
278
        cell.set_property("ypad", 0)
277
279
        cell.set_property("family", "Monospace")
278
280
        cell.set_property("cell-background-gdk",
279
 
                          tv.get_style().bg[Gtk.StateType.NORMAL])
280
 
        col = Gtk.TreeViewColumn()
 
281
                          tv.get_style().bg[gtk.STATE_NORMAL])
 
282
        col = gtk.TreeViewColumn()
281
283
        col.set_resizable(False)
282
 
        col.pack_start(cell, True, True, 0)
 
284
        col.pack_start(cell, expand=True)
283
285
        col.add_attribute(cell, "text", LINE_NUM_COL)
284
286
        tv.append_column(col)
285
287
 
286
 
        cell = Gtk.CellRendererText()
 
288
        cell = gtk.CellRendererText()
287
289
        cell.set_property("ypad", 0)
288
 
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
 
290
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
289
291
        cell.set_property("cell-background-gdk",
290
 
                          self.get_style().bg[Gtk.StateType.NORMAL])
291
 
        col = Gtk.TreeViewColumn("Committer")
 
292
                          self.get_style().bg[gtk.STATE_NORMAL])
 
293
        col = gtk.TreeViewColumn("Committer")
292
294
        col.set_resizable(True)
293
 
        col.pack_start(cell, True, True, 0)
 
295
        col.pack_start(cell, expand=True)
294
296
        col.add_attribute(cell, "text", COMMITTER_COL)
295
297
        tv.append_column(col)
296
298
 
297
 
        cell = Gtk.CellRendererText()
 
299
        cell = gtk.CellRendererText()
298
300
        cell.set_property("xalign", 1.0)
299
301
        cell.set_property("ypad", 0)
300
302
        cell.set_property("cell-background-gdk",
301
 
                          self.get_style().bg[Gtk.StateType.NORMAL])
302
 
        col = Gtk.TreeViewColumn("Revno")
 
303
                          self.get_style().bg[gtk.STATE_NORMAL])
 
304
        col = gtk.TreeViewColumn("Revno")
303
305
        col.set_resizable(False)
304
 
        col.pack_start(cell, True, True, 0)
 
306
        col.pack_start(cell, expand=True)
305
307
        col.add_attribute(cell, "markup", REVNO_COL)
306
308
        tv.append_column(col)
307
309
 
308
 
        cell = Gtk.CellRendererText()
 
310
        cell = gtk.CellRendererText()
309
311
        cell.set_property("ypad", 0)
310
312
        cell.set_property("family", "Monospace")
311
 
        col = Gtk.TreeViewColumn()
 
313
        col = gtk.TreeViewColumn()
312
314
        col.set_resizable(False)
313
 
        col.pack_start(cell, True, True, 0)
 
315
        col.pack_start(cell, expand=True)
314
316
#        col.add_attribute(cell, "foreground", HIGHLIGHT_COLOR_COL)
315
317
        col.add_attribute(cell, "background", HIGHLIGHT_COLOR_COL)
316
318
        col.add_attribute(cell, "text", TEXT_LINE_COL)
331
333
        return lv
332
334
 
333
335
    def _create_back_button(self):
334
 
        button = Gtk.Button()
 
336
        button = gtk.Button()
335
337
        button.set_use_stock(True)
336
338
        button.set_label("gtk-go-back")
337
339
        button.connect("clicked", lambda w: self.go_back())
338
 
        button.set_relief(Gtk.ReliefStyle.NONE)
 
340
        button.set_relief(gtk.RELIEF_NONE)
339
341
        button.show()
340
342
        return button
341
343
 
342
344
    def _create_forward_button(self):
343
 
        button = Gtk.Button()
 
345
        button = gtk.Button()
344
346
        button.set_use_stock(True)
345
347
        button.set_label("gtk-go-forward")
346
348
        button.connect("clicked", lambda w: self.go_forward())
347
 
        button.set_relief(Gtk.ReliefStyle.NONE)
 
349
        button.set_relief(gtk.RELIEF_NONE)
348
350
        button.show()
349
351
        button.set_sensitive(False)
350
352
        return button
351
353
 
352
354
    def _create_find_button(self):
353
 
        button = Gtk.Button()
 
355
        button = gtk.Button()
354
356
        button.set_use_stock(True)
355
357
        button.set_label("gtk-find")
356
358
        button.set_tooltip_text("Search for text (Ctrl+F)")
357
359
        button.connect("clicked", self._search_by_text)
358
 
        button.set_relief(Gtk.ReliefStyle.NONE)
 
360
        button.set_relief(gtk.RELIEF_NONE)
359
361
        button.show()
360
362
        button.set_sensitive(True)
361
363
        return button
362
364
 
363
365
    def _create_goto_button(self):
364
 
        button = Gtk.Button()
 
366
        button = gtk.Button()
365
367
        button.set_label("Goto Line")
366
368
        button.set_tooltip_text("Scroll to a line by entering its number (Ctrl+G)")
367
369
        button.connect("clicked", self._search_by_line)
368
 
        button.set_relief(Gtk.ReliefStyle.NONE)
 
370
        button.set_relief(gtk.RELIEF_NONE)
369
371
        button.show()
370
372
        button.set_sensitive(True)
371
373
        return button
450
452
            self.__cache[revision_id] = revision
451
453
        return self.__cache[revision_id]
452
454
 
453
 
class SearchBox(Gtk.HBox):
 
455
class SearchBox(gtk.HBox):
454
456
    """A button box for searching in text or lines of annotations"""
455
457
    def __init__(self):
456
 
        GObject.GObject.__init__(self, False, 6)
 
458
        gtk.HBox.__init__(self, False, 6)
457
459
 
458
460
        # Close button
459
 
        button = Gtk.Button()
460
 
        image = Gtk.Image()
461
 
        image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
 
461
        button = gtk.Button()
 
462
        image = gtk.Image()
 
463
        image.set_from_stock('gtk-stop', gtk.ICON_SIZE_BUTTON)
462
464
        button.set_image(image)
463
 
        button.set_relief(Gtk.ReliefStyle.NONE)
 
465
        button.set_relief(gtk.RELIEF_NONE)
464
466
        button.connect("clicked", lambda w: self.hide_all())
465
467
        self.pack_start(button, expand=False, fill=False)
466
468
 
467
469
        # Search entry
468
 
        label = Gtk.Label()
 
470
        label = gtk.Label()
469
471
        self._label = label
470
472
        self.pack_start(label, expand=False, fill=False)
471
473
 
472
 
        entry = Gtk.Entry()
 
474
        entry = gtk.Entry()
473
475
        self._entry = entry
474
476
        entry.connect("activate", lambda w, d: self._do_search(d),
475
477
                      'forward')
476
478
        self.pack_start(entry, expand=False, fill=False)
477
479
 
478
480
        # Next/previous buttons
479
 
        button = Gtk.Button('_Next')
480
 
        image = Gtk.Image()
481
 
        image.set_from_stock('gtk-go-forward', Gtk.IconSize.BUTTON)
 
481
        button = gtk.Button('_Next')
 
482
        image = gtk.Image()
 
483
        image.set_from_stock('gtk-go-forward', gtk.ICON_SIZE_BUTTON)
482
484
        button.set_image(image)
483
485
        button.connect("clicked", lambda w, d: self._do_search(d),
484
486
                       'forward')
485
487
        self.pack_start(button, expand=False, fill=False)
486
488
 
487
 
        button = Gtk.Button('_Previous')
488
 
        image = Gtk.Image()
489
 
        image.set_from_stock('gtk-go-back', Gtk.IconSize.BUTTON)
 
489
        button = gtk.Button('_Previous')
 
490
        image = gtk.Image()
 
491
        image.set_from_stock('gtk-go-back', gtk.ICON_SIZE_BUTTON)
490
492
        button.set_image(image)
491
493
        button.connect("clicked", lambda w, d: self._do_search(d),
492
494
                       'backward')
493
495
        self.pack_start(button, expand=False, fill=False)
494
496
 
495
497
        # Search options
496
 
        check = Gtk.CheckButton('Match case')
 
498
        check = gtk.CheckButton('Match case')
497
499
        self._match_case = check
498
500
        self.pack_start(check, expand=False, fill=False)
499
501
 
500
 
        check = Gtk.CheckButton('Regexp')
 
502
        check = gtk.CheckButton('Regexp')
501
503
        check.connect("toggled", lambda w: self._set_label())
502
504
        self._regexp = check
503
505
        self.pack_start(check, expand=False, fill=False)