Code

quotes around command line parameters + indention fixed
authoramphi <amphi@users.sourceforge.net>
Mon, 12 Feb 2007 03:30:03 +0000 (03:30 +0000)
committeramphi <amphi@users.sourceforge.net>
Mon, 12 Feb 2007 03:30:03 +0000 (03:30 +0000)
share/extensions/g2pngs.py

index 8566175b3c5b98a0bd0574ea419c46545f1a5609..a24906a04a49e9ea0ecfc524efbf4d6437a027b1 100644 (file)
@@ -30,52 +30,52 @@ import inkex
 import sys, os, tempfile
 
 class MyEffect(inkex.Effect):
-        def __init__(self):
-                inkex.Effect.__init__(self)
-               self.OptionParser.add_option("-d", "--directory",
-                                               action="store", type="string", 
-                                               dest="directory", default=os.path.expanduser("~"),
-                                               help="Existing destination directory")
-               self.OptionParser.add_option("-l", "--layers",
-                                               action="store", type="inkbool", 
-                                               dest="layers", default=False,
-                                               help="Save layers with their groups")
-               '''self.OptionParser.add_option("-s", "--scale",
-                                               action="store", type="float", 
-                                               dest="scale", default=100,
-                                               help="Scales the group at the specified value")
-               self.OptionParser.add_option("-f", "--format",
-                                               action="store", type="string", 
-                                               dest="format", default="png",
-                                               help="Save at the specified format [only PNG implemented yet]") 
-               '''
-       def output(self):
-               pass
-       
-       def effect(self):
-               svg_file = self.args[-1]
-               node = inkex.xml.xpath.Evaluate('/svg',self.document)[0]
-               '''docname = node.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'docname').value[:-4]'''
+    def __init__(self):
+        inkex.Effect.__init__(self)
+        self.OptionParser.add_option("-d", "--directory",
+                        action="store", type="string", 
+                        dest="directory", default=os.path.expanduser("~"),
+                        help="Existing destination directory")
+        self.OptionParser.add_option("-l", "--layers",
+                        action="store", type="inkbool", 
+                        dest="layers", default=False,
+                        help="Save layers with their groups")
+        '''self.OptionParser.add_option("-s", "--scale",
+                        action="store", type="float", 
+                        dest="scale", default=100,
+                        help="Scales the group at the specified value")
+        self.OptionParser.add_option("-f", "--format",
+                        action="store", type="string", 
+                        dest="format", default="png",
+                        help="Save at the specified format [only PNG implemented yet]") 
+        '''
+    def output(self):
+        pass
+    
+    def effect(self):
+        svg_file = self.args[-1]
+        node = inkex.xml.xpath.Evaluate('/svg',self.document)[0]
+        '''docname = node.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'docname').value[:-4]'''
 
-               #create os temp dir
-               '''tmp_dir = tempfile.mkdtemp()'''
-               directory = self.options.directory
-               """area = '--export-area-canvas'"""
-               pngs = []
-               if self.options.layers:
-                       path = "/svg/*[name()='g' or @style][@id]"
-               else:
-                       path = "/svg/g/*[name()='g' or @style][@id]"
-               
-               for node in inkex.xml.xpath.Evaluate(path,self.document):
-                       id = node.attributes.getNamedItem('id').value
-                       name = "%s.png" % id
-                       filename = os.path.join(directory, name)
-                       command = "inkscape -i %s -e %s %s " % (id, filename, svg_file)
-                       f = os.popen(command,'r')
-                       f.read()
-                       f.close()
-                       pngs.append(filename)
+        #create os temp dir
+        '''tmp_dir = tempfile.mkdtemp()'''
+        directory = self.options.directory
+        """area = '--export-area-canvas'"""
+        pngs = []
+        if self.options.layers:
+            path = "/svg/*[name()='g' or @style][@id]"
+        else:
+            path = "/svg/g/*[name()='g' or @style][@id]"
+        
+        for node in inkex.xml.xpath.Evaluate(path,self.document):
+            id = node.attributes.getNamedItem('id').value
+            name = "%s.png" % id
+            filename = os.path.join(directory, name)
+            command = "inkscape -i \"%s\" -e \"%s\" \"%s\" " % (id, filename, svg_file)
+            f = os.popen(command,'r')
+            f.read()
+            f.close()
+            pngs.append(filename)
 
 e = MyEffect()
 e.affect()