From 9fafb49af210e956d43d6a00106558d1a00d13df Mon Sep 17 00:00:00 2001 From: Simon Poirier Date: Thu, 02 Jul 2009 05:27:27 +0000 Subject: * Modularized actions and event filters through add-on components * Working serialization * Working editor with addons * began refactoring actions and events ** fixed some tests to work with addons ** filters and actions tests won't pass until refactoring is done --- (limited to 'src/sugar/tutorius/creator.py') diff --git a/src/sugar/tutorius/creator.py b/src/sugar/tutorius/creator.py index f24257e..d6826dc 100644 --- a/src/sugar/tutorius/creator.py +++ b/src/sugar/tutorius/creator.py @@ -27,16 +27,12 @@ from gettext import gettext as T from sugar.graphics.toolbutton import ToolButton -from sugar.tutorius import overlayer, gtkutils, actions, bundler, properties +from sugar.tutorius import overlayer, gtkutils, actions, bundler, properties, addon from sugar.tutorius import filters from sugar.tutorius.services import ObjectStore from sugar.tutorius.linear_creator import LinearCreator from sugar.tutorius.tutorial import Tutorial -insertable_actions = { - "MessageBubble" : actions.BubbleMessage -} - class Creator(object): """ Class acting as a bridge between the creator, serialization and core @@ -87,10 +83,12 @@ class Creator(object): self._tooldialog.set_size_request(dlg_width, dlg_height) toolbar = gtk.Toolbar() - toolitem = ToolButton("message-bubble") - toolitem.set_tooltip("Message Bubble") - toolitem.connect("clicked", self._add_action_cb, "MessageBubble") - toolbar.insert(toolitem, -1) + for tool in addon.list_addons(): + meta = addon.get_addon_meta(tool) + toolitem = ToolButton(meta['icon']) + toolitem.set_tooltip(meta['display_name']) + toolitem.connect("clicked", self._add_action_cb, tool) + toolbar.insert(toolitem, -1) toolitem = ToolButton("go-next") toolitem.connect("clicked", self._add_step_cb) toolitem.set_tooltip("Add Step") @@ -114,7 +112,7 @@ class Creator(object): to the FSM and increment states. """ self.introspecting = False - eventfilter = filters.GtkWidgetEventFilter( + eventfilter = addon.create('GtkWidgetEventFilter', next_state=None, object_id=self._selected_widget, event_name=event_name) @@ -191,12 +189,33 @@ class Creator(object): def _add_action_cb(self, widget, actiontype): """Callback for the action creation toolbar tool""" - action = actions.BubbleMessage("Bubble") - action.enter_editmode() - self._tutorial.action(action) - # TODO: replace following with event catching - action._BubbleMessage__drag._eventbox.connect_after( - "button-release-event", self._action_refresh_cb, action) + action = addon.create(actiontype) + if isinstance(action, actions.Action): + action.enter_editmode() + self._tutorial.action(action) + # FIXME: replace following with event catching + action._drag._eventbox.connect_after( + "button-release-event", self._action_refresh_cb, action) + else: + addonname = type(action).__name__ + meta = addon.get_addon_meta(addonname) + had_introspect = False + for propname in meta['mandatory_props']: + prop = getattr(type(action), propname) + if isinstance(prop, properties.TUAMProperty): + had_introspect = True + self.introspecting = True + elif isinstance(prop, properties.TStringProperty): + dlg = TextInputDialog(title="Mandatory property", + field=propname) + setattr(action, propname, dlg.pop()) + else: + raise NotImplementedError() + + # FIXME: hack to reuse previous introspection code + if not had_introspect: + self._tutorial.event(action) + def _action_refresh_cb(self, widget, evt, action): """ @@ -207,7 +226,7 @@ class Creator(object): action.enter_editmode() self._activity.queue_draw() # TODO: replace following with event catching - action._BubbleMessage__drag._eventbox.connect_after( + action._drag._eventbox.connect_after( "button-release-event", self._action_refresh_cb, action) self._propedit.action = action @@ -301,24 +320,26 @@ class EditToolBox(gtk.Window): """Refresh property values from the selected action.""" if self._action is None: return - props = self._action.get_properties() + props = self._action._props.keys() for propnum in xrange(len(props)): row = self._propbox.get_children()[propnum] - prop = self._action.properties[props[propnum]] + propname = props[propnum] + prop = getattr(type(self._action), propname) + propval = getattr(self._action, propname) if isinstance(prop, properties.TStringProperty): propwdg = row.get_children()[1] - propwdg.get_buffer().set_text(prop.value) + propwdg.get_buffer().set_text(propval) elif isinstance(prop, properties.TIntProperty): propwdg = row.get_children()[1] - propwdg.set_value(prop.value) + propwdg.set_value(propval) elif isinstance(prop, properties.TArrayProperty): propwdg = row.get_children()[1] - for i in xrange(len(prop.value)): + for i in xrange(len(propval)): entry = propwdg.get_children()[i] - entry.set_text(str(prop.value[i])) + entry.set_text(str(propval[i])) else: propwdg = row.get_children()[1] - propwdg.set_text(str(prop.value)) + propwdg.set_text(str(propval)) def set_action(self, action): """Setter for the action property.""" @@ -333,17 +354,18 @@ class EditToolBox(gtk.Window): self._action = action if action is None: return - for propname in action.get_properties(): + for propname in action._props.keys(): row = gtk.HBox() row.pack_start(gtk.Label(T(propname)), False, False, 10) - prop = action.properties[propname] + prop = getattr(type(action), propname) + propval = getattr(action, propname) if isinstance(prop, properties.TStringProperty): propwdg = gtk.TextView() - propwdg.get_buffer().set_text(prop.value) + propwdg.get_buffer().set_text(propval) propwdg.connect_after("focus-out-event", \ - self._str_prop_changed, action, prop) + self._str_prop_changed, action, propname) elif isinstance(prop, properties.TIntProperty): - adjustment = gtk.Adjustment(value=prop.value, + adjustment = gtk.Adjustment(value=propval, lower=prop.lower_limit.limit, upper=prop.upper_limit.limit, step_incr=1) @@ -352,14 +374,14 @@ class EditToolBox(gtk.Window): self._int_prop_changed, action, prop) elif isinstance(prop, properties.TArrayProperty): propwdg = gtk.HBox() - for i in xrange(len(prop.value)): + for i in xrange(len(propval)): entry = gtk.Entry() propwdg.pack_start(entry) entry.connect_after("focus-out-event", \ - self._list_prop_changed, action, prop, i) + self._list_prop_changed, action, propname, i) else: propwdg = gtk.Entry() - propwdg.set_text(str(prop.value)) + propwdg.set_text(str(propval)) row.pack_end(propwdg) self._propbox.pack_start(row, expand=False) self._vbox.show_all() @@ -371,18 +393,18 @@ class EditToolBox(gtk.Window): action = property(fset=set_action, fget=get_action, doc=\ "Action to be edited through introspection.") - def _list_prop_changed(self, widget, evt, action, prop, idx): + def _list_prop_changed(self, widget, evt, action, propname, idx): try: - prop.value[idx] = int(widget.get_text()) + getattr(action, propname)[idx] = int(widget.get_text()) except ValueError: - widget.set_text(str(prop.value[idx])) + widget.set_text(str(getattr(action, propname)[idx])) self.__parent._creator._action_refresh_cb(None, None, action) - def _str_prop_changed(self, widget, evt, action, prop): + def _str_prop_changed(self, widget, evt, action, propname): buf = widget.get_buffer() - prop.set(buf.get_text(buf.get_start_iter(), buf.get_end_iter())) + setattr(action, propname, buf.get_text(buf.get_start_iter(), buf.get_end_iter())) self.__parent._creator._action_refresh_cb(None, None, action) def _int_prop_changed(self, widget, evt, action, prop): - prop.set(widget.get_value_as_int()) + setattr(action, propname, widget.get_value_as_int()) self.__parent._creator._action_refresh_cb(None, None, action) class TextInputDialog(gtk.MessageDialog): @@ -411,6 +433,4 @@ class TextInputDialog(gtk.MessageDialog): def _dialog_done_cb(self, entry, response): self.response(response) - - # vim:set ts=4 sts=4 sw=4 et: -- cgit v0.9.1