From 0f95684bff102d8f573c17e806d37c35b59562d6 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:27:41 +0100 Subject: add apply attribute extension (#3983) --- lib/extensions/__init__.py | 2 ++ lib/extensions/apply_attribute.py | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 lib/extensions/apply_attribute.py (limited to 'lib/extensions') diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index f6694a90..b4a08840 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -4,6 +4,7 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. from .about import About +from .apply_attribute import ApplyAttribute from .apply_palette import ApplyPalette from .apply_threadlist import ApplyThreadlist from .auto_run import AutoRun @@ -82,6 +83,7 @@ from .zip import Zip extensions = [ About, + ApplyAttribute, ApplyPalette, ApplyThreadlist, AutoRun, diff --git a/lib/extensions/apply_attribute.py b/lib/extensions/apply_attribute.py new file mode 100644 index 00000000..0d3e30e6 --- /dev/null +++ b/lib/extensions/apply_attribute.py @@ -0,0 +1,47 @@ +# Authors: see git history +# +# Copyright (c) 2025 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from inkex import Boolean, errormsg + +from ..i18n import _ +from .base import InkstitchExtension + + +class ApplyAttribute(InkstitchExtension): + ''' + Applies a given attribute to all selected elements + ''' + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) + self.arg_parser.add_argument("--notebook") + self.arg_parser.add_argument("-n", "--namespace", dest="namespace", type=str, default='inkstitch') + self.arg_parser.add_argument("-k", "--key", dest="key", type=str, default='') + self.arg_parser.add_argument("-v", "--value", dest="value", type=str, default='') + self.arg_parser.add_argument("-r", "--remove", dest="remove", type=Boolean, default=False) + + def effect(self): + self.get_elements() + if not self.elements: + errormsg(_("Please select at least one element.")) + return + + if not self.options.key: + errormsg(_("Please enter the attribute name.")) + return + + key = '' + if self.options.namespace: + key = f'{self.options.namespace}:' + key += self.options.key + + if self.options.remove: + for element in self.elements: + element.node.pop(key) + else: + if not self.options.value: + errormsg(_("Please enter a value.")) + return + for element in self.elements: + element.node.set(key, self.options.value) -- cgit v1.2.3