Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-09-08 22:42:38 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-09-08 22:42:38 (GMT)
commita3800a37971a073b2d8e9df3ef8f2fbc8f302113 (patch)
tree3ef8566dc071a40cdfe60d5a7bbd9a628133acc9
parent67ee212417a7832eb1030984a87719893e7478a8 (diff)
Start crating SugarVte.View
-rw-r--r--sugarvte/__init__.py17
-rw-r--r--sugarvte/vteview.py90
2 files changed, 107 insertions, 0 deletions
diff --git a/sugarvte/__init__.py b/sugarvte/__init__.py
new file mode 100644
index 0000000..0110fb5
--- /dev/null
+++ b/sugarvte/__init__.py
@@ -0,0 +1,17 @@
+# Copyright (C) 2012 Daniel Francis <francis@sugarlabs.org>
+#
+# 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.
+
+from vteview import View
diff --git a/sugarvte/vteview.py b/sugarvte/vteview.py
new file mode 100644
index 0000000..f4843f3
--- /dev/null
+++ b/sugarvte/vteview.py
@@ -0,0 +1,90 @@
+# Copyright (C) 2012 Daniel Francis <francis@sugarlabs.org>
+#
+# 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):
+ 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')
+ ubuf = unicode(spec)
+ count = 0
+ for i in ubuf:
+ if i == '-':
+ range.start = i
+ range.end = i
+ self.word_chars.append(range)
+ logger.debug('Word charset includes hypen')
+ continue
+ if ubuf[1] != '-' and ubuf[count + 1] != '-':
+ range.start = i
+ range.end = i
+ self.word_chars.append(range)
+ continue
+
+
+if __name__ == "__main__":
+ view = View()
+ w = Gtk.Window()
+ w.connect('destroy', Gtk.main_quit)
+ w.add(view)
+ view.show()
+ w.show()
+ Gtk.main()