Code

Extensions. Fix bug in svg+media when there are special characters in the path
[inkscape.git] / share / extensions / webslicer-create-group.py
1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2010 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 '''
20 import inkex
21 import gettext
23 _ = gettext.gettext
25 def is_empty(val):
26     if val is None:
27         return True
28     else:
29         return len(str(val)) == 0
31 class WebSlicer_CreateGroup(inkex.Effect):
33     def __init__(self):
34         inkex.Effect.__init__(self)
35         self.OptionParser.add_option("--html-id",
36                                      action="store", type="string",
37                                      dest="html_id",
38                                      help="")
39         self.OptionParser.add_option("--html-class",
40                                      action="store", type="string",
41                                      dest="html_class",
42                                      help="")
43         self.OptionParser.add_option("--width-unity",
44                                      action="store", type="string",
45                                      dest="width_unity",
46                                      help="")
47         self.OptionParser.add_option("--height-unity",
48                                      action="store", type="string",
49                                      dest="height_unity",
50                                      help="")
52     def effect(self):
53         if len(self.selected) == 0:
54             inkex.errormsg(_('You must to select some "Slicer rectangles".'))
55             return
56         layer = self.document.xpath(
57                      '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]',
58                      namespaces=inkex.NSS)[0]
59         group = inkex.etree.SubElement(layer, 'g')
60         desc = inkex.etree.SubElement(group, 'desc')
61         conf_txt = ''
62         if not is_empty(self.options.html_id):
63             conf_txt += 'html-id:'    + self.options.html_class +'\n'
64         if not is_empty(self.options.html_class):
65             conf_txt += 'html-class:' + self.options.html_class +'\n'
66         conf_txt += 'width-unity:' + self.options.width_unity +'\n'
67         conf_txt += 'height-unity:' + self.options.height_unity
68         desc.text = conf_txt
69         for id,node in self.selected.iteritems():
70             group.insert( 1, node )
73 if __name__ == '__main__':
74     e = WebSlicer_CreateGroup()
75     e.affect()