diff pyink/domview.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 b241f9768833
children 45e9566ea5c0
line wrap: on
line diff
--- 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