From 394001c2e7c8585b7152e8f5888e340a0c7a1bbc Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 09 Dec 2009 02:58:20 +0000 Subject: Integration with Sugar : Exposing set_current_act on Service Correcting two interface mismatches (install error on translator, subscribe error on creator) Changing MessageButtonNext to ButtonNext --- diff --git a/addons/messagebuttonnext.py b/addons/messagebuttonnext.py index 40e55c2..37d86b4 100644 --- a/addons/messagebuttonnext.py +++ b/addons/messagebuttonnext.py @@ -29,7 +29,7 @@ class MessageButtonNext(EventFilter): MessageButtonNext """ # set message - message = TStringProperty("Message") + message = TStringProperty("Click next to continue") # create the position as an array of fixed-size 2 position = TArrayProperty((0,0), 2, 2) @@ -95,7 +95,7 @@ __event__ = { "display_name" : "Message button next", "icon" : "message-bubble", "class" : MessageButtonNext, - "mandatory_props" : ["message"] + "mandatory_props" : [] } class MsgNext(gtk.EventBox): diff --git a/src/extensions/tutoriusremote.py b/src/extensions/tutoriusremote.py index 129b7b3..2cd449d 100755 --- a/src/extensions/tutoriusremote.py +++ b/src/extensions/tutoriusremote.py @@ -106,6 +106,8 @@ class TPalette(Palette): activity = get_model().get_active_activity() act_name = activity.get_type() + LOGGER.debug("Remote :: Listing tutorial for activity %s", act_name) + tutorial_dict = Vault.list_available_tutorials(act_name) # Build the combo box diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py index 7f717f1..ea677ca 100644 --- a/tutorius/TProbe.py +++ b/tutorius/TProbe.py @@ -673,15 +673,24 @@ class ProbeProxy: else: LOGGER.debug("ProbeProxy :: unsubsribe address %s inconsistency : not registered", address) - def create_event(self, addon_name): + def create_event(self, addon_name, event_created_cb): """ Create an event on the app side and request the user to fill the properties before returning it. @param addon_name: the add-on name of the event + @param event_created_cb The notification to trigger once the event has + been instantiated @returns: an eventfilter instance """ - return pickle.loads(str(self._probe.create_event(addon_name))) + self._probe.create_event(addon_name, + reply_handler=save_args(self._event_created_cb, event_created_cb), + error_handler=ignore) + + def _event_created_cb(self, event_created_cb, event): + LOGGER.debug("ProbeProxy :: _event_created_cb, calling upper layer") + event = pickle.loads(str(event)) + event_created_cb(event) def subscribe(self, event, notification_cb, event_subscribed_cb, error_cb): @@ -754,26 +763,20 @@ class ProbeManager(object): ProbeManager._LOGGER.debug("__init__()") def setCurrentActivity(self, activity_id): - if not activity_id in self._probes: - raise RuntimeError("Activity not attached, id : %s"%activity_id) + # HACK : Disabling check for now, since it prevents usage of probes + # in activities that have yet to register their probes... We might + # set the current activity before having to execute anything inside it + # e.g. A new source is crawling in and we need to start the activity + # + # This should be removed once the Home Window probes are installed. + + #if not activity_id in self._probes: + # raise RuntimeError("Activity not attached, id : %s"%activity_id) + LOGGER.debug("ProbeManager :: New activity set as current = %s", str(activity_id)) self._current_activity = activity_id def getCurrentActivity(self): - if self._current_activity == "org.laptop.JournalActivity": - return self._current_activity - # TODO : Insert the correct call to remember the current activity, - # taking the views and frame into account - current_act = get_model().get_active_activity() - bundle_path = current_act.get_bundle_path() - if bundle_path: - current_act_bundle = ActivityBundle(bundle_path) - current_act_id = current_act_bundle.get_bundle_id() - self._current_activity = current_act_id - return self._current_activity - else: - # Temp hack for Journal - self._current_activity = 'org.laptop.JournalActivity'#current_act.get_bundle_id() - return self._current_activity + return self._current_activity currentActivity = property(fget=getCurrentActivity, fset=setCurrentActivity) @@ -848,16 +851,17 @@ class ProbeManager(object): else: raise RuntimeWarning("No activity attached") - def create_event(self, addon_name): + def create_event(self, addon_name, event_created_cb): """ Create an event on the app side and request the user to fill the properties before returning it. @param addon_name: the add-on name of the event + @param event_created_cb The notification to send once the event was created @returns: an eventfilter instance """ if self.currentActivity: - return self._first_proxy(self.currentActivity).create_event(addon_name) + return self._first_proxy(self.currentActivity).create_event(addon_name, event_created_cb) else: raise RuntimeWarning("No activity attached") @@ -918,6 +922,10 @@ class ProbeManager(object): self._probes[process_name] = [(unique_id,self._ProxyClass(process_name, unique_id))] else: self._probes[process_name].append((unique_id,self._ProxyClass(process_name, unique_id))) + # Register the probe that was just installed as the current activity + # (this will be true by default since we probably were waiting for it + # to open up) + self.currentActivity = process_name def unregister_probe(self, unique_id): diff --git a/tutorius/creator.py b/tutorius/creator.py index 6ba7011..7d9153b 100644 --- a/tutorius/creator.py +++ b/tutorius/creator.py @@ -306,8 +306,17 @@ class Creator(Object): """ event_type = self._propedit.events_list[path][ToolBox.ICON_NAME] - event = self._probe_mgr.create_event(event_type) + event = self._probe_mgr.create_event(event_type, + event_created_cb=partial(self._event_created, event_type)) + def _event_created(self, event_type, event): + """ + Callback to execute when the creation of a new event is complete. + + @param event_type The type of event that was created + @param event The event that was instanciated + """ + LOGGER.debug("Creator :: _event_created, now setting source and adding inside tutorial") # Configure the event prior to installing it # Currently, this consists of writing its source event.source = self._probe_mgr.currentActivity diff --git a/tutorius/engine.py b/tutorius/engine.py index 39cfeeb..de58f88 100644 --- a/tutorius/engine.py +++ b/tutorius/engine.py @@ -108,7 +108,7 @@ class TutorialRunner(object): # Verify if we just completed the subscription of all the events for this state self._verify_event_install_state() - def subscribe_error(self, event_name, exception): + def subscribe_error(self, event_name, event, exception): # TODO : Do correct error handling here LOGGER.debug("TutorialRunner :: Could not subscribe to event %s, got exception : %s"%(event_name, str(exception))) self._subscription_errors[event_name] = exception @@ -317,10 +317,15 @@ class Engine: #Get the active activity from the shell activity = self._shell.get_active_activity() - #TProbes automatically use the bundle id, available from the ActivityBundle - bundle = ActivityBundle(activity.get_bundle_path()) - self._tutorial._activity_id = bundle.get_bundle_id() #HACK until we have activity id's in action/events + LOGGER.debug("Engine :: Launching tutorial on activity %s", activity.get_type()) + if hasattr(activity, 'is_journal') and activity.is_journal(): + self._tutorial._activity_id = 'org.laptop.JournalActivity' + else: + #TProbes automatically use the bundle id, available from the ActivityBundle + bundle = ActivityBundle(activity.get_bundle_path()) + + self._tutorial._activity_id = bundle.get_bundle_id() #HACK until we have activity id's in action/events self._tutorial.start() diff --git a/tutorius/propwidgets.py b/tutorius/propwidgets.py index dfc6ac0..09d53c5 100644 --- a/tutorius/propwidgets.py +++ b/tutorius/propwidgets.py @@ -21,6 +21,9 @@ Allows displaying properties cleanly. import gtk import gobject +import logging +LOGGER = logging.getLogger("sugar.tutorius.propwidgets") + from . import gtkutils, overlayer ########################################################################### # Dialog classes @@ -94,6 +97,7 @@ class SignalInputDialog(gtk.MessageDialog): iter = self.entry.get_active_iter() if iter: text = self.model.get_value(iter, 0) + LOGGER.debug("SignalInputDialog :: Got signal name %s", text) return text return None diff --git a/tutorius/translator.py b/tutorius/translator.py index bd24f8f..fee964f 100644 --- a/tutorius/translator.py +++ b/tutorius/translator.py @@ -172,7 +172,7 @@ class ResourceTranslator(object): # was installed action_installed_cb(address) - def action_install_error(self, install_error_cb, old_action, exception): + def action_install_error(self, install_error_cb, old_action, new_action, exception): # Warn the upper layer that the installation failed install_error_cb(old_action, exception) @@ -186,7 +186,8 @@ class ResourceTranslator(object): self.translate(new_action) # Send the new action to the probe manager - self._probe_manager.install(new_action, save_args(self.action_installed, action_installed_cb), + self._probe_manager.install(new_action, + save_args(self.action_installed, action_installed_cb), save_args(self.action_install_error, error_cb, new_action), is_editing=is_editing, editing_cb=editing_cb) -- cgit v0.9.1