summaryrefslogtreecommitdiffstats
path: root/share/extensions/jessyink_video.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
commit35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch)
tree657d15a03cc46bd099fc2c6546a7a4ad43815d9f /share/extensions/jessyink_video.py
parentInitial commit. (diff)
downloadinkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.tar.xz
inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.zip
Adding upstream version 1.0.2.upstream/1.0.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.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/share/extensions/jessyink_video.py b/share/extensions/jessyink_video.py
new file mode 100755
index 0000000..0b783d7
--- /dev/null
+++ b/share/extensions/jessyink_video.py
@@ -0,0 +1,83 @@
+#!/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(br"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()