From: Aurélio A. Heckert (a) Date: Fri, 5 Mar 2010 23:44:27 +0000 (-0300) Subject: Now webslicer-create-group respects the grouping hierarchy X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1cc63bdf28a8ad8cbd35712e9019df66cbb77f9b;p=inkscape.git Now webslicer-create-group respects the grouping hierarchy --- diff --git a/share/extensions/webslicer-create-group.py b/share/extensions/webslicer-create-group.py index 8a496c4ba..dcbf53fbe 100755 --- a/share/extensions/webslicer-create-group.py +++ b/share/extensions/webslicer-create-group.py @@ -49,19 +49,32 @@ class WebSlicer_CreateGroup(inkex.Effect): dest="height_unity", help="") - def effect(self): - layer = self.document.xpath( + + def get_base_elements(self): + self.layer = self.document.xpath( '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', namespaces=inkex.NSS)[0] + self.layer_descendants = self.get_descendants_in_array(self.layer) + + + def get_descendants_in_array(self, el): + descendants = el.getchildren() + for e in descendants: + descendants.extend( self.get_descendants_in_array(e) ) + return descendants + + + def effect(self): + self.get_base_elements() if len(self.selected) == 0: inkex.errormsg(_('You must to select some "Slicer rectangles" or other "Layout groups".')) exit(1) - descendants = get_descendants_in_array(layer) for id,node in self.selected.iteritems(): - if node not in descendants: + if node not in self.layer_descendants: inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id) exit(2) - g_parent = self.find_node_parent(node) + g_parent = self.getParentNode(node) + inkex.errormsg( g_parent.get('id') ) group = inkex.etree.SubElement(g_parent, 'g') desc = inkex.etree.SubElement(group, 'desc') conf_txt = '' @@ -76,18 +89,6 @@ class WebSlicer_CreateGroup(inkex.Effect): group.insert( 1, node ) - def find_node_parent(self, node): - #TODO: make it real! - return self.document.xpath( - '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', - namespaces=inkex.NSS)[0] - -def get_descendants_in_array(el): - descendants = el.getchildren() - for e in descendants: - descendants.extend( get_descendants_in_array(e) ) - return descendants - if __name__ == '__main__': e = WebSlicer_CreateGroup() e.affect()