summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b55ed5b)
raw | patch | inline | side by side (parent: b55ed5b)
author | aurium <aurium@users.sourceforge.net> | |
Mon, 16 Feb 2009 21:18:34 +0000 (21:18 +0000) | ||
committer | aurium <aurium@users.sourceforge.net> | |
Mon, 16 Feb 2009 21:18:34 +0000 (21:18 +0000) |
share/extensions/inkex.py | patch | blob | history |
index 0bc49153981caf03c17af16b4ddab387b36d9017..98ebf9d1fc2e3c6d8570667e8de963fbdc7653f6 100755 (executable)
"""
import sys, copy, optparse, random, re
import gettext
+from math import *
_ = gettext.gettext
#a dictionary of all of the xmlns prefixes in a standard inkscape doc
class Effect:
"""A class for creating Inkscape SVG Effects"""
+
def __init__(self, *args, **kwargs):
self.id_characters = '0123456789abcdefghijklmnopqrstuvwkyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
self.document=None
self.OptionParser.add_option("--id",
action="append", type="string", dest="ids", default=[],
help="id attribute of object to manipulate")
+
def effect(self):
pass
+
def getoptions(self,args=sys.argv[1:]):
"""Collect command line arguments"""
self.options, self.args = self.OptionParser.parse_args(args)
+
def parse(self,file=None):
"""Parse document in specified file or on stdin"""
try:
stream = sys.stdin
self.document = etree.parse(stream)
stream.close()
+
def getposinlayer(self):
#defaults
self.current_layer = self.document.getroot()
y = yattr[0]
if x and y:
self.view_center = (float(x), doc_height - float(y)) # FIXME: y-coordinate flip, eliminate it when it's gone in Inkscape
+
def getselected(self):
"""Collect selected nodes"""
for id in self.options.ids:
path = '//*[@id="%s"]' % id
for node in self.document.xpath(path, namespaces=NSS):
self.selected[id] = node
+
def getdocids(self):
docIdNodes = self.document.xpath('//@id', namespaces=NSS)
for m in docIdNodes:
self.doc_ids[m] = 1
+
+ def getNamedView(self):
+ return self.document.xpath('//sodipodi:namedview', namespaces=NSS)[0]
+
+ def createGuide(self, posX, posY, angle):
+ atts = {
+ 'position': str(posX)+','+str(posY),
+ 'orientation': str(sin(radians(angle)))+','+str(-cos(radians(angle)))
+ }
+ guide = etree.SubElement(
+ self.getNamedView(),
+ addNS('guide','sodipodi'), atts )
+ return guide
+
def output(self):
"""Serialize document into XML on stdout"""
self.document.write(sys.stdout)
+
def affect(self, args=sys.argv[1:], output=True):
"""Affect an SVG document with a callback effect"""
self.getoptions(args)
new_id = "%s%s" % (new_id,random.choice(self.id_characters))
self.doc_ids[new_id] = 1
return new_id
+
def xpathSingle(self, path):
try:
retval = self.document.xpath(path, namespaces=NSS)[0]