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 set.")
31 self.OptionParser.add_option("-v", "--val",
32 action="store", type="string",
33 dest="val", default="red",
34 help="Values to set.")
35 self.OptionParser.add_option("-w", "--when",
36 action="store", type="string",
37 dest="when", default="onclick",
38 help="When it must to set?")
39 self.OptionParser.add_option("-c", "--compatibility",
40 action="store", type="string",
41 dest="compatibility", default="append",
42 help="Compatibility with previews code to this event.")
43 self.OptionParser.add_option("-t", "--from-and-to",
44 action="store", type="string",
45 dest="from_and_to", default="g-to-one",
46 help='Who transmit to Who? "g-to-one" All set the last. "one-to-g" The first set all.')
47 self.OptionParser.add_option("--tab",
48 action="store", type="string",
49 dest="tab",
50 help="The selected UI-tab when OK was pressed")
52 def effect(self):
53 self.ensureInkWebSupport()
55 if len(self.options.ids) < 2:
56 inkwebeffect.inkex.errormsg(_("You must select at least two elements."))
57 exit(1)
59 elFrom = []
60 idTo = []
61 if self.options.from_and_to == "g-to-one":
62 # All set the last
63 for selId in self.options.ids[:-1]:
64 elFrom.append( self.selected[selId] )
65 idTo.append( self.options.ids[-1] )
66 else:
67 # The first set all
68 elFrom.append( self.selected[ self.options.ids[0] ] )
69 for selId in self.options.ids[1:]:
70 idTo.append( selId )
72 evCode = "InkWeb.setAtt({el:['"+ "','".join(idTo) +"'], " + \
73 "att:'"+ self.options.att +"', " + \
74 "val:'"+ self.options.val +"'})"
76 for el in elFrom:
77 prevEvCode = el.get( self.options.when )
78 if prevEvCode == None: prevEvCode = ""
80 if self.options.compatibility == 'append':
81 elEvCode = prevEvCode +";\n"+ evCode
82 if self.options.compatibility == 'prepend':
83 elEvCode = evCode +";\n"+ prevEvCode
85 el.set( self.options.when, elEvCode )
87 if __name__ == '__main__':
88 e = InkWebTransmitAtt()
89 e.affect()