Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-02-23 16:04:12 (GMT)
committer Vincent Vinet <vince.vinet@gmail.com>2009-02-23 20:51:51 (GMT)
commite238a2d6b7f37e9a2f55d833ee2b5be7a3df7849 (patch)
tree478b6c50f37082b83c8b23fc8f55378122a25f0e
parent5e937f13f729448bee7bfc2c8ac2081747639b72 (diff)
Tutorius: Adding State and FSM stubs
-rw-r--r--src/sugar/tutorius/tutorial.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/sugar/tutorius/tutorial.py b/src/sugar/tutorius/tutorial.py
index 5236127..fc1d8ae 100644
--- a/src/sugar/tutorius/tutorial.py
+++ b/src/sugar/tutorius/tutorial.py
@@ -160,3 +160,67 @@ class Tutorial (object):
continue
+class State:
+ """This is a step in a tutorial. The state represents a collection of
+ actions to undertake when entering the state, and a description of an
+ event filter with associated actions to go to the next state."""
+
+ def __init__(self):
+ """Initializes the content of the state, as in loading the actions
+ that are required and building the correct tests."""
+ self.actions = []
+ self.tests = []
+
+
+ def setup(self):
+ """Install the state itself. This is the best time to pop-up a dialog
+ that has to remain for the duration of the state."""
+ for act in self.actions:
+ act.do()
+
+
+ def teardown(self):
+ """Undo every action that was installed for this state. This means
+ removing dialogs that were displayed, removing highlights, etc..."""
+ for act in self.actions:
+ act.undo()
+
+
+ def verify(self):
+ """Run the internal tests to see if one of them passes. If it does,
+ then do the associated processing to go in the next state."""
+ for test in self.tests:
+ if test.verify() == True:
+ actions = test.get_actions()
+ for act in actions:
+ act.do()
+ # Now that we execute the actions related to a test, we might
+ # want to undo them right after --- should we use a callback or
+ # a timer?
+
+class FiniteStateMachine(State):
+ """This is a collection of states, with a start state and an end callback.
+ It is used to simplify the development of the various tutorials by
+ encapsulating a collection of states that represent a given learning
+ process."""
+ def __init__(self, start_state, setup_actions):
+ """The constructor for a FSM. Pass in the start state and the setup
+ actions that need to be taken when the FSM itself start (which may be
+ different from what is done in the first state of the machine)."""
+ self.start_state = start_state
+ self.actions = setup_actions
+
+ self.tests = []
+
+ self.current_state = self.start_state
+
+ def setup(self):
+ for act in self.actions:
+ act.do()
+
+ def teardown(self):
+ for act in self.actions:
+ act.undo
+
+ def verify(self):
+ return self.current_state.verify() \ No newline at end of file