# HG changeset patch # User Thinker K.F. Li # Date 1296449269 -28800 # Node ID 407f321f0d7c12ffd094d734d3a03fd32018c2f2 # Parent ab281ec3eeec457919438e6835c501df384d1927 Add a svg:use after transform a group to a component diff -r ab281ec3eeec -r 407f321f0d7c pyink/MBScene.py --- a/pyink/MBScene.py Sun Jan 30 23:04:06 2011 +0800 +++ b/pyink/MBScene.py Mon Jan 31 12:47:49 2011 +0800 @@ -403,10 +403,19 @@ ## \brief To handle context menu event. # def do_make_component_from_group(self, node): + node_parent_group = node.parent() + comp_name = 'Component ' + node.getAttribute('id') self._domviewui.add_component_from_group(comp_name, node) + + self._domviewui.link_to_component(comp_name, node_parent_group) pass + ## \brief Add menu item to context menu. + # + # This method is called by pyink.pyink_context_menu() to notify the + # creation of context menu for a node. + # def context_menu(self, spitem, menu_factory): node = spitem.repr if node.name() != 'svg:g': diff -r ab281ec3eeec -r 407f321f0d7c pyink/domview.py --- a/pyink/domview.py Sun Jan 30 23:04:06 2011 +0800 +++ b/pyink/domview.py Mon Jan 31 12:47:49 2011 +0800 @@ -502,6 +502,25 @@ layer_group = self._get_group_of_component_layer(comp_name, 0) layer_group.appendChild(group) pass + + ## \brief Create a link to a component. + # + # \param parent_group is where the link will be pliaced in. + # \return link node. + # + def link_to_component(self, comp_name, parent_group): + layers_group = self._get_layers_group_of_component(comp_name) + + use_node = self._doc.createElement('svg:use') + layers_group_id = layers_group.getAttribute('id') + use_node.setAttribute('xlink:href', '#' + layers_group_id) + use_node_id = self.new_id() + use_node.setAttribute('id', use_node_id) + use_node.setAttribute('use_component', 'true') + + parent_group.appendChild(use_node) + + return use_node pass diff -r ab281ec3eeec -r 407f321f0d7c pyink/domview_ui.py --- a/pyink/domview_ui.py Sun Jan 30 23:04:06 2011 +0800 +++ b/pyink/domview_ui.py Mon Jan 31 12:47:49 2011 +0800 @@ -465,6 +465,10 @@ self.add_component(comp_name) self._dom.mv_group_to_component(group, comp_name) pass + + def link_to_component(self, comp_name, parent_group): + link_node = self._dom.link_to_component(comp_name, parent_group) + return link_node pass