Code

webslicer is starting to export image pieces
authorAurélio A. Heckert (a) <auriumgmaildotcom>
Mon, 26 Apr 2010 04:45:48 +0000 (01:45 -0300)
committerAurélio A. Heckert (a) <auriumgmaildotcom>
Mon, 26 Apr 2010 04:45:48 +0000 (01:45 -0300)
share/extensions/webslicer_create_group.inx
share/extensions/webslicer_create_group.py
share/extensions/webslicer_create_rect.inx
share/extensions/webslicer_create_rect.py
share/extensions/webslicer_effect.py
share/extensions/webslicer_export.py

index 68f63ce722028be96a1afb64c86da94d688afbca..e4bf4e310c89ceb658767d6b71e9f86354a2eb94 100644 (file)
@@ -18,6 +18,7 @@
     <_item value="percent">Percent (relative to parent size)</_item>
     <_item value="undefined">Undefined (relative to non-floating content size)</_item>
   </param>
+  <param name="bg-color" type="string" _gui-text="Background color:"></param>
   <effect needs-live-preview="false">
     <object-type>all</object-type>
     <effects-menu>
index 666649bfb04d5082ca8227f78100adf80dfdd2ad..c6f9e653e3c6f5b809a52893bf1d2810fcfa5904 100644 (file)
@@ -43,6 +43,10 @@ class WebSlicer_CreateGroup(WebSlicer_Effect):
                                      action="store", type="string",
                                      dest="height_unity",
                                      help="")
+        self.OptionParser.add_option("--bg-color",
+                                     action="store", type="string",
+                                     dest="bg_color",
+                                     help="")
 
 
     def get_base_elements(self):
@@ -72,14 +76,11 @@ class WebSlicer_CreateGroup(WebSlicer_Effect):
         g_parent = self.getParentNode(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_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'
-        conf_txt += 'height-unity:' + self.options.height_unity
-        desc.text = conf_txt
+        desc.text = self.get_conf_text_from_list(
+            [ 'html_id', 'html_class',
+              'width_unity', 'height_unity',
+              'bg_color' ] )
+
         for id,node in self.selected.iteritems():
             group.insert( 1, node )
 
index 7490953c5131cea6caa7c74df5353abec08e373c..651dda668516f63711e854d442ccb33b8c28e308 100644 (file)
       <param name="html-class" type="string" _gui-text="HTML class atribute:"></param>
       <_param name="help-gif" type="description">Options for HTML export</_param>
       <param name="layout-disposition" type="enum" _gui-text="Layout disposition:">
+        <_item value="bg-el-norepeat">Positioned html block element with the image as Background</_item>
         <_item value="bg-parent-repeat">Tiled Background (on parent group)</_item>
         <_item value="bg-parent-repeat-x">Background — repeat horizontally (on parent group)</_item>
         <_item value="bg-parent-repeat-y">Background — repeat vertically (on parent group)</_item>
         <_item value="bg-parent-norepeat">Background — no repeat (on parent group)</_item>
-        <_item value="bg-div-norepeat">Positioned &lt;div&gt; with the image as Background</_item>
         <_item value="img-pos">Positioned Image</_item>
         <_item value="img-nonpos">Non Positioned Image</_item>
         <_item value="img-float-left">Left Floated Image</_item>
       </param>
       <param name="layout-position-anchor" type="enum" _gui-text="Position anchor:">
         <_item value="tl">Top and Left</_item>
+        <_item value="tc">Top and Center</_item>
         <_item value="tr">Top and right</_item>
+        <_item value="ml">Middle and Left</_item>
+        <_item value="mc">Middle and Center</_item>
+        <_item value="mr">Middle and Right</_item>
         <_item value="bl">Bottom and Left</_item>
+        <_item value="bc">Bottom and Center</_item>
         <_item value="br">Bottom and Right</_item>
       </param>
     </page>
index 5fd961a13982afd900b7c756302df7e4b055c25a..9e916532f8d68a643bf97340d0d3a6f228c08e4a 100755 (executable)
@@ -121,30 +121,20 @@ class WebSlicer_CreateRect(WebSlicer_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 = "\n".join( self.get_full_conf_list() )
+        desc.text = self.get_conf_text_from_list( self.get_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 ]
+    def get_conf_list(self):
+        conf_list = [ 'format' ]
         if self.options.format == 'gif':
-            conf_list.extend( self.get_conf_from_list([ 'gif_type', 'palette_size' ]) )
+            conf_list.extend( [ 'gif_type', 'palette_size' ] )
         if self.options.format == 'jpg':
-            conf_list.extend( self.get_conf_from_list([ 'quality' ]) )
-        conf_general_atts = [
+            conf_list.extend( [ 'quality' ] )
+        conf_list.extend( [
                 'dpi', 'dimension',
                 'bg_color', 'html_id', 'html_class',
                 'layout_disposition', 'layout_position_anchor'
-            ]
-        conf_list.extend( self.get_conf_from_list(conf_general_atts) )
+            ] )
         return conf_list
 
 
index 37bea447b9da10083ccaeb94bdac550d1e4ba031..d91d0ce85396685dc9a9df54974771435489f90b 100644 (file)
@@ -50,3 +50,12 @@ class WebSlicer_Effect(inkex.Effect):
             layer = layer[0]
         return layer
 
+    def get_conf_text_from_list(self, conf_atts):
+        conf_list = []
+        for att in conf_atts:
+            if not is_empty(getattr(self.options, att)):
+                conf_list.append(
+                    att.replace('_','-') +': '+ str(getattr(self.options, att))
+                )
+        return "\n".join( conf_list )
+
index 3a1a38135bc9dbc192d40ef4b0f91c8c343293cc..02d049364baf7459e9ba32a99bc25d1f9a316f46 100755 (executable)
@@ -21,6 +21,7 @@ from webslicer_effect import *
 import inkex
 import gettext
 import os.path
+import tempfile
 import commands
 
 _ = gettext.gettext
@@ -76,13 +77,27 @@ class WebSlicer_Export(WebSlicer_Effect):
                 inkex.errormsg( _('Can\'t create code files.') )
                 inkex.errormsg( _('Error: %s') % e )
                 return {'error':'Can\'t create code files.'}
+        # Create the temporary SVG with invisible Slicer layer to export image pieces
+        self.create_the_temporary_svg()
         # Start what we really want!
         self.export_chids_of( self.get_slicer_layer() )
         # Close the HTML and CSS files:
         if self.options.with_code:
             self.html.close()
             self.css.close()
+        # Delete the temporary SVG with invisible Slicer layer
+        self.delete_the_temporary_svg()
 
+    def create_the_temporary_svg(self):
+        (ref, self.tmp_svg) = tempfile.mkstemp('.svg')
+        layer = self.get_slicer_layer()
+        current_style = layer.attrib['style']
+        layer.attrib['style'] = 'display:none'
+        self.document.write( self.tmp_svg );
+        layer.attrib['style'] = current_style
+
+    def delete_the_temporary_svg(self):
+        os.remove( self.tmp_svg )
 
     def get_el_conf(self, el):
         desc = el.find('{http://www.w3.org/2000/svg}desc')
@@ -129,7 +144,13 @@ class WebSlicer_Export(WebSlicer_Effect):
 
 
     def export_img(self, el, conf):
-        (status, output) = commands.getstatusoutput("inkscape -e ...")
+        (status, output) = commands.getstatusoutput(
+            "inkscape -i '%s' -e '%s' '%s'" % (
+                el.attrib['id'],
+                os.path.join( self.options.dir, el.attrib['id']+'.png' ),
+                self.tmp_svg
+            )
+        )
         #inkex.errormsg( status )
         #inkex.errormsg( output )