From 8f412ef9896a93533d8bed10243eb3145fbd3fd6 Mon Sep 17 00:00:00 2001 From: "Aurelio A. Heckert (a)" Date: Wed, 3 Mar 2010 10:53:15 -0300 Subject: [PATCH] A little more work to Web Slicer (not usable yet) --- share/extensions/webslicer-create-group.inx | 2 +- share/extensions/webslicer-create-group.py | 28 +++++++++++++++++---- share/extensions/webslicer-create-rect.inx | 2 +- share/extensions/webslicer-create-rect.py | 20 ++++++++++++++- share/extensions/webslicer-export.inx | 2 +- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/share/extensions/webslicer-create-group.inx b/share/extensions/webslicer-create-group.inx index 683795213..b5c5b48ed 100644 --- a/share/extensions/webslicer-create-group.inx +++ b/share/extensions/webslicer-create-group.inx @@ -17,7 +17,7 @@ <_item value="percent">Percent (relative to parent size) <_item value="undefined">Undefined (relative to non-floating content size) - + all diff --git a/share/extensions/webslicer-create-group.py b/share/extensions/webslicer-create-group.py index 3c44b2cb4..8a496c4ba 100755 --- a/share/extensions/webslicer-create-group.py +++ b/share/extensions/webslicer-create-group.py @@ -50,17 +50,23 @@ class WebSlicer_CreateGroup(inkex.Effect): help="") def effect(self): - if len(self.selected) == 0: - inkex.errormsg(_('You must to select some "Slicer rectangles".')) - return layer = self.document.xpath( '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', namespaces=inkex.NSS)[0] - group = inkex.etree.SubElement(layer, 'g') + 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: + inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id) + exit(2) + g_parent = self.find_node_parent(node) + group = inkex.etree.SubElement(g_parent, 'g') desc = inkex.etree.SubElement(group, 'desc') conf_txt = '' if not is_empty(self.options.html_id): - conf_txt += 'html-id:' + self.options.html_class +'\n' + conf_txt += 'html-id:' + self.options.html_id +'\n' if not is_empty(self.options.html_class): conf_txt += 'html-class:' + self.options.html_class +'\n' conf_txt += 'width-unity:' + self.options.width_unity +'\n' @@ -70,6 +76,18 @@ 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() diff --git a/share/extensions/webslicer-create-rect.inx b/share/extensions/webslicer-create-rect.inx index 2a41ff4d8..7ac681e69 100644 --- a/share/extensions/webslicer-create-rect.inx +++ b/share/extensions/webslicer-create-rect.inx @@ -52,7 +52,7 @@ - + all diff --git a/share/extensions/webslicer-create-rect.py b/share/extensions/webslicer-create-rect.py index 2c495e7af..9761fd3a5 100755 --- a/share/extensions/webslicer-create-rect.py +++ b/share/extensions/webslicer-create-rect.py @@ -83,12 +83,30 @@ class WebSlicer_CreateRect(inkex.Effect): # inkscape param workarround self.OptionParser.add_option("--tab") + + def unique_slice_name(self): + name = self.options.name + el = self.document.xpath( '//*[@id="'+name+'"]', namespaces=inkex.NSS ) + if len(el) > 0: + if name[-3:] == '-00': name = name[:-3] + num = 0 + num_s = '00' + while len(el) > 0: + num += 1 + num_s = str(num) + if len(num_s)==1 : num_s = '0'+num_s + el = self.document.xpath( '//*[@id="'+name+'-'+num_s+'"]', + namespaces=inkex.NSS ) + self.options.name = name+'-'+num_s + + def effect(self): layer = self.get_slicer_layer() #TODO: get selected elements to define location and size rect = inkex.etree.SubElement(layer, 'rect') if is_empty(self.options.name): - self.options.name = 'rect0001' + self.options.name = 'slice-00' + self.unique_slice_name() rect.set('id', self.options.name) rect.set('fill', 'red') rect.set('opacity', '0.5') diff --git a/share/extensions/webslicer-export.inx b/share/extensions/webslicer-export.inx index 06863ece5..9f7aac323 100644 --- a/share/extensions/webslicer-export.inx +++ b/share/extensions/webslicer-export.inx @@ -7,7 +7,7 @@ <_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory. true - + all -- 2.30.2