summaryrefslogtreecommitdiffstats
path: root/share/extensions/jessyink_video.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_video.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_video.py')
-rwxr-xr-xshare/extensions/jessyink_video.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/share/extensions/jessyink_video.py b/share/extensions/jessyink_video.py
new file mode 100755
index 0000000..63b0afb
--- /dev/null
+++ b/share/extensions/jessyink_video.py
@@ -0,0 +1,96 @@
+#!/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/.
+#
+"""Add a video to the slideshow"""
+
+import re
+from copy import deepcopy
+
+import inkex
+from jessyink_install import JessyInkMixin, _
+
+
+class Video(JessyInkMixin, inkex.EffectExtension):
+ """Add jessyink video"""
+
+ def add_arguments(self, pars):
+ self.arg_parser.add_argument("--tab", dest="what")
+
+ def effect(self):
+ self.is_installed()
+ # Check version.
+ base_view = self.svg.xpath("//sodipodi:namedview[@id='base']")
+ if base_view is None:
+ raise inkex.AbortExtension(
+ _(
+ "Could not obtain the selected layer for inclusion of the video element."
+ )
+ )
+
+ layer = self.svg.get_current_layer()
+ if layer is None:
+ raise inkex.AbortExtension(
+ _(
+ "Could not obtain the selected layer for inclusion of the video element.\n\n"
+ )
+ )
+
+ template = inkex.load_svg(self.get_resource("jessyink_video.svg"))
+ root = template.getroot()
+
+ elem = layer.add(
+ root.getElement("//svg:g[@jessyink:element='core.video']").copy()
+ )
+ node_dict = find_internal_links(elem, root, {})
+ delete_ids(elem)
+
+ for node in node_dict.values():
+ elem.insert(0, node)
+
+ for node in node_dict.values():
+ node.set_id(self.svg.get_unique_id("jessyink.core.video"), backlinks=True)
+
+
+def find_internal_links(node, svg, node_dict):
+ """Get all clone links and css links"""
+ for entry in re.findall(rb"url\(#.*\)", node.tostring()):
+ entry = entry.decode()
+ link_id = entry[5 : len(entry) - 1]
+
+ if link_id not in node_dict:
+ node_dict[link_id] = deepcopy(svg.getElementById(link_id))
+ find_internal_links(node_dict[link_id], svg, node_dict)
+
+ for entry in node.iter():
+ if entry.get("xlink:href"):
+ link_id = entry.get("xlink:href")
+ if link_id not in node_dict:
+ node_dict[link_id] = deepcopy(svg.getElementById(link_id))
+ find_internal_links(node_dict[link_id], svg, node_dict)
+
+ return node_dict
+
+
+def delete_ids(node):
+ """Delete ids in the given node's children"""
+ for entry in node.iter():
+ if "id" in entry.attrib:
+ del entry.attrib["id"]
+
+
+if __name__ == "__main__":
+ Video().run()