home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Inkscape / Inkscape-0.48.2-1-win32.exe / share / extensions / web-set-att.py < prev    next >
Text File  |  2011-07-08  |  3KB  |  87 lines

  1. #!/usr/bin/env python
  2. '''
  3. Copyright (C) 2009 Aurelio A. Heckert, aurium (a) gmail dot com
  4.  
  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.
  9.  
  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.
  14.  
  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
  20.  
  21. _ = gettext.gettext
  22.  
  23. class InkWebTransmitAtt(inkwebeffect.InkWebEffect):
  24.  
  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.  
  48.     def effect(self):
  49.       self.ensureInkWebSupport()
  50.  
  51.       if len(self.options.ids) < 2:
  52.         inkwebeffect.inkex.errormsg(_("You must select at least two elements."))
  53.         exit(1)
  54.  
  55.       elFrom = []
  56.       idTo = []
  57.       if self.options.from_and_to == "g-to-one":
  58.         # All set the last
  59.         for selId in self.options.ids[:-1]:
  60.           elFrom.append( self.selected[selId] )
  61.         idTo.append( self.options.ids[-1] )
  62.       else:
  63.         # The first set all
  64.         elFrom.append( self.selected[ self.options.ids[0] ] )
  65.         for selId in self.options.ids[1:]:
  66.           idTo.append( selId )
  67.  
  68.       evCode = "InkWeb.setAtt({el:['"+ "','".join(idTo) +"'], " + \
  69.                               "att:'"+ self.options.att +"', "  + \
  70.                               "val:'"+ self.options.val +"'})"
  71.  
  72.       for el in elFrom:
  73.         prevEvCode = el.get( self.options.when )
  74.         if prevEvCode == None: prevEvCode = ""
  75.  
  76.         if self.options.compatibility == 'append':
  77.           elEvCode = prevEvCode +";\n"+ evCode
  78.         if self.options.compatibility == 'prepend':
  79.           elEvCode = evCode +";\n"+ prevEvCode
  80.  
  81.         el.set( self.options.when, elEvCode )
  82.  
  83. if __name__ == '__main__':
  84.     e = InkWebTransmitAtt()
  85.     e.affect()
  86.  
  87.