summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ac3b0f1)
raw | patch | inline | side by side (parent: ac3b0f1)
author | aurium <aurium@users.sourceforge.net> | |
Wed, 25 Mar 2009 23:41:59 +0000 (23:41 +0000) | ||
committer | aurium <aurium@users.sourceforge.net> | |
Wed, 25 Mar 2009 23:41:59 +0000 (23:41 +0000) |
share/extensions/inkwebeffect.py | [new file with mode: 0644] | patch | blob |
share/extensions/web-transmit-att.py | patch | blob | history |
diff --git a/share/extensions/inkwebeffect.py b/share/extensions/inkwebeffect.py
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2009 Aurelio A. Heckert, aurium (a) gmail dot com
+
+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
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+'''
+
+import inkex, sys, os, re
+
+class InkWebEffect(inkex.Effect):
+ def __init__(self):
+ inkex.Effect.__init__(self)
+ self.reUpdateJS = '/\\*\\s* inkweb.js [^*]* InkWebEffect:AutoUpdate \\s*\\*/'
+
+ def mustAddInkWebJSCode(self, scriptEl):
+ if not scriptEl.text: return True
+ if len(scriptEl.text) == 0: return True
+ if re.search(self.reUpdateJS, scriptEl.text): return True
+ return False
+
+ def addInkWebJSCode(self, scriptEl):
+ js = open( os.path.join(sys.path[0], "inkweb.js"), 'r' )
+ scriptEl.text = \
+ inkex.etree.CDATA(
+ "\n/* inkweb.js - InkWebEffect:AutoUpdate */\n" + js.read()
+ )
+ js.close()
+
+ def ensureInkWebSupport(self):
+ # Search for the script tag with the inkweb.js code:
+ scriptEl = False
+ scripts = self.document.xpath('//script', namespaces=inkex.NSS)
+ for s in scripts:
+ inkex.errormsg(s)
+ if re.search(self.reUpdateJS, s.text):
+ inkex.errormsg("OK!")
+ scriptEl = s
+
+ if not scriptEl:
+ root = self.document.getroot()
+ scriptEl = inkex.etree.Element( "script" )
+ scriptEl.set( "id", "inkwebjs" )
+ scriptEl.set( "type", "text/javascript" )
+ root.insert( 0, scriptEl )
+
+ if self.mustAddInkWebJSCode(scriptEl): self.addInkWebJSCode(scriptEl)
+
index eff10f05feb85a6b930c1ae8d6848f2d873fd7cb..830085fab07b2e959a693f30b8426c3938fe8258 100644 (file)
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import inkex, sys, os
-#from lxml import etree
+import inkwebeffect, gettext
-class InterpAttG(inkex.Effect):
+_ = gettext.gettext
+
+class InkWebTransmitAtt(inkwebeffect.InkWebEffect):
def __init__(self):
- inkex.Effect.__init__(self)
+ inkwebeffect.InkWebEffect.__init__(self)
self.OptionParser.add_option("-a", "--att",
action="store", type="string",
dest="att", default="fill",
dest="compatibility", default="append",
help="Compatibility with previews code to this event.")
- def ensureInkWebSupport(self):
- if not self.document.xpath('//*[@id="inkwebjs"]', namespaces=inkex.NSS):
- root = self.document.getroot()
- scriptEl = inkex.etree.Element( "script" )
- scriptEl.set( "id", "inkwebjs" )
- scriptEl.set( "type", "text/javascript" )
- js = open( os.path.join(sys.path[0], "inkweb.js"), 'r' )
- scriptEl.text = inkex.etree.CDATA( js.read() )
- js.close()
- root.insert( 0, scriptEl )
-
def effect(self):
self.ensureInkWebSupport()
+ if len(self.options.ids) < 2:
+ inkwebeffect.inkex.errormsg(_("You must to select at least two elements."))
+ exit(1)
+
elFrom = self.selected[ self.options.ids[0] ]
idTo = self.options.ids[1]
elFrom.set( self.options.when, evCode )
if __name__ == '__main__':
- e = InterpAttG()
- e.affect()
\ No newline at end of file
+ e = InkWebTransmitAtt()
+ e.affect()
+