summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1dac100)
raw | patch | inline | side by side (parent: 1dac100)
author | amphi <amphi@users.sourceforge.net> | |
Fri, 2 Mar 2007 21:57:40 +0000 (21:57 +0000) | ||
committer | amphi <amphi@users.sourceforge.net> | |
Fri, 2 Mar 2007 21:57:40 +0000 (21:57 +0000) |
share/extensions/embedimage.py | patch | blob | history |
index 5277f0fa47cd85da2c34d68abd7e23f24e73880c..4cab6c0a907a30a812b08447320b22f7311691bd 100644 (file)
import inkex, os, base64
-class MyEffect(inkex.Effect):
+class Embedder(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option("-s", "--selectedonly",
help="embed only selected images")
def effect(self):
- ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
-
# if slectedonly is enabled and there is a selection only embed selected
# images. otherwise embed all images
if (self.options.selectedonly):
- if (self.options.ids):
- for id, node in self.selected.iteritems():
- if node.tagName == 'image':
- self.embedImage(node)
+ self.embedSelected(self.document, self.selected)
else:
- path = '//image'
- for node in inkex.xml.xpath.Evaluate(path,self.document, context=ctx):
- self.embedImage(node)
+ self.embedAll(self.document)
+
+ def embedSelected(self, document, selected):
+ self.document=document
+ self.selected=selected
+ if (self.options.ids):
+ for id, node in selected.iteritems():
+ if node.tagName == 'image':
+ self.embedImage(node)
+
+ def embedAll(self, document):
+ self.document=document #not that nice... oh well
+ ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
+ path = '//image'
+ for node in inkex.xml.xpath.Evaluate(path, self.document, context=ctx):
+ self.embedImage(node)
+
def embedImage(self, node):
xlink = node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href')
if (xlink.value[:4]!='data'):
inkex.debug("%s is not of type image/png, image/jpeg, image/bmp, image/gif or image/x-icon" % path)
else:
inkex.debug("Sorry we could not locate %s" % path)
-e = MyEffect()
-e.affect()
+
+if __name__ == '__main__':
+ e = Embedder()
+ e.affect()