# Copyright (C) 2012 Daniel Francis # # This is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #Python translation of Vte. # http://git.gnome.org/browse/vte?h=vte-next import logging logger = logging.getLogger('SugarVteView') from gi.repository import GObject from gi.repository import Gtk class WordCharRange: start = None end = None class View(Gtk.Widget, Gtk.Scrollable): __gsignals__ = {'buffer-changed': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT,)), 'char-size-changed': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_INT, GObject.TYPE_INT)), 'selection-changed': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple()), 'increase-font-size': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple()), 'decrease-font-size': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple()), 'text-scrolled': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_INT,)), 'copy-clipboard': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple()), 'paste-clipboard': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple()), 'copy-primary': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple()), 'paste-primary': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple())} __gproperties__ = {'word-chars' : (GObject.TYPE_PYOBJECT, 'word chars', '', GObject.PARAM_READWRITE)} char_width = 1 char_height = 2 char_ascent = 3 char_descent = 4 line_thickness = 1 underline_position = 1 strikethrough_position = 1 scroll_on_keystroke = True def __init__(self): GObject.GObject.__init__(self) self.set_can_focus(True) self.set_app_paintable(True) self.set_redraw_on_allocate(False) self.set_word_chars(None) vadjustment = GObject.property(type=Gtk.Adjustment) hadjustment = GObject.property(type=Gtk.Adjustment) hscroll_policy = GObject.property(type=Gtk.ScrollablePolicy, default=Gtk.ScrollablePolicy.NATURAL) vscroll_policy = GObject.property(type=Gtk.ScrollablePolicy, default=Gtk.ScrollablePolicy.NATURAL) def set_word_chars(self, spec=None): """ @spec: a specification When the user double-clicks to start selection, the terminal will extend the selection on word boundaries. It will treat characters included in @spec as parts of words, and all other characters as word separators. Ranges of characters can be specified by separating them with a hyphen. As a special case, if @spec is %NULL or the empty string, the terminal will treat all graphic non-punctuation non-space characters as word characters. """ range = WordCharRange() self.word_chars = [] if spec == None or spec[0] == '\0': self.notify('word-chars') return ubuf = unicode(spec) i = -1 while i + 1 < len(ubuf): i += 1 if ubuf[i] == '-': range.start = ubuf[i] range.end = ubuf[i] self.word_chars.append(range) logger.debug('Word charset includes hypen') continue if ubuf[i] != '-' and ubuf[i + 1] != '-': range.start = ubuf[i] range.end = ubuf[i] self.word_chars.append(range) continue if ubuf[i] != '-' and\ ubuf[i + 1] == u'-' and\ ubuf[i + 2] != u'-' and\ ubuf[i + 2] != unichr(0): range.start = ubuf[i] range.end = ubuf[i + 1] self.word_chars.append(range) i += 2 continue self.notify('word-chars') if __name__ == "__main__": view = View() w = Gtk.Window() w.connect('destroy', Gtk.main_quit) w.add(view) view.show() w.show() Gtk.main()