Code

first version of web-set-att extension
authoraurium <aurium@users.sourceforge.net>
Thu, 26 Mar 2009 23:57:32 +0000 (23:57 +0000)
committeraurium <aurium@users.sourceforge.net>
Thu, 26 Mar 2009 23:57:32 +0000 (23:57 +0000)
share/extensions/inkweb.js
share/extensions/web-set-att.inx [new file with mode: 0644]
share/extensions/web-set-att.py [new file with mode: 0755]
share/extensions/web-transmit-att.inx

index dfadd4a7f0e4d928242d54d1bbabd10a17b3d7b4..7b53153e748685d0d5d14a6bfd57bf37ea0d61b4 100644 (file)
@@ -71,7 +71,7 @@ InkWeb.transmitAtt = function (conf) {
     conf.from = document.getElementById( conf.from );
   if ( typeof(conf.to) == "string" )
     conf.to = document.getElementById( conf.to );
-  conf.att = conf.att.split( /\s+/ )
+  conf.att = conf.att.split( /\s+/ );
   for ( var i=0; i<conf.att.length; i++ ) {
     var val = this.getStyle( conf.from, conf.att[i] );
     if ( val ) {
@@ -83,3 +83,29 @@ InkWeb.transmitAtt = function (conf) {
   }
 }
 
+InkWeb.setAtt = function (conf) {
+  if ( typeof(conf.el) == "string" )
+    conf.el = document.getElementById( conf.el );
+  conf.att = conf.att.split( /\s+/ );
+  conf.val = conf.val.split( /\s+/ );
+  var att;
+  for ( var i=0; att=conf.att[i]; i++ ) {
+    if (
+         att == "width"  ||
+         att == "height" ||
+         att == "x"  ||
+         att == "y"  ||
+         att == "cx" ||
+         att == "cy" ||
+         att == "r"  ||
+         att == "rx" ||
+         att == "ry" ||
+         att == "transform"
+       ) {
+      conf.el.setAttribute( att, conf.val[i] );
+    } else {
+      this.setStyle( conf.el, att, conf.val[i] );
+    }
+  }
+}
+
diff --git a/share/extensions/web-set-att.inx b/share/extensions/web-set-att.inx
new file mode 100644 (file)
index 0000000..d9058d7
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+  <_name>Set Atributes</_name>
+  <id>org.inkscape.web.set-att</id>
+  <dependency type="executable" location="extensions">web-set-att.py</dependency>
+  <dependency type="executable" location="extensions">inkex.py</dependency>
+  <_param name="intro" 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="help" type="description">This effect sets one or more atributes in the second selected element, when a defined event occurs on the first selected element.</_param>
+  <_param name="sep2" type="description">••••••••••••••••••••••••••••••••••••••••••••••••</_param>
+  <_param name="help" type="description">If you want to set 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 set">fill stroke stroke-width</param>
+  <param name="when" type="enum" _gui-text="When the set must be done?">
+    <_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="help" type="description">The list of values must have the same size of the attributes list.</_param>
+  <param name="val" type="string" _gui-text="Value to set">red black 5px</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-set-att.py</command>
+  </script>
+</inkscape-extension>
diff --git a/share/extensions/web-set-att.py b/share/extensions/web-set-att.py
new file mode 100755 (executable)
index 0000000..520120f
--- /dev/null
@@ -0,0 +1,69 @@
+#!/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 inkwebeffect, gettext
+
+_ = gettext.gettext
+
+class InkWebTransmitAtt(inkwebeffect.InkWebEffect):
+
+    def __init__(self):
+        inkwebeffect.InkWebEffect.__init__(self)
+        self.OptionParser.add_option("-a", "--att",
+                        action="store", type="string",
+                        dest="att", default="fill",
+                        help="Attribute to set.")
+        self.OptionParser.add_option("-v", "--val",
+                        action="store", type="string",
+                        dest="val", default="red",
+                        help="Values to set.")
+        self.OptionParser.add_option("-w", "--when",
+                        action="store", type="string",
+                        dest="when", default="onclick",
+                        help="When it must to set?")
+        self.OptionParser.add_option("-c", "--compatibility",
+                        action="store", type="string",
+                        dest="compatibility", default="append",
+                        help="Compatibility with previews code to this event.")
+
+    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]
+
+      prevEvCode = elFrom.get( self.options.when )
+      if prevEvCode == None: prevEvCode = ""
+
+      evCode = "InkWeb.setAtt({el:'"+idTo+"', att:'"+self.options.att+"', val:'"+self.options.val+"'})"
+
+      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 = InkWebTransmitAtt()
+    e.affect()
+
index 9df45264b52bed8de6d00aacdb264978524669f3..5d5a52a6354a92571f08e2b5a5de839db83dd3b2 100644 (file)
@@ -4,11 +4,11 @@
   <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="intro" 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="help" 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="help" 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>
@@ -38,4 +38,4 @@
   <script>
     <command reldir="extensions" interpreter="python">web-transmit-att.py</command>
   </script>
-</inkscape-extension>
\ No newline at end of file
+</inkscape-extension>