changeset 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 45e9566ea5c0
files pyink/MBScene.py pyink/domview.py pyink/domview_ui.py
diffstat 3 files changed, 52 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Mon Jan 10 19:07:26 2011 +0800
+++ b/pyink/MBScene.py	Mon Jan 10 19:44:15 2011 +0800
@@ -37,22 +37,6 @@
 #       scene into two scenes with the same content.
 #
 
-## \brief Iterator to travel a sub-tree of DOM.
-#
-def _DOM_iterator(node):
-    nodes = [node]
-    while nodes:
-	node = nodes.pop(0)
-	child = node.firstChild()
-	while child:
-	    nodes.append(child)
-	    child = child.next()
-	    pass
-	yield node
-	pass
-    pass
-
-
 ## \brief MBScene connect GUI and DOM-tree
 #
 # This method accepts user actions and involves domview_ui to update
@@ -174,40 +158,11 @@
 	    return
 
 	self._domview.mark_key(layer_idx, frame_idx)
-	
-	scene_group = self._domview.get_key_group(layer_idx, frame_idx)
-	left_scene_group = \
-	    self._domview.get_key_group(layer_idx, left_start)
-	
-	dup_group = self._duplicate_group(left_scene_group, scene_group)
+	self._domview.copy_key_group(layer_idx, left_start, frame_idx)
 
 	self._director.show_scene(frame_idx)
 	pass
 
-    ## \brief Duplicate children of a group.
-    #
-    # Duplicate children of a group, and append them to another group.
-    #
-    def _duplicate_group(self, src_group, dst_group):
-	# Search for the duplicated group
-        root = self._root
-	doc = self.document
-	
-	dup_group = src_group.duplicate(doc)
-	for child in dup_group.childList():
-	    dup_group.removeChild(child) # prvent from crash
-	    dst_group.appendChild(child)
-	    pass
-
-	old_nodes = _DOM_iterator(src_group)
-	new_nodes = _DOM_iterator(dst_group)
-	for old_node in old_nodes:
-	    old_node_id = old_node.getAttribute('id')
-	    new_node = new_nodes.next()
-	    new_node.setAttribute('ns0:duplicate-src', old_node_id)
-	    pass
-	pass
-    
     def changeObjectLabel(self,w):
 	o = self.desktop.selection.list()[0]
 	o.setAttribute("inkscape:label", self.nameEditor.get_text())
--- a/pyink/domview.py	Mon Jan 10 19:07:26 2011 +0800
+++ b/pyink/domview.py	Mon Jan 10 19:44:15 2011 +0800
@@ -293,6 +293,22 @@
     pass
 
 
+## \brief Iterator to travel a sub-tree of DOM.
+#
+def _DOM_iterator(node):
+    nodes = [node]
+    while nodes:
+	node = nodes.pop(0)
+	child = node.firstChild()
+	while child:
+	    nodes.append(child)
+	    child = child.next()
+	    pass
+	yield node
+	pass
+    pass
+
+
 ## \brief This layer provide a data view to the DOM-tree.
 #
 # This class maintains layers information, and provides functions to create,
@@ -590,5 +606,28 @@
 
     def get_max_frame(self):
 	return self._maxframe
+    
+    ## \brief Copy children of a group.
+    #
+    # Duplicate children of a group, and append them to another group.
+    #
+    def copy_group_children(self, src_group, dst_group):
+	# Search for the duplicated group
+	doc = self._doc
+	
+	dup_group = src_group.duplicate(doc)
+	for child in dup_group.childList():
+	    dup_group.removeChild(child) # prvent from crash
+	    dst_group.appendChild(child)
+	    pass
+
+	old_nodes = _DOM_iterator(src_group)
+	new_nodes = _DOM_iterator(dst_group)
+	for old_node in old_nodes:
+	    old_node_id = old_node.getAttribute('id')
+	    new_node = new_nodes.next()
+	    new_node.setAttribute('ns0:duplicate-src', old_node_id)
+	    pass
+	pass
     pass
 
--- a/pyink/domview_ui.py	Mon Jan 10 19:07:26 2011 +0800
+++ b/pyink/domview_ui.py	Mon Jan 10 19:44:15 2011 +0800
@@ -348,6 +348,7 @@
 	pass
     pass
 
+
 ## \brief Bridge of DOM-tree to syncrhonize data-model and UI.
 #
 # This class is a wrapper
@@ -564,6 +565,17 @@
 	key_tweens = self._fl_stack.get_all_key_tween_of_layer(layer_idx)
 	return key_tweens
 
+    ## \brief Copy content of a source key frame to a destinate.
+    #
+    # Copy content of the scene group of a source key frame to the
+    # scene group of a destinate key frame.
+    #
+    def copy_key_group(self, layer_idx, src_frame_idx, dst_frame_idx):
+        src_group = self.get_key_group(layer_idx, src_frame_idx)
+        dst_group = self.get_key_group(layer_idx, dst_frame_idx)
+        self._dom.copy_group_children(src_group, dst_group)
+        pass
+
     ## \brief Return widget showing frames and layers.
     #
     def get_frame_ui_widget(self):