comparison pyink/domview.py @ 1310:85d04ba11146

Support adding new components
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 20 Jan 2011 12:44:37 +0800
parents 49775feefbcf
children fcff6978f9bf
comparison
equal deleted inserted replaced
1309:f2b1b22f7cbc 1310:85d04ba11146
42 for child in comp_node.childList(): 42 for child in comp_node.childList():
43 if child.name() == 'ns0:scenes': 43 if child.name() == 'ns0:scenes':
44 break 44 break
45 pass 45 pass
46 else: # no any ns0:scenes 46 else: # no any ns0:scenes
47 scenes_node = doc.createElementById('ns0:scenes') 47 doc = self._comp_mgr._doc
48 scenes_node = doc.createElement('ns0:scenes')
48 scenes_node.setAttribute('name', 'default') 49 scenes_node.setAttribute('name', 'default')
50
49 node_id = self._comp_mgr.new_id() 51 node_id = self._comp_mgr.new_id()
50 scenes_node.setAttribute('id', node_id) 52 scenes_node.setAttribute('id', node_id)
53
51 comp_node.appendChild(scenes_node) 54 comp_node.appendChild(scenes_node)
52 pass 55 pass
53 pass 56 pass
54 57
55 def name(self): 58 def name(self):
68 if self.node: 71 if self.node:
69 assert self.node.name() == 'ns0:component' 72 assert self.node.name() == 'ns0:component'
70 pass 73 pass
71 74
72 comp_node = self.node 75 comp_node = self.node
73 for child in comp_node.childList: 76 for child in comp_node.childList():
74 if child.name() == 'ns0:scenes': 77 if child.name() == 'ns0:scenes':
75 tl = Timeline(child) 78 tl = Timeline(child)
76 self.timelines.append(tl) 79 self.timelines.append(tl)
77 pass 80 pass
78 pass 81 pass
98 'try add a timeline with duplicated name - %s' % (name) 101 'try add a timeline with duplicated name - %s' % (name)
99 102
100 doc = self._comp_mgr._doc 103 doc = self._comp_mgr._doc
101 comp_node = self.node 104 comp_node = self.node
102 105
103 scenes_node = doc.createElementById('ns0:scenes') 106 scenes_node = doc.createElement('ns0:scenes')
104 scenes_node.setAttribute('name', name) 107 scenes_node.setAttribute('name', name)
105 node_id = self._comp_mgr.new_id() 108 node_id = self._comp_mgr.new_id()
106 scenes_node.setAttribute('id', node_id) 109 scenes_node.setAttribute('id', node_id)
107 110
108 comp_node.appendChild(scenes_node) 111 comp_node.appendChild(scenes_node)
216 def add_component(self, comp_name): 219 def add_component(self, comp_name):
217 if self.has_component(comp_name): 220 if self.has_component(comp_name):
218 raise ValueError, \ 221 raise ValueError, \
219 'try add a component with existed name %s' % (comp_name) 222 'try add a component with existed name %s' % (comp_name)
220 223
221 comp_node = self._doc.createElementById('ns0:component') 224 comp_node = self._doc.createElement('ns0:component')
222 comp_id = self.new_id() 225 comp_id = self.new_id()
223 comp_node.setAttribute('id', comp_id) 226 comp_node.setAttribute('id', comp_id)
224 comp_node.setAttribute('name', comp_name) 227 comp_node.setAttribute('name', comp_name)
225 self._components_node.appendChild(comp_node) 228 self._components_node.appendChild(comp_node)
226 229