Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / share / extensions / inkex.py
index 665575c6b67b0047a98d2f7af66ba42409b7821f..b2b59442b1febdebe7ac65751d42434acd9005cf 100755 (executable)
@@ -1,9 +1,16 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 """
 inkex.py
 A helper module for creating Inkscape extensions
 
-Copyright (C) 2005,2007 Aaron Spike, aaron@ekips.org
+Copyright (C) 2005,2010 Aaron Spike <aaron@ekips.org> and contributors
+
+Contributors:
+  AurĂ©lio A. Heckert <aurium(a)gmail.com>
+  Bulia Byak <buliabyak@users.sf.net>
+  Nicolas Dufour, nicoduf@yahoo.fr
+  Peter J. R. Moulder <pjrm@users.sourceforge.net>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -22,7 +29,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 import sys, copy, optparse, random, re
 import gettext
 from math import *
-_ = gettext.gettext
+
+gettext.install('inkscape')
+# _ = gettext.gettext
+# gettext.bindtextdomain('inkscape', '/usr/share/locale')
+# gettext.textdomain('inkscape')
 
 #a dictionary of all of the xmlns prefixes in a standard inkscape doc
 NSS = {
@@ -38,7 +49,8 @@ u'xml'      :u'http://www.w3.org/XML/1998/namespace'
 }
 
 #a dictionary of unit to user unit conversion factors
-uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0}
+uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'm':3543.3070866,
+          'km':3543307.0866, 'pc':15.0, 'yd':3240 , 'ft':1080}
 def unittouu(string):
     '''Returns userunits given a string representation of units in another system'''
     unit = re.compile('(%s)$' % '|'.join(uuconv.keys()))
@@ -62,8 +74,9 @@ def uutounit(val, unit):
 
 try:
     from lxml import etree
-except:
-    sys.exit(_('The fantastic lxml wrapper for libxml2 is required by inkex.py and therefore this extension. Please download and install the latest version from http://cheeseshop.python.org/pypi/lxml/, or install it through your package manager by a command like: sudo apt-get install python-lxml'))
+except Exception, e:
+    sys.exit(_("The fantastic lxml wrapper for libxml2 is required by inkex.py and therefore this extension. Please download and install the latest version from http://cheeseshop.python.org/pypi/lxml/, or install it through your package manager by a command like: sudo apt-get install python-lxml\n\nTechnical details:\n%s" % (e,)))
 
 def debug(what):
     sys.stderr.write(str(what) + "\n")
@@ -83,7 +96,7 @@ def errormsg(msg):
          ...
          inkex.errormsg(_("This extension requires two selected paths."))
     """
-    sys.stderr.write((str(msg) + "\n").encode("UTF-8"))
+    sys.stderr.write((unicode(msg) + "\n").encode("UTF-8"))
 
 def check_inkbool(option, opt, value):
     if str(value).capitalize() == 'True':
@@ -132,7 +145,7 @@ class Effect:
             try:
                 stream = open(file,'r')
             except:
-                stream = open(self.args[-1],'r')
+                stream = open(self.svg_file,'r')
         except:
             stream = sys.stdin
         self.document = etree.parse(stream)
@@ -174,6 +187,13 @@ class Effect:
         else:
           return None
 
+    def getParentNode(self, node):
+        for parent in self.document.getiterator():
+            if node in parent.getchildren():
+                return parent
+                break
+
+
     def getdocids(self):
         docIdNodes = self.document.xpath('//@id', namespaces=NSS)
         for m in docIdNodes:
@@ -198,6 +218,7 @@ class Effect:
 
     def affect(self, args=sys.argv[1:], output=True):
         """Affect an SVG document with a callback effect"""
+        self.svg_file = args[-1]
         self.getoptions(args)
         self.parse()
         self.getposinlayer()
@@ -223,4 +244,4 @@ class Effect:
         return retval
             
 
-# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99