summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelio A. Heckert (a) <auriumgmaildotcom>2010-03-29 21:42:38 +0000
committerAurelio A. Heckert (a) <auriumgmaildotcom>2010-03-29 21:42:38 +0000
commitfe83fef83df5cdee64b4da900197cb3c9e1b9a6e (patch)
treefb34c23a6cbee1bdf40663b07cfd0a808c60c339
parentRemove remnants of rather pointless MMX optimizations, and fix (diff)
downloadinkscape-fe83fef83df5cdee64b4da900197cb3c9e1b9a6e.tar.gz
inkscape-fe83fef83df5cdee64b4da900197cb3c9e1b9a6e.zip
webslicer: preparing to export
(bzr r9256)
-rw-r--r--share/extensions/webslicer_create_group.py19
-rwxr-xr-xshare/extensions/webslicer_create_rect.py12
-rw-r--r--share/extensions/webslicer_export.inx1
-rwxr-xr-xshare/extensions/webslicer_export.py88
4 files changed, 85 insertions, 35 deletions
diff --git a/share/extensions/webslicer_create_group.py b/share/extensions/webslicer_create_group.py
index aadfded38..666649bfb 100644
--- a/share/extensions/webslicer_create_group.py
+++ b/share/extensions/webslicer_create_group.py
@@ -17,21 +17,16 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
+from webslicer_effect import *
import inkex
import gettext
_ = gettext.gettext
-def is_empty(val):
- if val is None:
- return True
- else:
- return len(str(val)) == 0
-
-class WebSlicer_CreateGroup(inkex.Effect):
+class WebSlicer_CreateGroup(WebSlicer_Effect):
def __init__(self):
- inkex.Effect.__init__(self)
+ WebSlicer_Effect.__init__(self)
self.OptionParser.add_option("--html-id",
action="store", type="string",
dest="html_id",
@@ -51,12 +46,8 @@ class WebSlicer_CreateGroup(inkex.Effect):
def get_base_elements(self):
- layerArr = self.document.xpath(
- '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]',
- namespaces=inkex.NSS)
- if len(layerArr) > 0:
- self.layer = layerArr[0]
- else:
+ self.layer = self.get_slicer_layer()
+ if is_empty(self.layer):
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)
diff --git a/share/extensions/webslicer_create_rect.py b/share/extensions/webslicer_create_rect.py
index 8c1e5e5ac..5fd961a13 100755
--- a/share/extensions/webslicer_create_rect.py
+++ b/share/extensions/webslicer_create_rect.py
@@ -17,22 +17,16 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import webslicer_effect
+from webslicer_effect import *
import inkex
import gettext
_ = gettext.gettext
-def is_empty(val):
- if val is None:
- return True
- else:
- return len(str(val)) == 0
-
-class WebSlicer_CreateRect(webslicer_effect.WebSlicer_Effect):
+class WebSlicer_CreateRect(WebSlicer_Effect):
def __init__(self):
- webslicer_effect.WebSlicer_Effect.__init__(self)
+ WebSlicer_Effect.__init__(self)
self.OptionParser.add_option("--name",
action="store", type="string",
dest="name",
diff --git a/share/extensions/webslicer_export.inx b/share/extensions/webslicer_export.inx
index 2434c9582..3a7324370 100644
--- a/share/extensions/webslicer_export.inx
+++ b/share/extensions/webslicer_export.inx
@@ -7,6 +7,7 @@
<dependency type="executable" location="extensions">inkex.py</dependency>
<_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory.</_param>
<param name="dir" type="string" _gui-text="Directory path to export"></param>
+ <param name="create-dir" type="boolean" _gui-text="Create directory, if it does not exists">false</param>
<param name="with-code" type="boolean" _gui-text="With HTML and CSS">true</param>
<effect needs-live-preview="false">
<object-type>all</object-type>
diff --git a/share/extensions/webslicer_export.py b/share/extensions/webslicer_export.py
index 1d5057a43..e722ccb1a 100755
--- a/share/extensions/webslicer_export.py
+++ b/share/extensions/webslicer_export.py
@@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import webslicer_effect
+from webslicer_effect import *
import inkex
import gettext
import os.path
@@ -25,29 +25,93 @@ import commands
_ = gettext.gettext
-class WebSlicer_Export(webslicer_effect.WebSlicer_Effect):
+class WebSlicer_Export(WebSlicer_Effect):
def __init__(self):
- webslicer_effect.WebSlicer_Effect.__init__(self)
- self.OptionParser.add_option("--with-code",
- action="store", type="string",
- dest="with_code",
- help="")
+ WebSlicer_Effect.__init__(self)
self.OptionParser.add_option("--dir",
action="store", type="string",
dest="dir",
help="")
+ self.OptionParser.add_option("--create-dir",
+ action="store", type="inkbool",
+ default=False,
+ dest="create_dir",
+ help="")
+ self.OptionParser.add_option("--with-code",
+ action="store", type="inkbool",
+ default=False,
+ dest="with_code",
+ help="")
def effect(self):
+ # The user must supply a directory to export:
if is_empty( self.options.dir ):
inkex.errormsg(_('You must to give a directory to export the slices.'))
- return
+ return {'error':'You must to give a directory to export the slices.'}
+ # No directory separator at the path end:
+ if self.options.dir[-1] == '/' or self.options.dir[-1] == '\\':
+ self.options.dir = self.options.dir[0:-1]
+ # Test if the directory exists:
if not os.path.exists( self.options.dir ):
- inkex.errormsg(_('The directory "%s" does not exists.') % self.options.dir)
- return
+ if self.options.create_dir:
+ # Try to create it:
+ try:
+ os.makedirs( self.options.dir )
+ except Exception as e:
+ inkex.errormsg( _('Can\'t create "%s".') % self.options.dir )
+ inkex.errormsg( _('Error: %s') % e )
+ return {'error':'Can\'t create the directory to export.'}
+ else:
+ inkex.errormsg(_('The directory "%s" does not exists.') % self.options.dir)
+ return
+ # Create HTML and CSS files, if the user wants:
+ if self.options.with_code:
+ try:
+ self.html = open(os.path.join(self.options.dir,'layout.html'), 'w')
+ self.css = open(os.path.join(self.options.dir,'style.css'), 'w')
+ except Exception as e:
+ inkex.errormsg( _('Can\'t create code files.') )
+ inkex.errormsg( _('Error: %s') % e )
+ return {'error':'Can\'t create code files.'}
+ # 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()
+
+
+ def export_chids_of(self, parent):
+ nmspc = '{http://www.w3.org/2000/svg}'
+ for el in parent.getchildren():
+ if el.tag == nmspc+'g':
+ if self.options.with_code:
+ self.register_group_code( el )
+ else:
+ self.export_chids_of( el )
+ if el.tag in [ nmspc+'rect', nmspc+'path', nmspc+'circle' ]:
+ if self.options.with_code:
+ self.register_unity_code( el )
+ self.export_img( el )
+
+
+ def register_group_code(self, group):
+ #inkex.errormsg( 'group CSS and HTML' )
+ self.html.write( '<div id="G">\n' )
+ self.export_chids_of( group )
+ self.html.write( '</div><!-- end id="G" -->\n' )
+
+
+ def register_unity_code(self, el):
+ #inkex.errormsg( 'unity CSS and HTML' )
+ self.html.write( el.tag + '\n' )
+
+
+ def export_img(self, el):
(status, output) = commands.getstatusoutput("inkscape -e ...")
- inkex.errormsg( status )
- inkex.errormsg( output )
+ #inkex.errormsg( status )
+ #inkex.errormsg( output )
if __name__ == '__main__':