diff options
author | Vincent Vinet <vince.vinet@gmail.com> | 2009-03-19 03:47:04 (GMT) |
---|---|---|
committer | Vincent Vinet <vince.vinet@gmail.com> | 2009-03-19 18:23:13 (GMT) |
commit | 72e28a934bc26b5f9c9b8ac6d917aad5eb76b51d (patch) | |
tree | 121f8ec9b365f82f367e920113b6fb85f2157fe5 /src/sugar/tutorius/editor.py | |
parent | cd4b5c8d01e68f170c783b638ad24992dbba8aea (diff) |
Add the Widget Identifier and corresponding Action
Make Writus use it
Fix a dupe in the ActivityToolbar
Use the ObjectStore in tutorial.attach()
Do a rebase onto master and hope it works
Diffstat (limited to 'src/sugar/tutorius/editor.py')
-rw-r--r-- | src/sugar/tutorius/editor.py | 115 |
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) + + |