Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--addons/gtkwidgeteventfilter.py2
-rw-r--r--data/icons/clock.svg4
-rw-r--r--tutorius/core.py7
-rw-r--r--tutorius/creator.py45
-rw-r--r--tutorius/viewer.py4
5 files changed, 34 insertions, 28 deletions
diff --git a/addons/gtkwidgeteventfilter.py b/addons/gtkwidgeteventfilter.py
index 6f8d797..5811744 100644
--- a/addons/gtkwidgeteventfilter.py
+++ b/addons/gtkwidgeteventfilter.py
@@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from sugar.tutorius.filters import EventFilter
-from sugar.tutorius.properties import TUAMProperty, TStringProperty
+from sugar.tutorius.properties import TUAMProperty, TGtkSignal
from sugar.tutorius.gtkutils import find_widget
class GtkWidgetEventFilter(EventFilter):
diff --git a/data/icons/clock.svg b/data/icons/clock.svg
index 8adb898..dc73bbb 100644
--- a/data/icons/clock.svg
+++ b/data/icons/clock.svg
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
-<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://web.resource.org/cc/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="231" height="231" id="svg2" sodipodi:version="0.32" inkscape:version="0.44+devel" sodipodi:docbase="C:\Documents and Settings\Molumen\Desktop" sodipodi:docname="clock_beige.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" sodipodi:modified="true" version="1.0">
+<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://web.resource.org/cc/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="51" height="51" id="svg2" sodipodi:version="0.32" inkscape:version="0.44+devel" sodipodi:docbase="C:\Documents and Settings\Molumen\Desktop" sodipodi:docname="clock_beige.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" sodipodi:modified="true" version="1.0">
<defs id="defs4">
<linearGradient y2="84.524567" x2="302" y1="365.95651" x1="302" gradientUnits="userSpaceOnUse" id="linearGradient20470" xlink:href="#linearGradient13034" inkscape:collect="always"/>
<radialGradient r="90.78125" fy="691.20294" fx="527" cy="691.20294" cx="527" gradientTransform="matrix(1, 0, 0, 0.231842, -340, 200.219)" gradientUnits="userSpaceOnUse" id="radialGradient20468" xlink:href="#linearGradient12977" inkscape:collect="always"/>
@@ -266,4 +266,4 @@
<path sodipodi:ry="138" sodipodi:rx="138" transform="matrix(0.728261, 0, 0, 0.601449, 306.065, 286.927)" d="M 440,288.36218 A 138,138 0 1 1 164,288.36218 A 138,138 0 1 1 440,288.36218 z" sodipodi:type="arc" sodipodi:cy="288.36218" sodipodi:cx="302" id="path19429" style="fill: url(#linearGradient19441) rgb(0, 0, 0); fill-opacity: 1; fill-rule: nonzero; stroke: none; stroke-width: 1; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; stroke-dasharray: none; stroke-dashoffset: 0pt; stroke-opacity: 1;"/>
</g>
</g>
-</svg> \ No newline at end of file
+</svg>
diff --git a/tutorius/core.py b/tutorius/core.py
index b24b80b..cf1d6b3 100644
--- a/tutorius/core.py
+++ b/tutorius/core.py
@@ -505,10 +505,9 @@ class FiniteStateMachine(State):
#TODO : Move this code inside the State itself - we're breaking
# encap :P
- if st._transitions:
- for event, state in st._transitions.items():
- if state == state_name:
- del st._transitions[event]
+ for event in st._transitions:
+ if st._transitions[event] == state_name:
+ del st._transitions[event]
# Remove the state from the dictionary
del self._states[state_name]
diff --git a/tutorius/creator.py b/tutorius/creator.py
index d8f3d98..b322b69 100644
--- a/tutorius/creator.py
+++ b/tutorius/creator.py
@@ -34,7 +34,7 @@ from sugar.tutorius import overlayer, gtkutils, actions, bundler, properties, ad
from sugar.tutorius import filters, __path__
from sugar.tutorius.services import ObjectStore
from sugar.tutorius.linear_creator import LinearCreator
-from sugar.tutorius.core import Tutorial
+from sugar.tutorius.core import Tutorial, FiniteStateMachine, State
from sugar.tutorius import viewer
class Creator(object):
@@ -97,6 +97,16 @@ class Creator(object):
self._overview.win.move(0, gtk.gdk.screen_height()- \
self._overview.win.get_allocation().height)
+ self._transitions = dict()
+
+ def _update_next_state(self, state, event, next_state):
+ self._transitions[event] = next_state
+
+ evts = state.get_event_filter_list()
+ state.clear_event_filters()
+ for evt, next_state in evts:
+ state.add_event_filter(evt, self._transitions[evt])
+
def delete_action(self, action):
"""
Removes the first instance of specified action from the tutorial.
@@ -121,8 +131,7 @@ class Creator(object):
ev_list = state.get_event_filter_list()
if ev_list:
- state = self._tutorial.get_state_by_name(
- ev_list[0].get_next_state())
+ state = self._tutorial.get_state_by_name(ev_list[0][1])
continue
return False
@@ -141,9 +150,8 @@ class Creator(object):
state = self._tutorial.get_state_by_name("INIT")
ev_list = state.get_event_filter_list()
- if state == self._state:
- next_state = self._tutorial.get_state_by_name(
- ev_list[0].get_next_state())
+ if state is self._state:
+ next_state = self._tutorial.get_state_by_name(ev_list[0][1])
self.set_insertion_point(next_state.name)
self._tutorial.remove_state(state.name)
self._tutorial.remove_state(next_state.name)
@@ -153,20 +161,17 @@ class Creator(object):
# loop to repair links from deleted state
while ev_list:
- next_state = self._tutorial.get_state_by_name(
- ev_list[0].get_next_state())
+ next_state = self._tutorial.get_state_by_name(ev_list[0][1])
if next_state is self._state:
# the tutorial will flush the event filters. We'll need to
# clear and re-add them.
- ev_list = copy.copy(ev_list)
self._tutorial.remove_state(self._state.name)
state.clear_event_filters()
- ev_list[0].set_next_state(
- next_state.get_event_filter_list()[0].get_next_state())
- for ev in ev_list:
- state.add_event_filter(ev)
+ self._update_next_state(state, ev_list[0][0], next_state.get_event_filter_list()[0][1])
+ for ev, next_state in ev_list:
+ state.add_event_filter(ev, next_state)
- self.set_insertion_point(ev_list[0].get_next_state())
+ self.set_insertion_point(ev_list[0][1])
return True
state = next_state
@@ -285,18 +290,20 @@ class Creator(object):
new_state = State(name=str(self._state_counter))
self._state_counter += 1
self._state.clear_event_filters()
- for evt_filt in event_filters:
- new_state.add_event_filter(evt_filt)
- event.set_next_state(new_state.name)
+ for evt_filt, next_state in event_filters:
+ new_state.add_event_filter(evt_filt, next_state)
+ self._update_next_state(self._state, event, new_state.name)
+ next_state = new_state.name
# blocks are shifted, full redraw is necessary
self._overview.win.queue_draw()
else:
# append empty event only if edit not inserting between events
- event.set_next_state(str(self._state_counter))
+ self._update_next_state(self._state, event, str(self._state_counter))
+ next_state = str(self._state_counter)
new_state = State(name=str(self._state_counter))
self._state_counter += 1
- self._state.add_event_filter(event)
+ self._state.add_event_filter(event, next_state)
self._tutorial.add_state(new_state)
self._overview.win.queue_draw()
diff --git a/tutorius/viewer.py b/tutorius/viewer.py
index e0ae4a9..751e89a 100644
--- a/tutorius/viewer.py
+++ b/tutorius/viewer.py
@@ -179,7 +179,7 @@ class Viewer(object):
if event_list:
local_height = (block_max_height - BLOCK_PADDING)/len(event_list) - BLOCK_PADDING
ctx.save()
- for event in event_list:
+ for event, next_state in event_list:
origin = tuple(ctx.get_matrix())[-2:]
if self.click_pos and \
self.click_pos[0]-BLOCK_WIDTH<origin[0] and \
@@ -193,7 +193,7 @@ class Viewer(object):
# FIXME point to next state in state, as it would highlight
# the "happy path".
- cur_state = event_list[0].get_next_state()
+ cur_state = event_list[0][1]
if (not new_insert_point) and self.click_pos:
origin = tuple(ctx.get_matrix())[-2:]