1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2006 Aaron Spike, aaron@ekips.org
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 TODO :
20 specify save format, scale, and if it is a layer or g export
22 RELEASE NOTE
23 - accepte l'export des calques
24 - dossier par défaut = dossier utilisateur
25 - crée le dossier spécifié s'il n'existe pas
27 '''
28 import inkex
29 import sys, os, tempfile
31 class MyEffect(inkex.Effect):
32 def __init__(self):
33 inkex.Effect.__init__(self)
34 self.OptionParser.add_option("-d", "--directory",
35 action="store", type="string",
36 dest="directory", default=os.path.expanduser("~"),
37 help="Existing destination directory")
38 self.OptionParser.add_option("-l", "--layers",
39 action="store", type="inkbool",
40 dest="layers", default=False,
41 help="Save layers with their groups")
42 '''self.OptionParser.add_option("-s", "--scale",
43 action="store", type="float",
44 dest="scale", default=100,
45 help="Scales the group at the specified value")
46 self.OptionParser.add_option("-f", "--format",
47 action="store", type="string",
48 dest="format", default="png",
49 help="Save at the specified format [only PNG implemented yet]")
50 '''
51 def output(self):
52 pass
54 def effect(self):
55 svg_file = self.args[-1]
56 node = inkex.xml.xpath.Evaluate('/svg',self.document)[0]
57 '''docname = node.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'docname').value[:-4]'''
59 #create os temp dir
60 '''tmp_dir = tempfile.mkdtemp()'''
61 directory = self.options.directory
62 """area = '--export-area-canvas'"""
63 pngs = []
64 if self.options.layers:
65 path = "/svg/*[name()='g' or @style][@id]"
66 else:
67 path = "/svg/g/*[name()='g' or @style][@id]"
69 for node in inkex.xml.xpath.Evaluate(path,self.document):
70 id = node.attributes.getNamedItem('id').value
71 name = "%s.png" % id
72 filename = os.path.join(directory, name)
73 command = "inkscape -i %s -e %s %s " % (id, filename, svg_file)
74 f = os.popen(command,'r')
75 f.read()
76 f.close()
77 pngs.append(filename)
79 e = MyEffect()
80 e.affect()