Code

New feature: to exchange position of two objects (bug #171944)
[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="")
52     def get_base_elements(self):
53         self.layer = self.get_slicer_layer()
54         if is_empty(self.layer):
55             inkex.errormsg(_('You must to create and select some "Slicer rectangles" before try to group.'))
56             exit(3)
57         self.layer_descendants = self.get_descendants_in_array(self.layer)
60     def get_descendants_in_array(self, el):
61         descendants = el.getchildren()
62         for e in descendants:
63             descendants.extend( self.get_descendants_in_array(e) )
64         return descendants
67     def effect(self):
68         self.get_base_elements()
69         if len(self.selected) == 0:
70             inkex.errormsg(_('You must to select some "Slicer rectangles" or other "Layout groups".'))
71             exit(1)
72         for id,node in self.selected.iteritems():
73             if node not in self.layer_descendants:
74                 inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id)
75                 exit(2)
76         g_parent = self.getParentNode(node)
77         group = inkex.etree.SubElement(g_parent, 'g')
78         desc = inkex.etree.SubElement(group, 'desc')
79         desc.text = self.get_conf_text_from_list(
80             [ 'html_id', 'html_class',
81               'width_unity', 'height_unity',
82               'bg_color' ] )
84         for id,node in self.selected.iteritems():
85             group.insert( 1, node )
88 if __name__ == '__main__':
89     e = WebSlicer_CreateGroup()
90     e.affect()