From 97580dc474a6ba6cb18c12bf3ceb4ccee2c493bc Mon Sep 17 00:00:00 2001 From: aurium Date: Wed, 25 Mar 2009 23:41:59 +0000 Subject: [PATCH] InkWeb is a fetus, but is growing... --- share/extensions/inkwebeffect.py | 59 ++++++++++++++++++++++++++++ share/extensions/web-transmit-att.py | 29 ++++++-------- 2 files changed, 71 insertions(+), 17 deletions(-) create mode 100644 share/extensions/inkwebeffect.py diff --git a/share/extensions/inkwebeffect.py b/share/extensions/inkwebeffect.py new file mode 100644 index 000000000..65176652f --- /dev/null +++ b/share/extensions/inkwebeffect.py @@ -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) + diff --git a/share/extensions/web-transmit-att.py b/share/extensions/web-transmit-att.py index eff10f05f..830085fab 100644 --- a/share/extensions/web-transmit-att.py +++ b/share/extensions/web-transmit-att.py @@ -16,13 +16,14 @@ 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 -#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", @@ -36,20 +37,13 @@ class InterpAttG(inkex.Effect): 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] @@ -66,5 +60,6 @@ class InterpAttG(inkex.Effect): elFrom.set( self.options.when, evCode ) if __name__ == '__main__': - e = InterpAttG() - e.affect() \ No newline at end of file + e = InkWebTransmitAtt() + e.affect() + -- 2.30.2