summaryrefslogtreecommitdiffstats
path: root/share/extensions/jessyink_install.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /share/extensions/jessyink_install.py
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/extensions/jessyink_install.py')
-rwxr-xr-xshare/extensions/jessyink_install.py110
1 files changed, 110 insertions, 0 deletions
diff --git a/share/extensions/jessyink_install.py b/share/extensions/jessyink_install.py
new file mode 100755
index 0000000..dee36d3
--- /dev/null
+++ b/share/extensions/jessyink_install.py
@@ -0,0 +1,110 @@
+#!/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/.
+#
+"""Install jessyInk scripts"""
+
+import inkex
+from inkex import Script
+
+from inkex.localization import inkex_gettext as _
+
+inkex.NSS["jessyink"] = "https://launchpad.net/jessyink"
+
+
+class JessyInkMixin(object):
+ """Common jessyInk items"""
+
+ def is_installed(self):
+ """Check jessyInk is installed correctly"""
+ scripts = self.svg.getElement("//svg:script[@jessyink:version='1.5.5']")
+ if scripts is None:
+ raise inkex.AbortExtension(
+ _(
+ "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"
+ )
+ )
+
+ def attr_remove(self, prop, is_removed=True):
+ """Remove a property if it exists in the svg"""
+ if is_removed:
+ for node in self.svg.xpath(f"//*[@jessyink:{prop}]"):
+ node.set(f"jessyink:{prop}", None)
+ for node in self.svg.xpath(f"//*[@jessyInk_{prop}]"):
+ node.set(f"jessyInk_{prop}", None)
+
+ def attr_update(self, name):
+ """Update a single attr"""
+ for node in self.svg.xpath(f"//*[@jessyInk_{name}]"):
+ node.set(f"jessyink:{name}", node.get(f"jessyInk_{name}"))
+ node.set(f"jessyInk_{name}", None)
+ for node in self.svg.xpath(f"//*[@jessyink:{name}]"):
+ node.set(f"jessyink:{name}", node.get(f"jessyink:{name}").replace("=", ":"))
+
+ @staticmethod
+ def prop_str_to_list(string):
+ """Script string to list of instructions"""
+ return [prop.strip() for prop in string.split(";") if prop]
+
+ @staticmethod
+ def list_to_prop_str(lst):
+ """List of instructions to script string"""
+ return "; ".join(lst) + ";"
+
+
+class Install(JessyInkMixin, inkex.EffectExtension):
+ """Install jessyInk extension into an SVG"""
+
+ def add_arguments(self, pars):
+ pars.add_argument("--tab", type=str, dest="what")
+
+ def effect(self):
+ # Find and delete old script node
+ for node in self.svg.xpath("//svg:script[@id='JessyInk']"):
+ node.getparent().remove(node)
+
+ # Create new script node
+ script_elem = Script()
+ with open(self.get_resource("jessyInk.js")) as fhl:
+ script_elem.text = fhl.read()
+ script_elem.set("id", "JessyInk")
+ script_elem.set("jessyink:version", "1.5.5")
+ self.svg.append(script_elem)
+
+ # Remove "jessyInkInit()" in the "onload" attribute, if present.
+ prop_list = [prop.strip() for prop in self.svg.get("onload", "").split(";")]
+ if "jessyInkInit()" in prop_list:
+ prop_list.remove("jessyInkInit()")
+ self.svg.set("onload", "; ".join(prop_list) or None)
+
+ # Update jessyInk attributes to new formats
+ for attr in (
+ "effectIn",
+ "effectOut",
+ "masterSlide",
+ "transitionIn",
+ "transitionOut",
+ "autoText",
+ ):
+ self.attr_update(attr)
+
+
+# Create effect instance
+if __name__ == "__main__":
+ Install().run()