Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sugar/tutorius/bundler.py72
1 files changed, 53 insertions, 19 deletions
diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py
index 74aecd1..6f61779 100644
--- a/src/sugar/tutorius/bundler.py
+++ b/src/sugar/tutorius/bundler.py
@@ -24,6 +24,7 @@ import logging
import os
import uuid
import xml.dom.minidom
+import xml.dom.ext
from sugar.tutorius import gtkutils, overlayer
from sugar.tutorius.core import Tutorial, State, FiniteStateMachine
@@ -130,7 +131,7 @@ class XMLSerializer(Serializer):
stateNode = stateNode.appendChild(create_event_filters_node(state.event_filters, doc))
return statesList
- def create_state_dict_node(self, action_list, doc):
+ def create_action_list_node(self, action_list, doc):
"""
Create and return a xml Node from a Action list.
"""
@@ -138,11 +139,52 @@ class XMLSerializer(Serializer):
for action in action_list:
actionNode = actionsList.appendChild("Action")
if type(action) is DialogMessage:
- actionNode.setAttribute("Action:Message", action._message)
-
- stateNode = stateNode.appendChild(create_action_list_node(state.action_list, doc))
- stateNode = stateNode.appendChild(create_event_filters_node(state.event_filters, doc))
- return stateNode
+ actionNode.setAttribute("Action:Class", type(action))
+ actionNode.setAttribute("Action:Message", action.message)
+ actionNode.setAttribute("Action:Position", action.position)
+ elif type(action) is BubbleMessage:
+ actionNode.setAttribute("Action:Class", str(type(action)))
+ actionNode.setAttribute("Action:Message", action.message)
+ actionNode.setAttribute("Action:Position", action.position)
+ actionNode.setAttribute("Action:Tail_pos", action.tail_pos)
+ # TODO : elif for each type of action
+ elif type(action) is WidgetIdentifyAction:
+ actionNode.setAttribute("Action:Class", str(type(action)))
+ # TODO
+ elif type(action) is ChainAction:
+ # TODO
+ actionNode.setAttribute("Action:Class", str(type(action)))
+ elif type(action) is DisableWidgetAction:
+ # TODO
+ actionNode.setAttribute("Action:Class", str(type(action)))
+ elif type(action) is TypeTextAction:
+ # TODO
+ actionNode.setAttribute("Action:Class", str(type(action)))
+ elif type(action) is ClickAction:
+ # TODO
+ actionNode.setAttribute("Action:Class", str(type(action)))
+
+ return actionsList
+
+ def create_event_filters_node(self, event_filters, doc):
+ """
+ Create and return a xml Node from a event filters.
+ """
+ eventFiltersList = doc.createElement("EventFiltersList")
+ for event_f in event_filters:
+ eventFilterNode = eventFiltersList.appendChild("EventFilter")
+ # TODO : elif for each type of event filters
+ if type(event_f) is TimerEvent:
+ # TODO
+ eventFilterNode.setAttribute("EventFilter:Class", str(type(event_f)))
+ elif type(event_f) is GtkWidgetEventFilter:
+ # TODO
+ eventFilterNode.setAttribute("EventFilter:Class", str(type(event_f)))
+ elif type(event_f) is GtkWidgetTypeFilter:
+ # TODO
+ eventFilterNode.setAttribute("EventFilter:Class", str(type(event_f)))
+
+ return eventFiltersList
def save_fsm(self, fsm, xml_filename, path):
"""
@@ -156,25 +198,17 @@ class XMLSerializer(Serializer):
fsm_element.setAttribute("fsm:StartStateName", fsm.start_state_name)
fsm_element = fsm_element.appendChild(create_state_dict_node(fsm.state_dict, doc))
fsm_element = fsm_element.appendChild(create_action_list_node(fsm.action_list, doc))
+
+ file_object = open(path + "/" + xml_filename, "w")
+ xml.dom.ext.PrettyPrint(doc, file_object)
+ file_object.close()
def load_fsm(self, guid):
"""
Load fsm from xml file who .ini file guid match argument guid.
"""
-##
-## path = os.getenv("SUGAR_ACTIVITY_ROOT") + "/data/"
-## # Create /data/ folder if no exists
-## if not os.path.exists(path):
-## os.mkdir(path)
-## logging.debug("************* Creating data folder")
-##
-## # Save the dictionnary to .tml file
-## tutoSave = file(path + filename + ".tml", 'w')
-## str = "--KEY::" + key + "\n--NAME::" + name + "\n--PICKLE::" + \
-## pickle.dumps(fsm,0)
-## tutoSave.write(str)
-## tutoSave.close()
+
class TutorialBundler: