comparison pyink/domview.py @ 1336:0b5ee9c90af7

Update components and timelines list for async changes on DOM
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 01 Feb 2011 23:20:26 +0800
parents 5da64f67d00d
children 10d5f06f7566
comparison
equal deleted inserted replaced
1335:194c7a831083 1336:0b5ee9c90af7
88 def all_timeline_names(self): 88 def all_timeline_names(self):
89 names = [tl.name() for tl in self.timelines] 89 names = [tl.name() for tl in self.timelines]
90 return names 90 return names
91 91
92 def parse_timelines(self): 92 def parse_timelines(self):
93 print 'parse timelines fro component ' + self.name()
94 self.timelines[:] = []
95
93 if self.node: 96 if self.node:
94 assert self.node.name() == 'ns0:component' 97 assert self.node.name() == 'ns0:component'
95 pass 98 pass
96 99
97 comp_node = self.node 100 comp_node = self.node
98 for child in comp_node.childList(): 101 for child in comp_node.childList():
99 if child.name() == 'ns0:scenes': 102 if child.name() == 'ns0:scenes':
100 tl = Timeline(child) 103 tl = Timeline(child)
101 self.timelines.append(tl) 104 self.timelines.append(tl)
105 print ' ' + tl.name()
102 pass 106 pass
103 pass 107 pass
104 pass 108 pass
105 109
106 def get_timeline(self, name): 110 def get_timeline(self, name):
167 pass 171 pass
168 raise ValueError, 'try to remove a non-existed timeline - %s' % (name) 172 raise ValueError, 'try to remove a non-existed timeline - %s' % (name)
169 173
170 def rename(self, new_name): 174 def rename(self, new_name):
171 self.node.setAttribute('name', new_name) 175 self.node.setAttribute('name', new_name)
176 pass
177 pass
178
179
180 ## \brief A mix-in for class component_manager for UI updating.
181 #
182 # This class collects all methods for supporting UI updating.
183 #
184 class component_manager_ui_update(object):
185 ## \brief Update the list of components.
186 #
187 def reparse_components(self):
188 saved_cur_comp = self._cur_comp
189 self._components[:] = [self._main_comp]
190 self._comp_names.clear()
191 self._parse_components()
192
193 for comp in self._components:
194 if comp.name() == saved_cur_comp.name():
195 self._cur_comp = comp
196 break
197 pass
198 else:
199 self._cur_comp = self._main_comp
200 pass
201 pass
202
203 ## \brief Update the list of timelines of current component.
204 #
205 def reparse_timelines(self):
206 comp = self._cur_comp
207 saved_cur_timeline = self._cur_timeline
208 comp.parse_timelines()
209
210 for timeline in comp.timelines:
211 if timeline.name() == saved_cur_timeline.name():
212 self._cur_timeline = timeline
213 break
214 pass
215 else:
216 self._cur_timeline = comp.timelines[0]
217 pass
172 pass 218 pass
173 pass 219 pass
174 220
175 221
176 ## \brief A mix-in for class domview for management of components. 222 ## \brief A mix-in for class domview for management of components.
187 # 233 #
188 # FIXME: The root node is always the 'main' component. It is a 234 # FIXME: The root node is always the 'main' component. It is a
189 # special case with slightly different in structure. It should be 235 # special case with slightly different in structure. It should be
190 # removed and normalized to normal components. 236 # removed and normalized to normal components.
191 # 237 #
192 class component_manager(object): 238 class component_manager(component_manager_ui_update):
193 def __init__(self): 239 def __init__(self):
194 self._components_node = None 240 self._components_node = None
195 self._components = [] 241 self._components = []
196 self._comp_names = set() 242 self._comp_names = set()
197 self._main_comp = None 243 self._main_comp = None
701 (new_value) 747 (new_value)
702 748
703 if old_value: 749 if old_value:
704 del self._id2node[old_value] 750 del self._id2node[old_value]
705 pass 751 pass
706 self._id2node[new_value] = node 752 if new_value:
753 self._id2node[new_value] = node
754 pass
707 pass 755 pass
708 elif name == 'ref' and node.name() == 'ns0:scene': 756 elif name == 'ref' and node.name() == 'ns0:scene':
709 parent_node = node.parent() 757 parent_node = node.parent()
710 scenes_node = self._scenes_node 758 scenes_node = self._scenes_node
711 if not _id_eq(parent_node, scenes_node): 759 if not _id_eq(parent_node, scenes_node):
757 805
758 def _collect_node_ids_recursive(self, node): 806 def _collect_node_ids_recursive(self, node):
759 try: 807 try:
760 node_id = node.getAttribute('id') 808 node_id = node.getAttribute('id')
761 except: 809 except:
762 return 810 pass
763 811 else:
764 self._id2node[node_id] = node 812 self._id2node[node_id] = node
813 pass
814
765 for n in node.childList(): 815 for n in node.childList():
766 self._collect_node_ids_recursive(n) 816 self._collect_node_ids_recursive(n)
767 pass 817 pass
768 pass 818 pass
769 819