Code

Fixed const/non-const mismatch loop.
[inkscape.git] / share / extensions / jessyInk_uninstall.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
29 def propStrToList(str):
30         list = []
31         propList = str.split(";")
32         for prop in propList:
33                 if not (len(prop) == 0):
34                         list.append(prop.strip())
35         return list
37 def listToPropStr(list):
38         str = ""
39         for prop in list:
40                 str += " " + prop + ";" 
41         return str[1:]
43 class JessyInk_Uninstall(inkex.Effect):
44         def __init__(self):
45                 # Call the base class constructor.
46                 inkex.Effect.__init__(self)
48                 self.OptionParser.add_option('--tab', action = 'store', type = 'string', dest = 'what')
49                 self.OptionParser.add_option('--remove_script', action = 'store', type = 'inkbool', dest = 'remove_script', default = True)
50                 self.OptionParser.add_option('--remove_effects', action = 'store', type = 'inkbool', dest = 'remove_effects', default = True)
51                 self.OptionParser.add_option('--remove_masterSlide', action = 'store', type = 'inkbool', dest = 'remove_masterSlide', default = True)
52                 self.OptionParser.add_option('--remove_transitions', action = 'store', type = 'inkbool', dest = 'remove_transitions', default = True)
53                 self.OptionParser.add_option('--remove_autoTexts', action = 'store', type = 'inkbool', dest = 'remove_autoTexts', default = True)
54                 self.OptionParser.add_option('--remove_views', action = 'store', type = 'inkbool', dest = 'remove_views', default = True)
56                 inkex.NSS[u"jessyink"] = u"https://launchpad.net/jessyink"
58         def effect(self):
59                 # Remove script, if so desired.
60                 if self.options.remove_script:
61                         # Find and delete script node.
62                         for node in self.document.xpath("//svg:script[@id='JessyInk']", namespaces=inkex.NSS):
63                                 node.getparent().remove(node)
64                 
65                         # Remove "jessyInkInit()" in the "onload" attribute, if present.
66                         if self.document.getroot().get("onload"):
67                                 propList = propStrToList(self.document.getroot().get("onload"))
68                         else:
69                                 propList = []
70                 
71                         for prop in propList:
72                                 if prop == "jessyInkInit()":
73                                         propList.remove("jessyInkInit()")
74                 
75                         if len(propList) > 0:
76                                 self.document.getroot().set("onload", listToPropStr(propList))
77                         else:
78                                 if self.document.getroot().get("onload"):
79                                         del self.document.getroot().attrib["onload"]
81                 # Remove effect attributes, if so desired.
82                 if self.options.remove_effects:
83                         for node in self.document.xpath("//*[@jessyink:effectIn]", namespaces=inkex.NSS):
84                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}effectIn"]
86                         for node in self.document.xpath("//*[@jessyink:effectOut]", namespaces=inkex.NSS):
87                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}effectOut"]
89                         # Remove old style attributes as well.
90                         for node in self.document.xpath("//*[@jessyInk_effectIn]", namespaces=inkex.NSS):
91                                 del node.attrib["jessyInk_effectIn"]
93                         for node in self.document.xpath("//*[@jessyInk_effectOut]", namespaces=inkex.NSS):
94                                 del node.attrib["jessyInk_effectOut"]
96                 # Remove master slide assignment, if so desired.
97                 if self.options.remove_masterSlide:
98                         for node in self.document.xpath("//*[@jessyink:masterSlide]", namespaces=inkex.NSS):
99                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}masterSlide"]
101                         # Remove old style attributes as well.
102                         for node in self.document.xpath("//*[@jessyInk_masterSlide]", namespaces=inkex.NSS):
103                                 del node.attrib["jessyInk_masterSlide"]
105                 # Remove transitions, if so desired.
106                 if self.options.remove_transitions:
107                         for node in self.document.xpath("//*[@jessyink:transitionIn]", namespaces=inkex.NSS):
108                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}transitionIn"]
110                         for node in self.document.xpath("//*[@jessyink:transitionOut]", namespaces=inkex.NSS):
111                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}transitionOut"]
113                         # Remove old style attributes as well.
114                         for node in self.document.xpath("//*[@jessyInk_transitionIn]", namespaces=inkex.NSS):
115                                 del node.attrib["jessyInk_transitionIn"]
117                         for node in self.document.xpath("//*[@jessyInk_transitionOut]", namespaces=inkex.NSS):
118                                 del node.attrib["jessyInk_transitionOut"]
120                 # Remove auto texts, if so desired.
121                 if self.options.remove_autoTexts:
122                         for node in self.document.xpath("//*[@jessyink:autoText]", namespaces=inkex.NSS):
123                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}autoText"]
125                         # Remove old style attributes as well.
126                         for node in self.document.xpath("//*[@jessyInk_autoText]", namespaces=inkex.NSS):
127                                 del node.attrib["jessyInk_autoText"]
129                 # Remove views, if so desired.
130                 if self.options.remove_views:
131                         for node in self.document.xpath("//*[@jessyink:view]", namespaces=inkex.NSS):
132                                 del node.attrib["{" + inkex.NSS["jessyink"] + "}view"]
134 # Create effect instance.
135 effect = JessyInk_Uninstall()
136 effect.affect()