diff options
Diffstat (limited to 'tutorius/core.py')
-rw-r--r-- | tutorius/core.py | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/tutorius/core.py b/tutorius/core.py index dd2435e..8ab0b51 100644 --- a/tutorius/core.py +++ b/tutorius/core.py @@ -21,14 +21,11 @@ This module contains the core classes for tutorius """ -import gtk import logging -import copy import os -from sugar.tutorius.dialog import TutoriusDialog -from sugar.tutorius.gtkutils import find_widget -from sugar.tutorius.services import ObjectStore +from sugar.tutorius.TProbe import ProbeManager +from sugar.tutorius import addon logger = logging.getLogger("tutorius") @@ -37,7 +34,7 @@ class Tutorial (object): Tutorial Class, used to run through the FSM. """ - def __init__(self, name, fsm,filename= None): + def __init__(self, name, fsm, filename=None): """ Creates an unattached tutorial. """ @@ -51,21 +48,25 @@ class Tutorial (object): self.state = None self.handlers = [] - self.activity = None + self._probeMgr = ProbeManager() + self._activity_id = None #Rest of initialisation happens when attached - def attach(self, activity): + probeManager = property(lambda self: self._probeMgr) + activityId = property(lambda self: self._activity_id) + + def attach(self, activity_id): """ Attach to a running activity - @param activity the activity to attach to + @param activity_id the id of the activity to attach to """ #For now, absolutely detach if a previous one! - if self.activity: + if self._activity_id: self.detach() - self.activity = activity - ObjectStore().activity = activity - ObjectStore().tutorial = self + self._activity_id = activity_id + self._probeMgr.attach(activity_id) + self._probeMgr.currentActivity = activity_id self._prepare_activity() self.state_machine.set_state("INIT") @@ -77,9 +78,10 @@ class Tutorial (object): # Uninstall the whole FSM self.state_machine.teardown() - #FIXME There should be some amount of resetting done here... - self.activity = None - + #FIXME (Old) There should be some amount of resetting done here... + if not self._activity_id is None: + self._probeMgr.detach(self._activity_id) + self._activity_id = None def set_state(self, name): """ @@ -112,9 +114,9 @@ class Tutorial (object): #of the activity root directory filename = os.getenv("SUGAR_ACTIVITY_ROOT") + "/data/" +\ self.activity_init_state_filename - if os.path.exists(filename): - self.activity.read_file(filename) - + readfile = addon.create("ReadFile", filename=filename) + if readfile: + self._probeMgr.install(self._activity_id, readfile) class State(object): """ @@ -169,11 +171,10 @@ class State(object): and then triggering the actions. """ for eventfilter in self._event_filters: - eventfilter.install_handlers(self._event_filter_state_done_cb, - activity=self.tutorial.activity) + self.tutorial.probeManager.subscribe(eventfilter, self._event_filter_state_done_cb ) for action in self._actions: - action.do() + self.tutorial.probeManager.install(action) def teardown(self): """ @@ -183,11 +184,11 @@ class State(object): """ # Remove the handlers for the all of the state's event filters for event_filter in self._event_filters: - event_filter.remove_handlers() + self.tutorial.probeManager.unsubscribe(event_filter, self._event_filter_state_done_cb ) # Undo all the actions related to this state for action in self._actions: - action.undo() + self.tutorial.probeManager.uninstall(action) def _event_filter_state_done_cb(self, event_filter): """ @@ -349,7 +350,7 @@ class FiniteStateMachine(State): self._fsm_setup_done = True # Execute all the FSM level actions for action in self.actions: - action.do() + self.tutorial.probeManager.install(action) # Then, we need to run the setup of the current state self.current_state.setup() @@ -414,7 +415,7 @@ class FiniteStateMachine(State): self._fsm_teardown_done = True # Undo all the FSM level actions here for action in self.actions: - action.undo() + self.tutorial.probeManager.uninstall(action) # TODO : It might be nice to have a start() and stop() method for the # FSM. |