Code

Updated the JessyInk extensions to version 1.5.4.
[inkscape.git] / share / extensions / jessyInk_summary.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_Summary(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')
57                 inkex.NSS[u"jessyink"] = u"https://launchpad.net/jessyink"
59         def effect(self):
60                 # Check version.
61                 scriptNodes = self.document.xpath("//svg:script[@jessyink:version='1.5.4']", namespaces=inkex.NSS)
63                 if len(scriptNodes) != 1:
64                         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"))
66                 # Find the script node, if present
67                 for node in self.document.xpath("//svg:script[@id='JessyInk']", namespaces=inkex.NSS):
68                         if node.get("{" + inkex.NSS["jessyink"] + "}version"):
69                                 inkex.errormsg(_("JessyInk script version {0} installed.").format(node.get("{" + inkex.NSS["jessyink"] + "}version")))
70                         else:
71                                 inkex.errormsg(_("JessyInk script installed."))
72         
73                 slides = []
74                 masterSlide = None 
76                 for node in self.document.xpath("//svg:g[@inkscape:groupmode='layer']", namespaces=inkex.NSS):
77                         if node.get("{" + inkex.NSS["jessyink"] + "}masterSlide"):
78                                 masterSlide = node
79                         else:
80                                 slides.append(node)
82                 if masterSlide is not None:
83                         inkex.errormsg(_("\nMaster slide:"))
84                         self.describeNode(masterSlide, "\t", "<the number of the slide>", str(len(slides)), "<the title of the slide>")
86                 slideCounter = 1
88                 for slide in slides:
89                         inkex.errormsg(_("\nSlide {0!s}:").format(slideCounter))
90                         self.describeNode(slide, "\t", str(slideCounter), str(len(slides)), slide.get("{" + inkex.NSS["inkscape"] + "}label"))
91                         slideCounter += 1
93         def describeNode(self, node, prefix, slideNumber, numberOfSlides, slideTitle):
94                 inkex.errormsg(_(u"{0}Layer name: {1}").format(prefix, node.get("{" + inkex.NSS["inkscape"] + "}label")))
95                 
96                 # Display information about transitions.
97                 transitionInAttribute = node.get("{" + inkex.NSS["jessyink"] + "}transitionIn")
98                 if transitionInAttribute:
99                         transInDict = propListToDict(propStrToList(transitionInAttribute))
101                         if (transInDict["name"] != "appear") and transInDict.has_key("length"):
102                                 inkex.errormsg(_("{0}Transition in: {1} ({2!s} s)").format(prefix, transInDict["name"], int(transInDict["length"]) / 1000.0))
103                         else:
104                                 inkex.errormsg(_("{0}Transition in: {1}").format(prefix, transInDict["name"]))
106                 transitionOutAttribute = node.get("{" + inkex.NSS["jessyink"] + "}transitionOut")
107                 if transitionOutAttribute:
108                         transOutDict = propListToDict(propStrToList(transitionOutAttribute))
110                         if (transOutDict["name"] != "appear") and transOutDict.has_key("length"):
111                                 inkex.errormsg(_("{0}Transition out: {1} ({2!s} s)").format(prefix, transOutDict["name"], int(transOutDict["length"]) / 1000.0))
112                         else:
113                                 inkex.errormsg(_("{0}Transition out: {1}").format(prefix, transOutDict["name"]))
115                 # Display information about auto-texts.
116                 autoTexts = {"slideNumber" : slideNumber, "numberOfSlides" : numberOfSlides, "slideTitle" : slideTitle}
117                 autoTextNodes = node.xpath(".//*[@jessyink:autoText]", namespaces=inkex.NSS)
118                 
119                 if (len(autoTextNodes) > 0):
120                         inkex.errormsg(_("\n{0}Auto-texts:").format(prefix))
121                         
122                         for atNode in autoTextNodes:
123                                 inkex.errormsg(_("{0}\t\"{1}\" (object id \"{2}\") will be replaced by \"{3}\".").format(prefix, atNode.text, atNode.getparent().get("id"), autoTexts[atNode.get("{" + inkex.NSS["jessyink"] + "}autoText")]))
125                 # Collect information about effects.
126                 effects = {}
128                 for effectNode in node.xpath(".//*[@jessyink:effectIn]", namespaces=inkex.NSS):
129                         dictio = propListToDict(propStrToList(effectNode.get("{" + inkex.NSS["jessyink"] + "}effectIn")))
130                         dictio["direction"] = "in"
131                         dictio["id"] = effectNode.get("id")
132                         dictio["type"] = "effect"
134                         if not effects.has_key(dictio["order"]):
135                                 effects[dictio["order"]] = []
137                         effects[dictio["order"]].append(dictio)
139                 for effectNode in node.xpath(".//*[@jessyink:effectOut]", namespaces=inkex.NSS):
140                         dictio = propListToDict(propStrToList(effectNode.get("{" + inkex.NSS["jessyink"] + "}effectOut")))
141                         dictio["direction"] = "out"
142                         dictio["id"] = effectNode.get("id")
143                         dictio["type"] = "effect"
145                         if not effects.has_key(dictio["order"]):
146                                 effects[dictio["order"]] = []
148                         effects[dictio["order"]].append(dictio)
150                 for viewNode in node.xpath(".//*[@jessyink:view]", namespaces=inkex.NSS):
151                         dictio = propListToDict(propStrToList(viewNode.get("{" + inkex.NSS["jessyink"] + "}view")))
152                         dictio["id"] = viewNode.get("id")
153                         dictio["type"] = "view"
155                         if not effects.has_key(dictio["order"]):
156                                 effects[dictio["order"]] = []
158                         effects[dictio["order"]].append(dictio)
160                 order = sorted(effects.keys())
161                 orderNumber = 0
163                 # Display information about effects.
164                 for orderItem in order:
165                         tmpStr = ""
167                         if orderNumber == 0:
168                                 tmpStr += _("\n{0}Initial effect (order number {1}):").format(prefix, effects[orderItem][0]["order"])
169                         else:
170                                 tmpStr += _("\n{0}Effect {1!s} (order number {2}):").format(prefix, orderNumber, effects[orderItem][0]["order"])
171                 
172                         for item in effects[orderItem]:
173                                 if item["type"] == "view":
174                                         tmpStr += _("{0}\tView will be set according to object \"{1}\"").format(prefix, item["id"])
175                                 else:
176                                         tmpStr += _("{0}\tObject \"{1}\"").format(prefix, item["id"])
177         
178                                         if item["direction"] == "in":
179                                                 tmpStr += _(" will appear")
180                                         elif item["direction"] == "out":
181                                                 tmpStr += _(" will disappear")
182         
183                                 if item["name"] != "appear":
184                                         tmpStr += _(" using effect \"{0}\"").format(item["name"])
185                                         
186                                 if item.has_key("length"):
187                                         tmpStr += _(" in {0!s} s").format(int(item["length"]) / 1000.0)
189                                 inkex.errormsg(tmpStr + ".\n")
191                         orderNumber += 1
193 # Create effect instance
194 effect = JessyInk_Summary()
195 effect.affect()