comparison pyink/domview.py @ 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 5ff744b981fb
children 6927debad4ee
comparison
equal deleted inserted replaced
1464:28769a82a72d 1465:a3ce8d22d163
327 if not states_nodes: 327 if not states_nodes:
328 self.fsm_states = {} 328 self.fsm_states = {}
329 return 329 return
330 states_node = states_nodes[0] 330 states_node = states_nodes[0]
331 331
332 self.fsm_start_state = states_node.getAttribute('start_state') 332 try:
333 self.fsm_start_state = states_node.getAttribute('start_state')
334 except:
335 pass
333 336
334 state_nodes = [child 337 state_nodes = [child
335 for child in states_node.childList 338 for child in states_node.childList
336 if child.name() == 'ns0:state'] 339 if child.name() == 'ns0:state']
337 states = [State.parse_state(node) for state_node in state_nodes] 340 states = [State.parse_state(node) for state_node in state_nodes]
406 409
407 def rename(self, new_name): 410 def rename(self, new_name):
408 self.node.setAttribute('name', new_name) 411 self.node.setAttribute('name', new_name)
409 pass 412 pass
410 413
414 def _create_states_node(self):
415 node = self.node
416 doc = self._comp_mgr._doc
417
418 states_node = doc.createElement('ns0:states')
419 node.addChild(states_node)
420 self.fsm_states_node = states_node
421 pass
422
411 def get_start_state_name(self): 423 def get_start_state_name(self):
412 return self.fsm_start_state 424 return self.fsm_start_state
413 425
414 def set_start_state(self, state_name): 426 def set_start_state(self, state_name):
415 assert state_name in self.fsm_states 427 assert state_name in self.fsm_states
421 433
422 def get_state(self, name): 434 def get_state(self, name):
423 return self.fsm_states[name] 435 return self.fsm_states[name]
424 436
425 def add_state(self, name): 437 def add_state(self, name):
438 if not self.fsm_states_node:
439 self._create_states_node()
440 pass
441
426 doc = self._comp_mgr._doc 442 doc = self._comp_mgr._doc
427 443
428 state = State(name) 444 state = State(name)
429 state.transitions = [] 445 state.transitions = []
430 self.fsm_states[name] = state 446 self.fsm_states[name] = state
431 447
432 state_node = state.create_node(doc) 448 state_node = state.create_node(doc)
433 node = self.node 449 states_node = self.fsm_states_node
434 node.addChild(state_node) 450 states_node.addChild(state_node)
435 pass 451 pass
436 452
437 def rename_state(self, state_name, new_name): 453 def rename_state(self, state_name, new_name):
438 state = self.fsm_states[state_name] 454 state = self.fsm_states[state_name]
439 del self.fsm_states[state_name] 455 del self.fsm_states[state_name]
446 fsm_states = self.fsm_states 462 fsm_states = self.fsm_states
447 state = fsm_states[name] 463 state = fsm_states[name]
448 del self.fsm_states[name] 464 del self.fsm_states[name]
449 465
450 state_node = state.node 466 state_node = state.node
451 node = self.node 467 states_node = self.fsm_states_node
452 node.removeChild(state_node) 468 states_node.removeChild(state_node)
453 pass 469 pass
454 pass 470 pass
455 471
456 472
457 ## \brief A mix-in for class component_manager for UI updating. 473 ## \brief A mix-in for class component_manager for UI updating.
560 if child_name in comp_names: 576 if child_name in comp_names:
561 raise ValueError, 'duplicate component name %s' % (child_name) 577 raise ValueError, 'duplicate component name %s' % (child_name)
562 578
563 comp = Component(self, child) 579 comp = Component(self, child)
564 comp.parse_timelines() 580 comp.parse_timelines()
581 comp.parse_states()
565 582
566 self._components.append(comp) 583 self._components.append(comp)
567 584
568 comp_names.add(child_name) 585 comp_names.add(child_name)
569 pass 586 pass