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 / webslicer_create_rect.py < prev    next >
Text File  |  2011-07-08  |  6KB  |  145 lines

  1. #!/usr/bin/env python
  2. '''
  3. Copyright (C) 2010 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.  
  20. from webslicer_effect import *
  21. import inkex
  22. import gettext
  23.  
  24. _ = gettext.gettext
  25.  
  26. class WebSlicer_CreateRect(WebSlicer_Effect):
  27.  
  28.     def __init__(self):
  29.         WebSlicer_Effect.__init__(self)
  30.         self.OptionParser.add_option("--name",
  31.                                      action="store", type="string",
  32.                                      dest="name",
  33.                                      help="")
  34.         self.OptionParser.add_option("--format",
  35.                                      action="store", type="string",
  36.                                      dest="format",
  37.                                      help="")
  38.         self.OptionParser.add_option("--dpi",
  39.                                      action="store", type="int",
  40.                                      dest="dpi",
  41.                                      help="")
  42.         self.OptionParser.add_option("--dimension",
  43.                                      action="store", type="string",
  44.                                      dest="dimension",
  45.                                      help="")
  46.         self.OptionParser.add_option("--bg-color",
  47.                                      action="store", type="string",
  48.                                      dest="bg_color",
  49.                                      help="")
  50.         self.OptionParser.add_option("--quality",
  51.                                      action="store", type="int",
  52.                                      dest="quality",
  53.                                      help="")
  54.         self.OptionParser.add_option("--gif-type",
  55.                                      action="store", type="string",
  56.                                      dest="gif_type",
  57.                                      help="")
  58.         self.OptionParser.add_option("--palette-size",
  59.                                      action="store", type="int",
  60.                                      dest="palette_size",
  61.                                      help="")
  62.         self.OptionParser.add_option("--html-id",
  63.                                      action="store", type="string",
  64.                                      dest="html_id",
  65.                                      help="")
  66.         self.OptionParser.add_option("--html-class",
  67.                                      action="store", type="string",
  68.                                      dest="html_class",
  69.                                      help="")
  70.         self.OptionParser.add_option("--layout-disposition",
  71.                                      action="store", type="string",
  72.                                      dest="layout_disposition",
  73.                                      help="")
  74.         self.OptionParser.add_option("--layout-position-anchor",
  75.                                      action="store", type="string",
  76.                                      dest="layout_position_anchor",
  77.                                      help="")
  78.         # inkscape param workarround
  79.         self.OptionParser.add_option("--tab")
  80.  
  81.  
  82.     def unique_slice_name(self):
  83.         name = self.options.name
  84.         el = self.document.xpath( '//*[@id="'+name+'"]', namespaces=inkex.NSS )
  85.         if len(el) > 0:
  86.             if name[-3:] == '-00': name = name[:-3]
  87.             num = 0
  88.             num_s = '00'
  89.             while len(el) > 0:
  90.                 num += 1
  91.                 num_s = str(num)
  92.                 if len(num_s)==1 : num_s = '0'+num_s
  93.                 el = self.document.xpath( '//*[@id="'+name+'-'+num_s+'"]',
  94.                                           namespaces=inkex.NSS )
  95.             self.options.name = name+'-'+num_s
  96.  
  97.  
  98.     def validate_options(self):
  99.         self.options.format = self.options.ensure_value('format', 'png').lower()
  100.         if not is_empty( self.options.dimension ):
  101.             self.options.dimension
  102.  
  103.     def effect(self):
  104.         self.validate_options()
  105.         layer = self.get_slicer_layer(True)
  106.         #TODO: get selected elements to define location and size
  107.         rect = inkex.etree.SubElement(layer, 'rect')
  108.         if is_empty(self.options.name):
  109.             self.options.name = 'slice-00'
  110.         self.unique_slice_name()
  111.         rect.set('id', self.options.name)
  112.         rect.set('fill', 'red')
  113.         rect.set('opacity', '0.5')
  114.         rect.set('x', '-100')
  115.         rect.set('y', '-100')
  116.         rect.set('width', '200')
  117.         rect.set('height', '200')
  118.         desc = inkex.etree.SubElement(rect, 'desc')
  119.         conf_txt = "format:"+ self.options.format +"\n"
  120.         if not is_empty(self.options.dpi):
  121.             conf_txt += "dpi:"     + str(self.options.dpi) +"\n"
  122.         if not is_empty(self.options.html_id):
  123.             conf_txt += "html-id:" + self.options.html_id
  124.         desc.text = self.get_conf_text_from_list( self.get_conf_list() )
  125.  
  126.  
  127.     def get_conf_list(self):
  128.         conf_list = [ 'format' ]
  129.         if self.options.format == 'gif':
  130.             conf_list.extend( [ 'gif_type', 'palette_size' ] )
  131.         if self.options.format == 'jpg':
  132.             conf_list.extend( [ 'quality' ] )
  133.         conf_list.extend( [
  134.                 'dpi', 'dimension',
  135.                 'bg_color', 'html_id', 'html_class',
  136.                 'layout_disposition', 'layout_position_anchor'
  137.             ] )
  138.         return conf_list
  139.  
  140.  
  141.  
  142. if __name__ == '__main__':
  143.     e = WebSlicer_CreateRect()
  144.     e.affect()
  145.