1#!/usr/local/bin/python3.8
2#
3# Copyright 2008, 2009 Hannes Hochreiner
4#
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 3 of the License, or
8# (at your option) any later version.
9#
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.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see http://www.gnu.org/licenses/.
17#
18"""Uninstall jessyInk"""
19
20import inkex
21from jessyink_install import JessyInkMixin
22
23class Uninstall(JessyInkMixin, inkex.EffectExtension):
24    """Uninstall jessyInk from this svg"""
25    def add_arguments(self, pars):
26        pars.add_argument('--tab')
27        pars.add_argument('--remove_script', type=inkex.Boolean, default=True)
28        pars.add_argument('--remove_effects', type=inkex.Boolean, default=True)
29        pars.add_argument('--remove_masterSlide', type=inkex.Boolean, default=True)
30        pars.add_argument('--remove_transitions', type=inkex.Boolean, default=True)
31        pars.add_argument('--remove_autoTexts', type=inkex.Boolean, default=True)
32        pars.add_argument('--remove_views', type=inkex.Boolean, default=True)
33
34    def effect(self):
35        # Remove script, if so desired.
36        if self.options.remove_script:
37            # Find and delete script node.
38            for node in self.svg.xpath("//svg:script[@id='JessyInk']"):
39                node.delete()
40
41            # Remove "jessyInkInit()" in the "onload" attribute, if present.
42            prop_list = []
43            if self.svg.get("onload"):
44                prop_list = self.prop_str_to_list(self.svg.get("onload"))
45
46            for prop in prop_list:
47                if prop == "jessyInkInit()":
48                    prop_list.remove("jessyInkInit()")
49
50            if prop_list:
51                self.svg.set("onload", self.list_to_prop_str(prop_list))
52            else:
53                if self.document.getroot().get("onload"):
54                    del self.document.getroot().attrib["onload"]
55
56        self.attr_remove("effectIn", self.options.remove_effects)
57        self.attr_remove("effectOut", self.options.remove_effects)
58        self.attr_remove("masterSlide", self.options.remove_masterSlide)
59        self.attr_remove("transitionIn", self.options.remove_transitions)
60        self.attr_remove("transitionOut", self.options.remove_transitions)
61        self.attr_remove("autoText", self.options.remove_autoTexts)
62        self.attr_remove("view", self.options.remove_views)
63
64
65# Create effect instance.
66if __name__ == '__main__':
67    Uninstall().run()
68