1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2009 Aurelio A. Heckert, aurium (a) gmail dot com
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 '''
19 import inkwebeffect, gettext
21 _ = gettext.gettext
23 class InkWebTransmitAtt(inkwebeffect.InkWebEffect):
25 def __init__(self):
26 inkwebeffect.InkWebEffect.__init__(self)
27 self.OptionParser.add_option("-a", "--att",
28 action="store", type="string",
29 dest="att", default="fill",
30 help="Attribute to transmited.")
31 self.OptionParser.add_option("-w", "--when",
32 action="store", type="string",
33 dest="when", default="onclick",
34 help="When it must to transmit?")
35 self.OptionParser.add_option("-c", "--compatibility",
36 action="store", type="string",
37 dest="compatibility", default="append",
38 help="Compatibility with previews code to this event.")
39 self.OptionParser.add_option("-t", "--from-and-to",
40 action="store", type="string",
41 dest="from_and_to", default="g-to-one",
42 help='Who transmit to Who? "g-to-one" All tramsmit to the last. "one-to-g" The first transmit to all.')
44 def effect(self):
45 self.ensureInkWebSupport()
47 if len(self.options.ids) < 2:
48 inkwebeffect.inkex.errormsg(_("You must select at least two elements."))
49 exit(1)
51 elFrom = []
52 idTo = []
53 if self.options.from_and_to == "g-to-one":
54 # All tramsmit to the last
55 for selId in self.options.ids[:-1]:
56 elFrom.append( self.selected[selId] )
57 idTo.append( self.options.ids[-1] )
58 else:
59 # The first transmit to all
60 elFrom.append( self.selected[ self.options.ids[0] ] )
61 for selId in self.options.ids[1:]:
62 idTo.append( selId )
64 evCode = "InkWeb.transmitAtt({from:this, " + \
65 "to:['"+ "','".join(idTo) +"'], " + \
66 "att:'"+ self.options.att +"'})"
68 for el in elFrom:
69 prevEvCode = el.get( self.options.when )
70 if prevEvCode == None: prevEvCode = ""
72 if self.options.compatibility == 'append':
73 elEvCode = prevEvCode +";\n"+ evCode
74 if self.options.compatibility == 'prepend':
75 elEvCode = evCode +";\n"+ prevEvCode
77 el.set( self.options.when, elEvCode )
79 if __name__ == '__main__':
80 e = InkWebTransmitAtt()
81 e.affect()