web-transmit-att.py revision b93ce4197e7f5026a1c8deeb79cbd00aa3f86d91
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith#!/usr/bin/env python
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith'''
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn SmithCopyright (C) 2009 Aurelio A. Heckert, aurium (a) gmail dot com
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn SmithThis program is free software; you can redistribute it and/or modify
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smithit under the terms of the GNU General Public License as published by
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smiththe Free Software Foundation; either version 2 of the License, or
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith(at your option) any later version.
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn SmithThis program is distributed in the hope that it will be useful,
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smithbut WITHOUT ANY WARRANTY; without even the implied warranty of
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn SmithMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn SmithGNU General Public License for more details.
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn SmithYou should have received a copy of the GNU General Public License
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smithalong with this program; if not, write to the Free Software
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn SmithFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith'''
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smithimport inkwebeffect, gettext
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith_ = gettext.gettext
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smithclass InkWebTransmitAtt(inkwebeffect.InkWebEffect):
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith def __init__(self):
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith inkwebeffect.InkWebEffect.__init__(self)
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith self.OptionParser.add_option("-a", "--att",
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith action="store", type="string",
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith dest="att", default="fill",
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith help="Attribute to transmited.")
5c45bb188ab729e501e48732842cb9de6a9813beAlex Valavanis self.OptionParser.add_option("-w", "--when",
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith action="store", type="string",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel dest="when", default="onclick",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel help="When it must to transmit?")
a4142717644b885998f4de2b27be4e8648315decMarkus Engel self.OptionParser.add_option("-c", "--compatibility",
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith action="store", type="string",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel dest="compatibility", default="append",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel help="Compatibility with previews code to this event.")
a4142717644b885998f4de2b27be4e8648315decMarkus Engel self.OptionParser.add_option("-t", "--from-and-to",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel action="store", type="string",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel dest="from_and_to", default="g-to-one",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel help='Who transmit to Who? "g-to-one" All tramsmit to the last. "one-to-g" The first transmit to all.')
a4142717644b885998f4de2b27be4e8648315decMarkus Engel self.OptionParser.add_option("--tab",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel action="store", type="string",
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith dest="tab",
a4142717644b885998f4de2b27be4e8648315decMarkus Engel help="The selected UI-tab when OK was pressed")
a4142717644b885998f4de2b27be4e8648315decMarkus Engel
a4142717644b885998f4de2b27be4e8648315decMarkus Engel def effect(self):
a4142717644b885998f4de2b27be4e8648315decMarkus Engel self.ensureInkWebSupport()
a4142717644b885998f4de2b27be4e8648315decMarkus Engel
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith if len(self.options.ids) < 2:
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith inkwebeffect.inkex.errormsg(_("You must select at least two elements."))
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith exit(1)
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith elFrom = []
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith idTo = []
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith if self.options.from_and_to == "g-to-one":
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith # All tramsmit to the last
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith for selId in self.options.ids[:-1]:
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith elFrom.append( self.selected[selId] )
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith idTo.append( self.options.ids[-1] )
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith else:
6b0fbf10b982696648debeede2b57f2b32a6a958Alex Valavanis # The first transmit to all
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith elFrom.append( self.selected[ self.options.ids[0] ] )
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith for selId in self.options.ids[1:]:
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith idTo.append( selId )
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith evCode = "InkWeb.transmitAtt({from:this, " + \
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith "to:['"+ "','".join(idTo) +"'], " + \
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith "att:'"+ self.options.att +"'})"
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith for el in elFrom:
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith prevEvCode = el.get( self.options.when )
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith if prevEvCode == None: prevEvCode = ""
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith if self.options.compatibility == 'append':
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith elEvCode = prevEvCode +";\n"+ evCode
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith if self.options.compatibility == 'prepend':
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith elEvCode = evCode +";\n"+ prevEvCode
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith el.set( self.options.when, elEvCode )
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smithif __name__ == '__main__':
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith e = InkWebTransmitAtt()
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith e.affect()
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith
2f5f997e354e7f4a02b6818bdc68fbece5cb237dJohn Smith