changeset 1465:a3ce8d22d163

Parse states while parsing a component
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 17 Apr 2011 23:53:15 +0800
parents 28769a82a72d
children 1829b0cc9721
files pyink/domview.py
diffstat 1 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/domview.py	Sun Apr 17 21:34:49 2011 +0800
+++ b/pyink/domview.py	Sun Apr 17 23:53:15 2011 +0800
@@ -329,7 +329,10 @@
             return
         states_node = states_nodes[0]
         
-        self.fsm_start_state = states_node.getAttribute('start_state')
+        try:
+            self.fsm_start_state = states_node.getAttribute('start_state')
+        except:
+            pass
         
         state_nodes = [child
                        for child in states_node.childList
@@ -408,6 +411,15 @@
         self.node.setAttribute('name', new_name)
         pass
 
+    def _create_states_node(self):
+        node = self.node
+        doc = self._comp_mgr._doc
+
+        states_node = doc.createElement('ns0:states')
+        node.addChild(states_node)
+        self.fsm_states_node = states_node
+        pass
+
     def get_start_state_name(self):
         return self.fsm_start_state
 
@@ -423,6 +435,10 @@
         return self.fsm_states[name]
 
     def add_state(self, name):
+        if not self.fsm_states_node:
+            self._create_states_node()
+            pass
+        
         doc = self._comp_mgr._doc
         
         state = State(name)
@@ -430,8 +446,8 @@
         self.fsm_states[name] = state
 
         state_node = state.create_node(doc)
-        node = self.node
-        node.addChild(state_node)
+        states_node = self.fsm_states_node
+        states_node.addChild(state_node)
         pass
 
     def rename_state(self, state_name, new_name):
@@ -448,8 +464,8 @@
         del self.fsm_states[name]
 
         state_node = state.node
-        node = self.node
-        node.removeChild(state_node)
+        states_node = self.fsm_states_node
+        states_node.removeChild(state_node)
         pass
     pass
 
@@ -562,6 +578,7 @@
 
             comp = Component(self, child)
             comp.parse_timelines()
+            comp.parse_states()
             
             self._components.append(comp)