Code

Translations. French translation minor update.
[inkscape.git] / share / extensions / jessyInk_view.py
1 #!/usr/bin/env python
2 # Copyright 2008, 2009 Hannes Hochreiner
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see http://www.gnu.org/licenses/.
16 # These lines are only needed if you don't put the script directly into
17 # the installation directory
18 import sys
19 # Unix
20 sys.path.append('/usr/share/inkscape/extensions')
21 # OS X
22 sys.path.append('/Applications/Inkscape.app/Contents/Resources/extensions')
23 # Windows
24 sys.path.append('C:\Program Files\Inkscape\share\extensions')
26 # We will use the inkex module with the predefined Effect base class.
27 import inkex
28 import gettext
29 _ = gettext.gettext
31 def propStrToList(str):
32         list = []
33         propList = str.split(";")
34         for prop in propList:
35                 if not (len(prop) == 0):
36                         list.append(prop.strip())
37         return list
39 def propListToDict(list):
40         dictio = {}
42         for prop in list:
43                 keyValue = prop.split(":")
45                 if len(keyValue) == 2:
46                         dictio[keyValue[0].strip()] = keyValue[1].strip()
48         return dictio
50 class JessyInk_Effects(inkex.Effect):
51         def __init__(self):
52                 # Call the base class constructor.
53                 inkex.Effect.__init__(self)
55                 self.OptionParser.add_option('--tab', action = 'store', type = 'string', dest = 'what')
56                 self.OptionParser.add_option('--viewOrder', action = 'store', type = 'string', dest = 'viewOrder', default = 1)
57                 self.OptionParser.add_option('--viewDuration', action = 'store', type = 'float', dest = 'viewDuration', default = 0.8)
58                 self.OptionParser.add_option('--removeView', action = 'store', type = 'inkbool', dest = 'removeView', default = False)
60                 inkex.NSS[u"jessyink"] = u"https://launchpad.net/jessyink"
62         def effect(self):
63                 # Check version.
64                 scriptNodes = self.document.xpath("//svg:script[@jessyink:version='1.5.5']", namespaces=inkex.NSS)
66                 if len(scriptNodes) != 1:
67                         inkex.errormsg(_("The JessyInk script is not installed in this SVG file or has a different version than the JessyInk extensions. Please select \"install/update...\" from the \"JessyInk\" sub-menu of the \"Extensions\" menu to install or update the JessyInk script.\n\n"))
69                 rect = None
71                 for id, node in self.selected.items():
72                         if rect == None:
73                                 rect = node
74                         else:
75                                 inkex.errormsg(_("More than one object selected. Please select only one object.\n"))
76                                 exit()
78                 if rect == None:
79                         inkex.errormsg(_("No object selected. Please select the object you want to assign a view to and then press apply.\n"))
80                         exit()
82                 if not self.options.removeView:
83                         # Remove the view that currently has the requested order number.
84                         for node in rect.xpath("ancestor::svg:g[@inkscape:groupmode='layer']/descendant::*[@jessyink:view]", namespaces=inkex.NSS):
85                                 propDict = propListToDict(propStrToList(node.attrib["{" + inkex.NSS["jessyink"] + "}view"]))
86         
87                                 if propDict["order"] == self.options.viewOrder:
88                                         del node.attrib["{" + inkex.NSS["jessyink"] + "}view"]
89                         
90                         # Set the new view.
91                         rect.set("{" + inkex.NSS["jessyink"] + "}view","name:view;order:" + self.options.viewOrder + ";length:" + str(int(self.options.viewDuration * 1000)))
93                         # Remove possible effect arguments.
94                         if rect.attrib.has_key("{" + inkex.NSS["jessyink"] + "}effectIn"):
95                                 del rect.attrib["{" + inkex.NSS["jessyink"] + "}effectIn"]
97                         if rect.attrib.has_key("{" + inkex.NSS["jessyink"] + "}effectOut"):
98                                 del rect.attrib["{" + inkex.NSS["jessyink"] + "}effectOut"]
99                 else:
100                         if node.attrib.has_key("{" + inkex.NSS["jessyink"] + "}view"):
101                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}view"]
102                 
103 # Create effect instance
104 effect = JessyInk_Effects()
105 effect.affect()