Code

Updated the text of the JessyInk effect extension to make translation easier (bug...
[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 from webslicer_effect import *
21 import inkex
22 import gettext
24 _ = gettext.gettext
26 class WebSlicer_CreateGroup(WebSlicer_Effect):
28     def __init__(self):
29         WebSlicer_Effect.__init__(self)
30         self.OptionParser.add_option("--html-id",
31                         action="store", type="string",
32                         dest="html_id",
33                         help="")
34         self.OptionParser.add_option("--html-class",
35                         action="store", type="string",
36                         dest="html_class",
37                         help="")
38         self.OptionParser.add_option("--width-unity",
39                         action="store", type="string",
40                         dest="width_unity",
41                         help="")
42         self.OptionParser.add_option("--height-unity",
43                         action="store", type="string",
44                         dest="height_unity",
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("--tab",
51                         action="store", type="string",
52                         dest="tab",
53                         help="The selected UI-tab when OK was pressed")
55     def get_base_elements(self):
56         self.layer = self.get_slicer_layer()
57         if is_empty(self.layer):
58             inkex.errormsg(_('You must to create and select some "Slicer rectangles" before try to group.'))
59             exit(3)
60         self.layer_descendants = self.get_descendants_in_array(self.layer)
63     def get_descendants_in_array(self, el):
64         descendants = el.getchildren()
65         for e in descendants:
66             descendants.extend( self.get_descendants_in_array(e) )
67         return descendants
70     def effect(self):
71         self.get_base_elements()
72         if len(self.selected) == 0:
73             inkex.errormsg(_('You must to select some "Slicer rectangles" or other "Layout groups".'))
74             exit(1)
75         for id,node in self.selected.iteritems():
76             if node not in self.layer_descendants:
77                 inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id)
78                 exit(2)
79         g_parent = self.getParentNode(node)
80         group = inkex.etree.SubElement(g_parent, 'g')
81         desc = inkex.etree.SubElement(group, 'desc')
82         desc.text = self.get_conf_text_from_list(
83             [ 'html_id', 'html_class',
84               'width_unity', 'height_unity',
85               'bg_color' ] )
87         for id,node in self.selected.iteritems():
88             group.insert( 1, node )
91 if __name__ == '__main__':
92     e = WebSlicer_CreateGroup()
93     e.affect()