diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-03-12 20:24:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-12 20:24:05 +0100 |
| commit | 78df0c73c666387c996b42dd373cd5d41abc1172 (patch) | |
| tree | a54a0e08abe0993faaeb760c0d80bba1aa3434bb /lib/extensions | |
| parent | 760c17b8156db5cbc0662d52d57902939e9e0147 (diff) | |
Add annotations to tartan stripe editor main extension file (#3567)
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/tartan.py | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/lib/extensions/tartan.py b/lib/extensions/tartan.py index c5962499..fad623af 100644 --- a/lib/extensions/tartan.py +++ b/lib/extensions/tartan.py @@ -7,6 +7,7 @@ import sys import wx import wx.adv +from inkex import ShapeElement from ..gui.abort_message import AbortMessageApp from ..gui.simulator import SplitSimulatorWindow @@ -19,53 +20,53 @@ from .base import InkstitchExtension class Tartan(InkstitchExtension): def __init__(self, *args, **kwargs): - self.elements = set() + self.nodes = set() self.cancelled = False InkstitchExtension.__init__(self, *args, **kwargs) - def cancel(self): + def cancel(self) -> None: self.cancelled = True - def get_tartan_elements(self): + def get_tartan_nodes(self) -> None: if self.svg.selection: for node in self.svg.selection: self.get_selection(node) - def get_selection(self, node): + def get_selection(self, node: ShapeElement) -> None: if node.TAG == 'g' and not node.get_id().startswith('inkstitch-tartan'): for child_node in node.iterchildren(): self.get_selection(child_node) else: node = self.get_outline(node) if node.tag in EMBROIDERABLE_TAGS and node.style('fill') is not None: - self.elements.add(node) + self.nodes.add(node) - def get_outline(self, node): - # existing tartans are marked through their outline element - # we have either selected the element itself or some other element within a tartan group + def get_outline(self, node: ShapeElement) -> ShapeElement: + # existing tartans are marked through their outline node + # we have either selected the node itself or some other nodes within a tartan group if node.get(INKSTITCH_TARTAN, None) is not None: return node if node.get_id().startswith('inkstitch-tartan'): - for element in node.iterchildren(EMBROIDERABLE_TAGS): - if element.get(INKSTITCH_TARTAN, None): - return element + for node in node.iterchildren(EMBROIDERABLE_TAGS): + if node.get(INKSTITCH_TARTAN, None): + return node for group in node.iterancestors(SVG_GROUP_TAG): if group.get_id().startswith('inkstitch-tartan'): - for element in group.iterchildren(EMBROIDERABLE_TAGS): - if element.get(INKSTITCH_TARTAN, None) is not None: - return element + for node in group.iterchildren(EMBROIDERABLE_TAGS): + if node.get(INKSTITCH_TARTAN, None) is not None: + return node # if we don't find an existing tartan, return node return node - def effect(self): - self.get_tartan_elements() + def effect(self) -> None: + self.get_tartan_nodes() - if not self.elements: - app = AbortMessageApp( + if not self.nodes: + abort = AbortMessageApp( _("To create a tartan pattern please select at least one element with a fill color."), _("https://inkstitch.org/docs/fill-tools/#tartan") ) - app.MainLoop() + abort.MainLoop() return metadata = self.get_inkstitch_metadata() @@ -75,7 +76,7 @@ class Tartan(InkstitchExtension): frame = SplitSimulatorWindow( title=_("Ink/Stitch Tartan"), panel_class=TartanMainPanel, - elements=list(self.elements), + nodes=list(self.nodes), on_cancel=self.cancel, metadata=metadata, background_color=background_color, |
