Code

Translations. French translation minor update.
[inkscape.git] / share / extensions / webslicer_effect.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
23 def is_empty(val):
24     if val is None:
25         return True
26     else:
27         return len(str(val)) == 0
30 class WebSlicer_Effect(inkex.Effect):
32     def __init__(self):
33         inkex.Effect.__init__(self)
35     def get_slicer_layer(self, force_creation=False):
36         # Test if webslicer-layer layer existis
37         layer = self.document.xpath(
38                      '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]',
39                      namespaces=inkex.NSS)
40         if len(layer) is 0:
41             if force_creation:
42                 # Create a new layer
43                 layer = inkex.etree.SubElement(self.document.getroot(), 'g')
44                 layer.set('id', 'webslicer-layer')
45                 layer.set(inkex.addNS('label', 'inkscape'), 'Web Slicer')
46                 layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')
47             else:
48                 layer = None
49         else:
50             layer = layer[0]
51         return layer
53     def get_conf_text_from_list(self, conf_atts):
54         conf_list = []
55         for att in conf_atts:
56             if not is_empty(getattr(self.options, att)):
57                 conf_list.append(
58                     att.replace('_','-') +': '+ str(getattr(self.options, att))
59                 )
60         return "\n".join( conf_list )