From 904a8e1eec47cc33f95471859623cd4973039afe Mon Sep 17 00:00:00 2001 From: "Aurelio A. Heckert (a)" Date: Wed, 17 Mar 2010 18:21:54 -0300 Subject: [PATCH] webslicer: now a slicer rectangle remember it's configuration --- share/extensions/webslicer-create-group.py | 12 +++++--- share/extensions/webslicer-create-rect.py | 34 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/share/extensions/webslicer-create-group.py b/share/extensions/webslicer-create-group.py index dcbf53fbe..aadfded38 100755 --- a/share/extensions/webslicer-create-group.py +++ b/share/extensions/webslicer-create-group.py @@ -51,9 +51,14 @@ class WebSlicer_CreateGroup(inkex.Effect): def get_base_elements(self): - self.layer = self.document.xpath( - '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', - namespaces=inkex.NSS)[0] + layerArr = self.document.xpath( + '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', + namespaces=inkex.NSS) + if len(layerArr) > 0: + self.layer = layerArr[0] + else: + inkex.errormsg(_('You must to create and select some "Slicer rectangles" before try to group.')) + exit(3) self.layer_descendants = self.get_descendants_in_array(self.layer) @@ -74,7 +79,6 @@ class WebSlicer_CreateGroup(inkex.Effect): inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id) exit(2) 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 = '' diff --git a/share/extensions/webslicer-create-rect.py b/share/extensions/webslicer-create-rect.py index 9761fd3a5..957d6a8b2 100755 --- a/share/extensions/webslicer-create-rect.py +++ b/share/extensions/webslicer-create-rect.py @@ -100,7 +100,13 @@ class WebSlicer_CreateRect(inkex.Effect): self.options.name = name+'-'+num_s + def validate_options(self): + self.options.format = self.options.ensure_value('format', 'png').lower() + if not is_empty( self.options.dimension ): + self.options.dimension + def effect(self): + self.validate_options() layer = self.get_slicer_layer() #TODO: get selected elements to define location and size rect = inkex.etree.SubElement(layer, 'rect') @@ -120,7 +126,32 @@ class WebSlicer_CreateRect(inkex.Effect): conf_txt += "dpi:" + str(self.options.dpi) +"\n" if not is_empty(self.options.html_id): conf_txt += "html-id:" + self.options.html_id - desc.text = conf_txt + desc.text = "\n".join( self.get_full_conf_list() ) + + + + def get_conf_from_list(self, conf_atts): + conf_list = [] + for att in conf_atts: + if not is_empty(getattr(self.options, att)): + conf_list.append( att +':'+ str(getattr(self.options, att)) ) + return conf_list + + + def get_full_conf_list(self): + conf_list = [ 'format:'+self.options.format ] + if self.options.format == 'gif': + conf_list.extend( get_conf_from_list([ 'gif_type', 'palette_size' ]) ) + if self.options.format == 'jpg': + conf_list.extend( get_conf_from_list([ 'quality' ]) ) + conf_general_atts = [ + 'dpi', 'dimension', + 'bg_color', 'html_id', 'html_class', + 'layout_disposition', 'layout_position_anchor' + ] + conf_list.extend( get_conf_from_list(conf_general_atts) ) + return conf_list + def get_slicer_layer(self): # Test if webslicer-layer layer existis @@ -137,6 +168,7 @@ class WebSlicer_CreateRect(inkex.Effect): layer = layer[0] return layer + if __name__ == '__main__': e = WebSlicer_CreateRect() e.affect() -- 2.30.2