331b2d232e913691c78778cb32f1a5696d58c8d3
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 import os
18 # These lines are only needed if you don't put the script directly into
19 # the installation directory
20 import sys
21 # Unix
22 sys.path.append('/usr/share/inkscape/extensions')
23 # OS X
24 sys.path.append('/Applications/Inkscape.app/Contents/Resources/extensions')
25 # Windows
26 sys.path.append('C:\Program Files\Inkscape\share\extensions')
28 # We will use the inkex module with the predefined Effect base class.
29 import inkex
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 listToPropStr(list):
40 str = ""
41 for prop in list:
42 str += " " + prop + ";"
43 return str[1:]
45 class JessyInk_Install(inkex.Effect):
46 def __init__(self):
47 # Call the base class constructor.
48 inkex.Effect.__init__(self)
50 self.OptionParser.add_option('--tab', action = 'store', type = 'string', dest = 'what')
52 inkex.NSS[u"jessyink"] = u"https://launchpad.net/jessyink"
54 def effect(self):
55 # Find and delete old script node
56 for node in self.document.xpath("//svg:script[@id='JessyInk']", namespaces=inkex.NSS):
57 node.getparent().remove(node)
59 # Create new script node
60 scriptElm = inkex.etree.Element(inkex.addNS("script", "svg"))
61 scriptElm.text = open(os.path.join(os.path.dirname(__file__), "jessyInk.js")).read()
62 scriptElm.set("id","JessyInk")
63 scriptElm.set("{" + inkex.NSS["jessyink"] + "}version", '1.5.4')
64 self.document.getroot().append(scriptElm)
66 # Remove "jessyInkInit()" in the "onload" attribute, if present.
67 if self.document.getroot().get("onload"):
68 propList = propStrToList(self.document.getroot().get("onload"))
69 else:
70 propList = []
72 for prop in propList:
73 if prop == "jessyInkInit()":
74 propList.remove("jessyInkInit()")
76 if len(propList) > 0:
77 self.document.getroot().set("onload", listToPropStr(propList))
78 else:
79 if self.document.getroot().get("onload"):
80 del self.document.getroot().attrib["onload"]
82 # Update effect attributes.
83 for node in self.document.xpath("//*[@jessyInk_effectIn]", namespaces=inkex.NSS):
84 node.attrib["{" + inkex.NSS["jessyink"] + "}effectIn"] = node.attrib["jessyInk_effectIn"]
85 del node.attrib["jessyInk_effectIn"]
87 for node in self.document.xpath("//*[@jessyink:effectIn]", namespaces=inkex.NSS):
88 node.attrib["{" + inkex.NSS["jessyink"] + "}effectIn"] = node.attrib["{" + inkex.NSS["jessyink"] + "}effectIn"].replace("=", ":")
90 for node in self.document.xpath("//*[@jessyInk_effectOut]", namespaces=inkex.NSS):
91 node.attrib["{" + inkex.NSS["jessyink"] + "}effectOut"] = node.attrib["jessyInk_effectOut"]
92 del node.attrib["jessyInk_effectOut"]
94 for node in self.document.xpath("//*[@jessyink:effectOut]", namespaces=inkex.NSS):
95 node.attrib["{" + inkex.NSS["jessyink"] + "}effectOut"] = node.attrib["{" + inkex.NSS["jessyink"] + "}effectOut"].replace("=", ":")
97 # Update master slide assignment.
98 for node in self.document.xpath("//*[@jessyInk_masterSlide]", namespaces=inkex.NSS):
99 node.attrib["{" + inkex.NSS["jessyink"] + "}masterSlide"] = node.attrib["jessyInk_masterSlide"]
100 del node.attrib["jessyInk_masterSlide"]
102 for node in self.document.xpath("//*[@jessyink:masterSlide]", namespaces=inkex.NSS):
103 node.attrib["{" + inkex.NSS["jessyink"] + "}masterSlide"] = node.attrib["{" + inkex.NSS["jessyink"] + "}masterSlide"].replace("=", ":")
105 # Udpate transitions.
106 for node in self.document.xpath("//*[@jessyInk_transitionIn]", namespaces=inkex.NSS):
107 node.attrib["{" + inkex.NSS["jessyink"] + "}transitionIn"] = node.attrib["jessyInk_transitionIn"]
108 del node.attrib["jessyInk_transitionIn"]
110 for node in self.document.xpath("//*[@jessyink:transitionIn]", namespaces=inkex.NSS):
111 node.attrib["{" + inkex.NSS["jessyink"] + "}transitionIn"] = node.attrib["{" + inkex.NSS["jessyink"] + "}transitionIn"].replace("=", ":")
113 for node in self.document.xpath("//*[@jessyInk_transitionOut]", namespaces=inkex.NSS):
114 node.attrib["{" + inkex.NSS["jessyink"] + "}transitionOut"] = node.attrib["jessyInk_transitionOut"]
115 del node.attrib["jessyInk_transitionOut"]
117 for node in self.document.xpath("//*[@jessyink:transitionOut]", namespaces=inkex.NSS):
118 node.attrib["{" + inkex.NSS["jessyink"] + "}transitionOut"] = node.attrib["{" + inkex.NSS["jessyink"] + "}transitionOut"].replace("=", ":")
120 # Update auto texts.
121 for node in self.document.xpath("//*[@jessyInk_autoText]", namespaces=inkex.NSS):
122 node.attrib["{" + inkex.NSS["jessyink"] + "}autoText"] = node.attrib["jessyInk_autoText"]
123 del node.attrib["jessyInk_autoText"]
125 for node in self.document.xpath("//*[@jessyink:autoText]", namespaces=inkex.NSS):
126 node.attrib["{" + inkex.NSS["jessyink"] + "}autoText"] = node.attrib["{" + inkex.NSS["jessyink"] + "}autoText"].replace("=", ":")
128 # Create effect instance
129 effect = JessyInk_Install()
130 effect.affect()