Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/bundler.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/tutorius/bundler.py')
-rw-r--r--src/sugar/tutorius/bundler.py150
1 files changed, 95 insertions, 55 deletions
diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py
index 58288ca..34b3a12 100644
--- a/src/sugar/tutorius/bundler.py
+++ b/src/sugar/tutorius/bundler.py
@@ -140,33 +140,38 @@ class XMLSerializer(Serializer):
for action in action_list:
actionNode = doc.createElement("Action")
actionsList.appendChild(actionNode)
+ # Using .__class__ since type() doesn't have the same behavior
+ # with class derivating from object and class that don't
+ actionNode.setAttribute("Class", str(action.__class__))
+
if type(action) is DialogMessage:
- # Using .__class__ since type() doesn't have the same behavior
- # with class derivating from object and class that don't
- actionNode.setAttribute("Class", str(action.__class__))
- actionNode.setAttribute("Message", action.message)
- actionNode.setAttribute("Position", action.position)
+ actionNode.setAttribute("Message", action.message.value)
+ actionNode.setAttribute("PositionX", action.position.value[0])
+ actionNode.setAttribute("PositionY", str(action.position.value[1]))
elif type(action) is BubbleMessage:
- actionNode.setAttribute("Class", str(action.__class__))
- actionNode.setAttribute("Message", action.message)
- actionNode.setAttribute("Position", str(action.position))
- actionNode.setAttribute("Tail_pos", str(action.tail_pos))
+ actionNode.setAttribute("Message", action.message.value)
+ actionNode.setAttribute("PositionX", str(action.position.value[0]))
+ actionNode.setAttribute("PositionY", str(action.position.value[1]))
+ actionNode.setAttribute("Tail_posX", str(action.tail_pos.value[0]))
+ actionNode.setAttribute("Tail_posY", str(action.tail_pos.value[1]))
# TODO : elif for each type of action
elif type(action) is WidgetIdentifyAction:
- actionNode.setAttribute("Class", str(action.__class__))
- # TODO
+ # Nothing else to save
+ pass
elif type(action) is ChainAction:
- # TODO
- actionNode.setAttribute("Class", str(action.__class__))
+ # Recusively write the contained actions - in the correct order
+ subActionsNode = self._create_actions_node(action._actions, doc)
+ actionNode.appendChild(subActionsNode)
elif type(action) is DisableWidgetAction:
- # TODO
- actionNode.setAttribute("Class", str(action.__class__))
+ # Remember the target
+ actionNode.setAttribute("Target", action._target)
elif type(action) is TypeTextAction:
- # TODO
- actionNode.setAttribute("Class", str(action.__class__))
+ # Save the text and the widget
+ actionNode.setAttribute("Widget", action._widget)
+ actionNode.setAttribute("Text", action._text)
elif type(action) is ClickAction:
- # TODO
- actionNode.setAttribute("Class", str(action.__class__))
+ # Save the widget to click
+ actionNode.setAttribute("Widget", action._widget)
return actionsList
@@ -177,19 +182,27 @@ class XMLSerializer(Serializer):
eventFiltersList = doc.createElement("EventFiltersList")
for event_f in event_filters:
eventFilterNode = eventFiltersList.appendChild("EventFilter")
- # TODO : elif for each type of event filters
+
+ # Using .__class__ since type() doesn't have the same behavior
+ # with class derivating from object and class that don't
+ eventFilterNode.setAttribute("Class", str(event_f.__class__))
+
+ # Write the name of the next state
+ eventFilterNode.setAttribute("NextState", event_f.next_state)
+
if type(event_f) is sugar.tutorius.filters.TimerEvent:
- # Using .__class__ since type() doesn't have the same behavior
- # with class derivating from object and class that don't
+ eventFilterNode.setAttribute("Timeout_s", str(event_f._timeout))
- # TODO
- eventFilterNode.setAttribute("Class", str(event_f.__class__))
elif type(event_f) is sugar.tutorius.filters.GtkWidgetEventFilter:
- # TODO
- eventFilterNode.setAttribute("Class", str(event_f.__class__))
+ eventFilterNode.setAttribute("EventName", event_f._event_name)
+ eventFilterNode.setAttribute("ObjectId", event_f._object_id)
+
elif type(event_f) is sugar.tutorius.filters.GtkWidgetTypeFilter:
- # TODO
- eventFilterNode.setAttribute("Class", str(event_f.__class__))
+ eventFilterNode.setAttribute("ObjectId", event_f._object_id)
+ if event_f._strokes is not None:
+ eventFilterNode.setAttribute("Strokes", event_f._strokes)
+ if event_f._text is not None:
+ eventFilterNode.setAttribute("Text", event_f._text)
return eventFiltersList
@@ -204,14 +217,15 @@ class XMLSerializer(Serializer):
fsm_element.setAttribute("Name", fsm.name)
fsm_element.setAttribute("StartStateName", fsm.start_state_name)
statesDict = fsm_element.appendChild(self._create_state_dict_node(fsm._states, doc))
- actionsList = fsm_element.appendChild(self._create_action_list_node(fsm.actions, doc))
+
+ fsm_actions_node = self._create_action_list_node(fsm.actions, doc)
+ fsm_actions_node.tagName = "FSMActions"
+ actionsList = fsm_element.appendChild(fsm_actions_node)
file_object = open(os.path.join(path, xml_filename), "w")
- # Commented for DEBUG purposes
- #xml.dom.ext.PrettyPrint(doc, file_object)
file_object.write(doc.toprettyxml())
file_object.close()
-
+
def _find_tutorial_dir_with_guid(self, guid):
"""
@@ -284,18 +298,34 @@ class XMLSerializer(Serializer):
# item(0) because there is always only one <EventFilterList> tag in the xml file
# so states_elem should always contain only one element
event_filter_element_list = filters_elem.item(0).getElementsByTagName("EventFilter")
+ new_event_filter = None
for event_filter in event_filter_element_list:
- # TODO : elif for each type of event filter
+ # Load the name of the next state for this filter
+ next_state = event_filter.getAttribute("NextState")
+
if event_filter.getAttribute("Class") == str(sugar.tutorius.filters.TimerEvent):
- # TODO
- pass
+ timeout = int(event_filter.getAttribute("Timeout_s"))
+ new_event_filter = TimerEvent(next_state, timeout)
+
elif event_filter.getAttribute("Class") == str(sugar.tutorius.filters.GtkWidgetEventFilter):
- # TODO
- pass
+ # Get the event name and the object's ID
+ event_name = event_filter.getAttribute("EventName")
+ object_id = event_filter.getAttribute("ObjectId")
+
+ new_event_filter = GtkWidgetEventFilter(next_state, object_id, event_name)
elif event_filter.getAttribute("Class") == str(sugar.tutorius.filters.GtkWidgetTypeFilter):
- # TODO
- pass
+ # Get the widget to write in and the text
+ object_id = event_filter.getAttribute("ObjectId")
+ if event_filter.hasAttribute("Text"):
+ text = event_filter.getAttribute("Text")
+ new_event_filter = GtkWidgetTypeFilter(next_state, object_id, text=text)
+ elif event_filter.hasAttribute("Strokes"):
+ strokes = event_filter.getAttribute("Strokes")
+ new_event_filter = GtkWidgetTypeFilter(next_state, object_id, strokes=strokes)
+
+ if new_event_filter is not None:
+ reformed_event_filter.append(new_event_filter)
return reformed_event_filters_list
@@ -314,28 +344,40 @@ class XMLSerializer(Serializer):
# TODO : elif for each type of action
if action.getAttribute("Class") == str(DialogMessage):
message = action.getAttribute("Message")
- position = action.getAttribute("Postion")
+ positionX = int(action.getAttribute("PositionX"))
+ positionY = int(action.getAttribute("PositionY"))
+ position = [positionX, positionY]
reformed_actions_list.append(DialogMessage(message,position))
elif action.getAttribute("Class") == str(BubbleMessage):
message = action.getAttribute("Message")
- position = action.getAttribute("Postion")
- tail_pos = action.getAttribute("Tail_pos")
+ positionX = int(action.getAttribute("PositionX"))
+ positionY = int(action.getAttribute("PositionY"))
+ position = [positionX, positionY]
+ tail_posX = action.getAttribute("Tail_posX")
+ tail_posY = action.getAttribute("Tail_posY")
+ tail_pos = [tail_posX, tail_posY]
reformed_actions_list.append(BubbleMessage(message,position,None,tail_pos))
elif action.getAttribute("Class") == str(WidgetIdentifyAction):
- # TODO
- pass
+ reformed_actions_list.append(WidgetIdentifyAction())
elif action.getAttribute("Class") == str(ChainAction):
- # TODO
- pass
+ # Load the subactions
+ subActionsList = _load_xml_actions(action.getElementsByTagName("Actions"))
+ reformed_actions_list.append(ChainAction(subActionsList))
elif action.getAttribute("Class") == str(DisableWidgetAction):
- # TODO
- pass
+ # Get the target
+ targetName = action.getAttribute("Target")
+ reformed_actions_list.append(DisableWidgetAction(targetName))
elif action.getAttribute("Class") == str(TypeTextAction):
- # TODO
- pass
+ # Get the widget and the text to type
+ widget = action.getAttribute("Widget")
+ text = action.getAttribute("Text")
+
+ reformed_actions_list.append(TypeTextAction(widget, text))
elif action.getAttribute("Class") == str(ClickAction):
- # TODO
- pass
+ # Load the widget to click
+ widget = action.getAttribute("Widget")
+
+ reformed_actions_list.append(ClickAction(widget))
return reformed_actions_list
@@ -383,7 +425,7 @@ class XMLSerializer(Serializer):
fsm.add_state(state)
# Load the actions on this FSM
- actions = self._load_xml_actions(fsm_elem.getElementsByTagName("Actions"))
+ actions = self._load_xml_actions(fsm_elem.getElementsByTagName("FSMActions"))
for action in actions:
fsm.add_action(action)
@@ -399,7 +441,6 @@ class XMLSerializer(Serializer):
"""
Load fsm from xml file whose .ini file guid match argument guid.
"""
-
# Fetch the directory (if any)
tutorial_dir = self._find_tutorial_dir_with_guid(guid)
@@ -421,7 +462,6 @@ class TutorialBundler:
def __init__(self,generated_guid = None):
"""
- TODO.
Tutorial_bundler constructor. If a GUID is given in the parameter, the
Tutorial_bundler object will be associated with it. If no GUID is given,
a new GUID will be generated,