From 52d9ee6a6d97b2ea752f5fdd3080a160a3574f82 Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Wed, 30 Jun 2021 14:05:13 +0200 Subject: structuring --- lib/extensions/selection_to_pattern.py | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/extensions/selection_to_pattern.py (limited to 'lib/extensions/selection_to_pattern.py') diff --git a/lib/extensions/selection_to_pattern.py b/lib/extensions/selection_to_pattern.py new file mode 100644 index 00000000..3527cc5e --- /dev/null +++ b/lib/extensions/selection_to_pattern.py @@ -0,0 +1,61 @@ +# Authors: see git history +# +# Copyright (c) 2021 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +import inkex +from lxml import etree + +from ..i18n import _ +from ..svg.tags import SVG_DEFS_TAG +from .base import InkstitchExtension + + +class SelectionToPattern(InkstitchExtension): + + def effect(self): + if not self.get_elements(): + return + + if not self.svg.selected: + inkex.errormsg(_("Please select at least one object to be marked as a pattern.")) + return + + for pattern in self.svg.selected.values(): + self.set_marker(pattern) + + def set_marker(self, node): + xpath = ".//marker[@id='inkstitch-pattern-marker']" + pattern_marker = self.document.xpath(xpath) + + if not pattern_marker: + # get or create def element + defs = self.document.find(SVG_DEFS_TAG) + if defs is None: + defs = etree.SubElement(self.document, SVG_DEFS_TAG) + + # insert marker + marker = """ + + + + + """ # noqa: E501 + defs.append(etree.fromstring(marker)) + + # attach marker to node + style = node.get('style', '').split(";") + style = [i for i in style if not i.startswith('marker-start')] + style.append('marker-start:url(#inkstitch-pattern-marker)') + node.set('style', ";".join(style)) -- cgit v1.2.3 From a1581202646172707768d24bb5dcba63bd5d4538 Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Wed, 30 Jun 2021 16:36:25 +0200 Subject: fix selection in selection to pattern --- lib/extensions/selection_to_pattern.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/extensions/selection_to_pattern.py') diff --git a/lib/extensions/selection_to_pattern.py b/lib/extensions/selection_to_pattern.py index 3527cc5e..52a0404b 100644 --- a/lib/extensions/selection_to_pattern.py +++ b/lib/extensions/selection_to_pattern.py @@ -7,7 +7,7 @@ import inkex from lxml import etree from ..i18n import _ -from ..svg.tags import SVG_DEFS_TAG +from ..svg.tags import EMBROIDERABLE_TAGS, SVG_DEFS_TAG from .base import InkstitchExtension @@ -21,8 +21,9 @@ class SelectionToPattern(InkstitchExtension): inkex.errormsg(_("Please select at least one object to be marked as a pattern.")) return - for pattern in self.svg.selected.values(): - self.set_marker(pattern) + for pattern in self.get_nodes(): + if pattern.tag in EMBROIDERABLE_TAGS: + self.set_marker(pattern) def set_marker(self, node): xpath = ".//marker[@id='inkstitch-pattern-marker']" -- cgit v1.2.3 From a5d7ffaffd0b73b5848b7d55ea1f571ea94fd5a7 Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Wed, 7 Jul 2021 20:07:04 +0200 Subject: add or remove stitches (stroke or fill) --- lib/extensions/selection_to_pattern.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/extensions/selection_to_pattern.py') diff --git a/lib/extensions/selection_to_pattern.py b/lib/extensions/selection_to_pattern.py index 52a0404b..41f89a83 100644 --- a/lib/extensions/selection_to_pattern.py +++ b/lib/extensions/selection_to_pattern.py @@ -56,7 +56,8 @@ class SelectionToPattern(InkstitchExtension): defs.append(etree.fromstring(marker)) # attach marker to node - style = node.get('style', '').split(";") + style = node.get('style') or '' + style = style.split(";") style = [i for i in style if not i.startswith('marker-start')] style.append('marker-start:url(#inkstitch-pattern-marker)') node.set('style', ";".join(style)) -- cgit v1.2.3