# HG changeset patch # User Thinker K.F. Li # Date 1303098472 -28800 # Node ID 6927debad4ee49e796222c6d776f4eff4aa5e1d5 # Parent 1829b0cc9721223da10754a92c87a7076ec3b5e8 Fix issue and a simple testcase for FSM diff -r 1829b0cc9721 -r 6927debad4ee pyink/FSM_window.py --- a/pyink/FSM_window.py Mon Apr 18 10:23:00 2011 +0800 +++ b/pyink/FSM_window.py Mon Apr 18 11:47:52 2011 +0800 @@ -66,6 +66,8 @@ super(FSM_window, self).__init__() self._locker = domview_ui + + self._domview = domview_ui self._close_cb = close_cb # callback to close editor window (hide) self._destroy_cb = destroy_cb # callback to destroy editor window @@ -86,6 +88,13 @@ def on_FSM_main_win_delete_event(self, *args): self._destroy_cb() pass + + def on_add_state_toggled(self, *args): + domview = self._domview + domview.add_state('test0') + domview.add_state('test1') + domview.add_transition('test0', 'event1', 'test1') + pass pass if __name__ == '__main__': diff -r 1829b0cc9721 -r 6927debad4ee pyink/domview.py --- a/pyink/domview.py Mon Apr 18 10:23:00 2011 +0800 +++ b/pyink/domview.py Mon Apr 18 11:47:52 2011 +0800 @@ -137,8 +137,9 @@ entry_action = None transitions = None - def __init__(self, node): + def __init__(self, node=None): self.node = node + self.transitions = {} pass def rename(self, name): @@ -180,7 +181,7 @@ node.setAttribute('entry_action', self.entry_action) pass - transitions = self.transitions or [] + transitions = self.transitions for trn in transitions: trn.update_node() pass @@ -221,7 +222,7 @@ trn.target = target trn_node = trn.create_node(node.document()) - node.addChild(trn_node) + node.appendChild(trn_node) transitions[cond] = trn pass @@ -286,6 +287,9 @@ pass pass + def _get_comp_node(self): + return self.node or self._comp_mgr._metadata_node + def name(self): if self.node: name = self.node.getAttribute('name') @@ -301,11 +305,11 @@ def parse_timelines(self): self.timelines[:] = [] - if self.node: + if self.node: # main component has None value for self.node assert self.node.name() == 'ns0:component' pass - comp_node = self.node + comp_node = self._get_comp_node() for child in comp_node.childList(): if child.name() == 'ns0:scenes': tl = Timeline(child) @@ -318,7 +322,7 @@ ## \brief Parse FSM from a ns0:states node. # def parse_states(self): - comp_node = self.node + comp_node = self._get_comp_node() assert (not comp_node) or comp_node.name() == 'ns0:component' states_nodes = [node @@ -363,7 +367,7 @@ 'try add a timeline with duplicated name - %s' % (name) doc = self._comp_mgr._doc - comp_node = self.node + comp_node = self._get_comp_node() scenes_node = doc.createElement('ns0:scenes') scenes_node.setAttribute('name', name) @@ -391,7 +395,7 @@ def rm_timeline(self, name): for i, tl in enumerate(self.timelines): if tl.name() == name: - comp_node = self.node + comp_node = self._get_comp_node() comp_node.removeChild(tl.scenes_node) del self.timelines[i] @@ -412,11 +416,11 @@ pass def _create_states_node(self): - node = self.node + node = self._get_comp_node() doc = self._comp_mgr._doc states_node = doc.createElement('ns0:states') - node.addChild(states_node) + node.appendChild(states_node) self.fsm_states_node = states_node pass @@ -441,13 +445,13 @@ doc = self._comp_mgr._doc - state = State(name) - state.transitions = [] + state = State() + state.name = name self.fsm_states[name] = state state_node = state.create_node(doc) states_node = self.fsm_states_node - states_node.addChild(state_node) + states_node.appendChild(state_node) pass def rename_state(self, state_name, new_name):