summaryrefslogtreecommitdiffstats
path: root/share/extensions/jessyink_uninstall.py
blob: 4bdbca076335d048c1046e45bbd6af57a14b9066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
#
# Copyright 2008, 2009 Hannes Hochreiner
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see http://www.gnu.org/licenses/.
#
"""Uninstall jessyInk"""

import inkex
from jessyink_install import JessyInkMixin


class Uninstall(JessyInkMixin, inkex.EffectExtension):
    """Uninstall jessyInk from this svg"""

    def add_arguments(self, pars):
        pars.add_argument("--tab")
        pars.add_argument("--remove_script", type=inkex.Boolean, default=True)
        pars.add_argument("--remove_effects", type=inkex.Boolean, default=True)
        pars.add_argument("--remove_masterSlide", type=inkex.Boolean, default=True)
        pars.add_argument("--remove_transitions", type=inkex.Boolean, default=True)
        pars.add_argument("--remove_autoTexts", type=inkex.Boolean, default=True)
        pars.add_argument("--remove_views", type=inkex.Boolean, default=True)

    def effect(self):
        # Remove script, if so desired.
        if self.options.remove_script:
            # Find and delete script node.
            for node in self.svg.xpath("//svg:script[@id='JessyInk']"):
                node.delete()

            # Remove "jessyInkInit()" in the "onload" attribute, if present.
            prop_list = []
            if self.svg.get("onload"):
                prop_list = self.prop_str_to_list(self.svg.get("onload"))

            for prop in prop_list:
                if prop == "jessyInkInit()":
                    prop_list.remove("jessyInkInit()")

            if prop_list:
                self.svg.set("onload", self.list_to_prop_str(prop_list))
            else:
                if self.document.getroot().get("onload"):
                    del self.document.getroot().attrib["onload"]

        self.attr_remove("effectIn", self.options.remove_effects)
        self.attr_remove("effectOut", self.options.remove_effects)
        self.attr_remove("masterSlide", self.options.remove_masterSlide)
        self.attr_remove("transitionIn", self.options.remove_transitions)
        self.attr_remove("transitionOut", self.options.remove_transitions)
        self.attr_remove("autoText", self.options.remove_autoTexts)
        self.attr_remove("view", self.options.remove_views)


# Create effect instance.
if __name__ == "__main__":
    Uninstall().run()