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.py93
1 files changed, 54 insertions, 39 deletions
diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py
index c7456c4..d9d06bb 100644
--- a/src/sugar/tutorius/bundler.py
+++ b/src/sugar/tutorius/bundler.py
@@ -30,6 +30,7 @@ from sugar.tutorius import gtkutils, overlayer
from sugar.tutorius.core import Tutorial, State, FiniteStateMachine
from sugar.tutorius.actions import *
import sugar.tutorius.filters
+#from sugar.tutorius.filters import EventFilter, TimerEvent, GtkWidgetEventFilter, GtkWidgetTypeFilter
from ConfigParser import SafeConfigParser
def _get_store_root():
@@ -141,30 +142,32 @@ class XMLSerializer(Serializer):
actionNode = doc.createElement("Action")
actionsList.appendChild(actionNode)
if type(action) is DialogMessage:
- actionNode.setAttribute("Class", type(action))
+ # 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)
elif type(action) is BubbleMessage:
- actionNode.setAttribute("Class", str(type(action)))
+ 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))
# TODO : elif for each type of action
elif type(action) is WidgetIdentifyAction:
- actionNode.setAttribute("Class", str(type(action)))
+ actionNode.setAttribute("Class", str(action.__class__))
# TODO
elif type(action) is ChainAction:
# TODO
- actionNode.setAttribute("Class", str(type(action)))
+ actionNode.setAttribute("Class", str(action.__class__))
elif type(action) is DisableWidgetAction:
# TODO
- actionNode.setAttribute("Class", str(type(action)))
+ actionNode.setAttribute("Class", str(action.__class__))
elif type(action) is TypeTextAction:
# TODO
- actionNode.setAttribute("Class", str(type(action)))
+ actionNode.setAttribute("Class", str(action.__class__))
elif type(action) is ClickAction:
# TODO
- actionNode.setAttribute("Class", str(type(action)))
+ actionNode.setAttribute("Class", str(action.__class__))
return actionsList
@@ -176,15 +179,18 @@ class XMLSerializer(Serializer):
for event_f in event_filters:
eventFilterNode = eventFiltersList.appendChild("EventFilter")
# TODO : elif for each type of event filters
- if type(event_f) is TimerEvent:
+ 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
+
# TODO
- eventFilterNode.setAttribute("Class", str(type(event_f)))
- elif type(event_f) is GtkWidgetEventFilter:
+ eventFilterNode.setAttribute("Class", str(event_f.__class__))
+ elif type(event_f) is sugar.tutorius.filters.GtkWidgetEventFilter:
# TODO
- eventFilterNode.setAttribute("Class", str(type(event_f)))
- elif type(event_f) is GtkWidgetTypeFilter:
+ eventFilterNode.setAttribute("Class", str(event_f.__class__))
+ elif type(event_f) is sugar.tutorius.filters.GtkWidgetTypeFilter:
# TODO
- eventFilterNode.setAttribute("Class", str(type(event_f)))
+ eventFilterNode.setAttribute("Class", str(event_f.__class__))
return eventFiltersList
@@ -275,21 +281,24 @@ class XMLSerializer(Serializer):
@param filters_elem An XML Element representing a list of event filters
"""
- event_filters_list = []
+ reformed_event_filters_list = []
+ # 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")
- for event_filter in actions_elem.getElementByTagName("EventFilter"):
+ for event_filter in event_filter_element_list:
# TODO : elif for each type of event filter
- if event_filter.getAttribute("Class") is TimerEvent:
+ if event_filter.getAttribute("Class") == str(sugar.tutorius.filters.TimerEvent):
# TODO
pass
- elif event_filter.getAttribute("Class") is GtkWidgetEventFilter:
+ elif event_filter.getAttribute("Class") == str(sugar.tutorius.filters.GtkWidgetEventFilter):
# TODO
pass
- elif event_filter.getAttribute("Class") is GtkWidgetTypeFilter:
+ elif event_filter.getAttribute("Class") == str(sugar.tutorius.filters.GtkWidgetTypeFilter):
# TODO
pass
- return event_filters_list
+ return reformed_event_filters_list
def _load_xml_actions(self, actions_elem):
"""
@@ -297,53 +306,59 @@ class XMLSerializer(Serializer):
@param actions_elem An XML Element representing a list of Actions
"""
- actions_list = []
+ reformed_actions_list = []
+ # item(0) because there is always only one <Actions> tag in the xml file
+ # so states_elem should always contain only one element
+ actions_element_list = actions_elem.item(0).getElementsByTagName("Action")
- for action in actions_elem.getElementByTagName("Action"):
+ for action in actions_element_list:
# TODO : elif for each type of action
- if action.getAttribute("Class") is DialogMessage:
+ if action.getAttribute("Class") == str(DialogMessage):
message = action.getAttribute("Message")
position = action.getAttribute("Postion")
- actions_list.append(DialogMessage(message,position))
- elif action.getAttribute("Class") is BubbleMessage:
+ 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")
- actions_list.append(BubbleMessage(message,position,None,tail_pos))
- elif action.getAttribute("Class") is WidgetIdentifyAction:
+ reformed_actions_list.append(BubbleMessage(message,position,None,tail_pos))
+ elif action.getAttribute("Class") == str(WidgetIdentifyAction):
# TODO
pass
- elif action.getAttribute("Class") is ChainAction:
+ elif action.getAttribute("Class") == str(ChainAction):
# TODO
pass
- elif action.getAttribute("Class") is DisableWidgetAction:
+ elif action.getAttribute("Class") == str(DisableWidgetAction):
# TODO
pass
- elif action.getAttribute("Class") is TypeTextAction:
+ elif action.getAttribute("Class") == str(TypeTextAction):
# TODO
pass
- elif action.getAttribute("Class") is ClickAction:
+ elif action.getAttribute("Class") == str(ClickAction):
# TODO
pass
- return actions_list
+ return reformed_actions_list
def _load_xml_states(self, states_elem):
"""
- Takes in a States element and fleshes out a complete dictionnary of State
+ Takes in a States element and fleshes out a complete list of State
objects.
@param states_elem An XML Element that represents a list of States
"""
- states_dict = {}
+ reformed_state_list = []
+ # item(0) because there is always only one <States> tag in the xml file
+ # so states_elem should always contain only one element
+ states_element_list = states_elem.item(0).getElementsByTagName("State")
- for state in states_elem.getElementByTagName("State"):
- stateName = states_elem.getAttribute("Name")
- actions_list = _load_xml_actions(state.getElementByTagName("Actions"))
- event_filters_list = _load_xml_event_filters(state.getElementByTagName("EventFiltersList"))
- states_dict[stateName] = State(stateName, actions_list, event_filters_list)
+ for state in states_element_list:
+ stateName = state.getAttribute("Name")
+ actions_list = self._load_xml_actions(state.getElementsByTagName("Actions"))
+ event_filters_list = self._load_xml_event_filters(state.getElementsByTagName("EventFiltersList"))
+ reformed_state_list.append(State(stateName, actions_list, event_filters_list))
- return states_dict
+ return reformed_state_list
def _load_xml_fsm(self, fsm_elem):
"""