Code

initial version of web-transmit-att effect, to add web useful fetures in svg. Not...
authoraurium <aurium@users.sourceforge.net>
Tue, 24 Mar 2009 00:23:29 +0000 (00:23 +0000)
committeraurium <aurium@users.sourceforge.net>
Tue, 24 Mar 2009 00:23:29 +0000 (00:23 +0000)
share/extensions/interp-att-g.py
share/extensions/web-transmit-att.inx [new file with mode: 0644]
share/extensions/web-transmit-att.py [new file with mode: 0644]

index dc1c36379b34465f350f74df51e94fd70fe66a45..021d7b711fbba5ca6b00b68c019aad95b19afe83 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 '''
-Copyright (C) 2005 Aurelio A. Heckert, aurium (a) gmail dot com
+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
diff --git a/share/extensions/web-transmit-att.inx b/share/extensions/web-transmit-att.inx
new file mode 100644 (file)
index 0000000..9df4526
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+  <_name>Transmit Atributes</_name>
+  <id>org.inkscape.web.transmit-att</id>
+  <dependency type="executable" location="extensions">web-transmit-att.py</dependency>
+  <dependency type="executable" location="extensions">inkex.py</dependency>
+  <_param name="intro1" type="description">This effect adds a feature visible (or usable) only on a SVG enabled web browser (like Firefox).</_param>
+  <_param name="sep1" type="description">••••••••••••••••••••••••••••••••••••••••••••••••</_param>
+  <_param name="intro2" type="description">This effect transmit one or more atributes from the first selected element to the second when a event occurs.</_param>
+  <_param name="sep2" type="description">••••••••••••••••••••••••••••••••••••••••••••••••</_param>
+  <_param name="intro2" type="description">If you want to transmit more then one attribute, you must separate this with a space, and only with a space.</_param>
+  <param name="att" type="string" _gui-text="Attribute to transmit">fill</param>
+  <param name="when" type="enum" _gui-text="When it must to transmit?">
+    <_item value="onclick">on click</_item>
+    <_item value="onfocusin">on focus</_item>
+    <_item value="onfocusout">on blur</_item>
+    <_item value="onactivate">on activate</_item>
+    <_item value="onmousedown">on mouse down</_item>
+    <_item value="onmouseup">on mouse up</_item>
+    <_item value="onmouseover">on mouse over</_item>
+    <_item value="onmousemove">on mouse move</_item>
+    <_item value="onmouseout">on mouse out</_item>
+    <_item value="onload">on element loaded</_item>
+  </param>
+  <param name="compatibility" type="enum" _gui-text="Compatibility with previews code to this event">
+    <_item value="append">Run it after</_item>
+    <_item value="prepend">Run it before</_item>
+    <_item value="replace">Replace</_item>
+  </param>
+  <effect>
+    <object-type>all</object-type>
+    <effects-menu>
+      <submenu _name="Web">
+        <submenu name="Javascript"/>
+      </submenu>
+    </effects-menu>
+  </effect>
+  <script>
+    <command reldir="extensions" interpreter="python">web-transmit-att.py</command>
+  </script>
+</inkscape-extension>
\ No newline at end of file
diff --git a/share/extensions/web-transmit-att.py b/share/extensions/web-transmit-att.py
new file mode 100644 (file)
index 0000000..eff10f0
--- /dev/null
@@ -0,0 +1,70 @@
+#!/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
+#from lxml import etree
+
+class InterpAttG(inkex.Effect):
+
+    def __init__(self):
+        inkex.Effect.__init__(self)
+        self.OptionParser.add_option("-a", "--att",
+                        action="store", type="string",
+                        dest="att", default="fill",
+                        help="Attribute to transmited.")
+        self.OptionParser.add_option("-w", "--when",
+                        action="store", type="string",
+                        dest="when", default="onclick",
+                        help="When it must to transmit?")
+        self.OptionParser.add_option("-c", "--compatibility",
+                        action="store", type="string",
+                        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()
+
+      elFrom = self.selected[ self.options.ids[0] ]
+      idTo = self.options.ids[1]
+
+      prevEvCode = elFrom.get( self.options.when )
+      if prevEvCode == None: prevEvCode = ""
+
+      evCode = "InkWeb.transmitAtt({from:this, to:'"+idTo+"', att:'"+self.options.att+"'})"
+
+      if self.options.compatibility == 'append':
+        evCode = prevEvCode +";\n"+ evCode
+      if self.options.compatibility == 'prepend':
+        evCode = evCode +";\n"+ prevEvCode
+
+      elFrom.set( self.options.when, evCode )
+
+if __name__ == '__main__':
+    e = InterpAttG()
+    e.affect()
\ No newline at end of file