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)
---
icons/inx/apply_attribute.svg | 119 ++++++++++++++++++++++++++++++++++++++
lib/extensions/__init__.py | 2 +
lib/extensions/apply_attribute.py | 47 +++++++++++++++
templates/apply_attribute.xml | 35 +++++++++++
4 files changed, 203 insertions(+)
create mode 100644 icons/inx/apply_attribute.svg
create mode 100644 lib/extensions/apply_attribute.py
create mode 100644 templates/apply_attribute.xml
diff --git a/icons/inx/apply_attribute.svg b/icons/inx/apply_attribute.svg
new file mode 100644
index 00000000..9280df9f
--- /dev/null
+++ b/icons/inx/apply_attribute.svg
@@ -0,0 +1,119 @@
+
+
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)
diff --git a/templates/apply_attribute.xml b/templates/apply_attribute.xml
new file mode 100644
index 00000000..ddc7e0d4
--- /dev/null
+++ b/templates/apply_attribute.xml
@@ -0,0 +1,35 @@
+
+
+ Apply attribute
+ org.{{ id_inkstitch }}.apply_attribute
+ apply_attribute
+
+ all
+ {{ icon_path }}inx/apply_attribute.svg
+ Applies a custom attribute to multiple elements
+
+
+
+
+
+
+
+
+ inkstitch
+
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
--
cgit v1.2.3