Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/editor.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/tutorius/editor.py')
-rw-r--r--src/sugar/tutorius/editor.py115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/sugar/tutorius/editor.py b/src/sugar/tutorius/editor.py
new file mode 100644
index 0000000..1a1eb61
--- /dev/null
+++ b/src/sugar/tutorius/editor.py
@@ -0,0 +1,115 @@
+# Copyright (C) 2009, Tutorius.org
+# Greatly influenced by sugar/activity/namingalert.py
+#
+# This program 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 2 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gtk
+import gobject
+import hippo
+import gconf
+
+from gettext import gettext as _
+
+class WidgetIdentifier(gtk.Window):
+ """
+ Tool that allows identifying widgets
+ """
+ __gtype_name__ = 'TutoriusWidgetIdentifier'
+
+ def __init__(self, activity):
+ gtk.Window.__init__(self)
+
+ self._activity = activity
+ self._handlers = []
+
+ self.set_decorated(False)
+ self.set_resizable(False)
+ self.set_modal(False)
+
+ self.connect('realize', self.__realize_cb)
+
+ self._expander = gtk.Expander(_("Widget Identifier"))
+ self._expander.set_expanded(True)
+ self.add(self._expander)
+ self._expander.connect("notify::expanded", self.__expander_cb)
+
+ self._expander.show()
+
+ vbox = gtk.VBox()
+ self._expander.add(vbox)
+ vbox.show()
+
+
+ self.logview = gtk.TextView()
+ self.logview.set_editable(False)
+ self.logview.set_cursor_visible(False)
+ self.logview.set_wrap_mode(gtk.WRAP_NONE)
+ self._textbuffer = self.logview.get_buffer()
+
+ sw = gtk.ScrolledWindow()
+ sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ sw.add(self.logview)
+ self.logview.show()
+
+ vbox.pack_start(sw)
+ sw.show()
+
+ from sugar.tutorius.gtkutils import register_signals_numbered
+ self._handlers = register_signals_numbered(self._activity, self._handle_events)
+
+ def __expander_cb(self, *args):
+ if self._expander.get_expanded():
+ self.__move_expanded()
+ else:
+ self.__move_collapsed()
+
+ def __move_expanded(self):
+ width = 400
+ height = 300
+ ww = gtk.gdk.screen_width()
+ wh = gtk.gdk.screen_height()
+
+ self.set_size_request(width, height)
+ self.move((ww-width)/2, wh-height)
+
+ def __move_collapsed(self):
+ width = 150
+ height = 40
+ ww = gtk.gdk.screen_width()
+ wh = gtk.gdk.screen_height()
+
+ self.set_size_request(width, height)
+ self.move((ww-width)/2, wh-height)
+
+ def __realize_cb(self, widget):
+ self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
+ self.window.set_accept_focus(True)
+ self.__move_expanded()
+
+ def _disconnect_handlers(self):
+ for widget, handlerid in self._handlers:
+ widget.handler_disconnect(handlerid)
+ self._handlers = []
+
+ def _handle_events(self,*args):
+ sig, name = args[-1]
+ text = "\r\n".join(
+ (["%s event received from %s" % (sig, name)] +
+ self._textbuffer.get_text(*(self._textbuffer.get_bounds())
+ ).split("\r\n"))[:80]
+ )
+ self._textbuffer.set_text(text)
+
+