comparison pyink/MBScene.py @ 1246:42c4874c8d1e

Move _duplicate_group to domview_ui. - domview_ui.copy_key_group() replaces MBScene._duplicate_group().
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 10 Jan 2011 19:44:15 +0800
parents ccbf0c5d01d1
children 2f9fa5d59e67
comparison
equal deleted inserted replaced
1245:ccbf0c5d01d1 1246:42c4874c8d1e
35 # scene is 10, we will set the scene field as "8-10". 35 # scene is 10, we will set the scene field as "8-10".
36 # - 5. If this scene are filled screne, we will split the existing 36 # - 5. If this scene are filled screne, we will split the existing
37 # scene into two scenes with the same content. 37 # scene into two scenes with the same content.
38 # 38 #
39 39
40 ## \brief Iterator to travel a sub-tree of DOM.
41 #
42 def _DOM_iterator(node):
43 nodes = [node]
44 while nodes:
45 node = nodes.pop(0)
46 child = node.firstChild()
47 while child:
48 nodes.append(child)
49 child = child.next()
50 pass
51 yield node
52 pass
53 pass
54
55
56 ## \brief MBScene connect GUI and DOM-tree 40 ## \brief MBScene connect GUI and DOM-tree
57 # 41 #
58 # This method accepts user actions and involves domview_ui to update 42 # This method accepts user actions and involves domview_ui to update
59 # data on the document. 43 # data on the document.
60 # 44 #
172 return 156 return
173 if left_end >= frame_idx: 157 if left_end >= frame_idx:
174 return 158 return
175 159
176 self._domview.mark_key(layer_idx, frame_idx) 160 self._domview.mark_key(layer_idx, frame_idx)
177 161 self._domview.copy_key_group(layer_idx, left_start, frame_idx)
178 scene_group = self._domview.get_key_group(layer_idx, frame_idx)
179 left_scene_group = \
180 self._domview.get_key_group(layer_idx, left_start)
181
182 dup_group = self._duplicate_group(left_scene_group, scene_group)
183 162
184 self._director.show_scene(frame_idx) 163 self._director.show_scene(frame_idx)
185 pass 164 pass
186 165
187 ## \brief Duplicate children of a group.
188 #
189 # Duplicate children of a group, and append them to another group.
190 #
191 def _duplicate_group(self, src_group, dst_group):
192 # Search for the duplicated group
193 root = self._root
194 doc = self.document
195
196 dup_group = src_group.duplicate(doc)
197 for child in dup_group.childList():
198 dup_group.removeChild(child) # prvent from crash
199 dst_group.appendChild(child)
200 pass
201
202 old_nodes = _DOM_iterator(src_group)
203 new_nodes = _DOM_iterator(dst_group)
204 for old_node in old_nodes:
205 old_node_id = old_node.getAttribute('id')
206 new_node = new_nodes.next()
207 new_node.setAttribute('ns0:duplicate-src', old_node_id)
208 pass
209 pass
210
211 def changeObjectLabel(self,w): 166 def changeObjectLabel(self,w):
212 o = self.desktop.selection.list()[0] 167 o = self.desktop.selection.list()[0]
213 o.setAttribute("inkscape:label", self.nameEditor.get_text()) 168 o.setAttribute("inkscape:label", self.nameEditor.get_text())
214 pass 169 pass
215 170