summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aa91d2b)
raw | patch | inline | side by side (parent: aa91d2b)
author | JazzyNico <nicoduf@yahoo.fr> | |
Fri, 1 Oct 2010 11:47:46 +0000 (13:47 +0200) | ||
committer | JazzyNico <nicoduf@yahoo.fr> | |
Fri, 1 Oct 2010 11:47:46 +0000 (13:47 +0200) |
share/extensions/gimp_xcf.py | patch | blob | history |
index 02127059c990d60953aea22fed4b59f5c1b727c3..ae62c4a3d85d6e7dd7bd8afdda0acc89dafc35cd 100755 (executable)
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
import inkex
-import sys, os, tempfile
+import sys, os, tempfile, shutil
+import gettext
try:
from subprocess import Popen, PIPE
def output(self):
pass
+ def clear_tmp(self):
+ shutil.rmtree(self.tmp_dir)
+
def effect(self):
svg_file = self.args[-1]
- docname = self.xpathSingle('/svg:svg/@sodipodi:docname')[:-4]
+ ttmp_orig = self.document.getroot()
+ docname = ttmp_orig.get(inkex.addNS('docname',u'sodipodi'))
+ if docname is None: docname = self.args[-1]
+
pageHeight = int(inkex.unittouu(self.xpathSingle('/svg:svg/@height').split('.')[0]))
pageWidth = int(inkex.unittouu(self.xpathSingle('/svg:svg/@width').split('.')[0]))
#create os temp dir
- tmp_dir = tempfile.mkdtemp()
+ self.tmp_dir = tempfile.mkdtemp()
# Guides
hGuides = []
opacity += "0"
pngs = []
names = []
+ valid = 0
path = "/svg:svg/*[name()='g' or @style][@id]"
for node in self.document.xpath(path, namespaces=inkex.NSS):
if len(node) > 0: # Get rid of empty layers
+ valid=1
id = node.get('id')
if node.get("{" + inkex.NSS["inkscape"] + "}label"):
name = node.get("{" + inkex.NSS["inkscape"] + "}label")
else:
name = id
- filename = os.path.join(tmp_dir, "%s.png" % id)
+ filename = os.path.join(self.tmp_dir, "%s.png" % id)
command = "inkscape -i %s -j %s %s -e %s %s " % (id, area, opacity, filename, svg_file)
if bsubprocess:
p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
pngs.append(filename)
names.append(name.encode('utf-8'))
+ if (valid==0):
+ inkex.errormsg(gettext.gettext('This extension requires at least one non empty layer.'))
+ self.clear_tmp()
+ sys.exit(0)
+
filelist = '"%s"' % '" "'.join(pngs)
namelist = '"%s"' % '" "'.join(names)
- xcf = os.path.join(tmp_dir, "%s.xcf" % docname)
+ xcf = os.path.join(self.tmp_dir, "%s.xcf" % docname)
if os.name == 'nt':
xcf = xcf.replace("\\", "/")
script_fu = """
(gimp-quit 0)
""" % (filelist, namelist, hGList, vGList, gridSpacingFunc, gridOriginFunc, xcf, xcf)
- junk = os.path.join(tmp_dir, 'junk_from_gimp.txt')
+ junk = os.path.join(self.tmp_dir, 'junk_from_gimp.txt')
f = os.popen('gimp -i --batch-interpreter plug-in-script-fu-eval -b - > %s 2>&1' % junk,'w')
f.write(script_fu)
f.close()
pass
sys.stdout.write(x.read())
x.close()
+ self.clear_tmp()
+
if __name__ == '__main__':
e = MyEffect()