comparison pyink/domview.py @ 1284:cbcb91b196fa

Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
author wycc
date Sat, 15 Jan 2011 02:43:20 +0800
parents 1ac921a6bd9a
children e2d2532c3115 fb44830c8a81
comparison
equal deleted inserted replaced
1283:a6aba785656e 1284:cbcb91b196fa
730 # Duplicate children of a group, and append them to another group. 730 # Duplicate children of a group, and append them to another group.
731 # 731 #
732 def copy_group_children(self, src_group, dst_group): 732 def copy_group_children(self, src_group, dst_group):
733 # Search for the duplicated group 733 # Search for the duplicated group
734 doc = self._doc 734 doc = self._doc
735
736 dup_group = src_group.duplicate(doc)
737
738 old_nodes = _DOM_iterator(src_group) 735 old_nodes = _DOM_iterator(src_group)
739 new_nodes = _DOM_iterator(dup_group)
740 new_gids = set() 736 new_gids = set()
741 for old_node in old_nodes: 737 for old_node in old_nodes:
742 old_node_id = old_node.getAttribute('id') 738 old_node_id = old_node.getAttribute('id')
743 new_node = new_nodes.next() 739 new_node = doc.createElement("svg:use")
740 new_node.setAttribute("xlink:href",'#'+old_node_id)
744 new_node.setAttribute('ns0:duplicate-src', old_node_id) 741 new_node.setAttribute('ns0:duplicate-src', old_node_id)
745 742
746 # 743 #
747 # Change ID here, or inkscape would insert the node with 744 # Change ID here, or inkscape would insert the node with
748 # the same ID, and change it later to avoid duplication. 745 # the same ID, and change it later to avoid duplication.
754 while gid in new_gids: 751 while gid in new_gids:
755 gid = self.new_id() 752 gid = self.new_id()
756 pass 753 pass
757 new_gids.add(gid) 754 new_gids.add(gid)
758 new_node.setAttribute('id', gid) 755 new_node.setAttribute('id', gid)
759 pass 756 dst_group.appendChild(new_node)
760
761 for child in dup_group.childList():
762 dup_group.removeChild(child) # prvent from crash
763 dst_group.appendChild(child)
764 pass 757 pass
765 pass 758 pass
766 pass 759 pass
767 760