summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2025-03-12 20:24:05 +0100
committerGitHub <noreply@github.com>2025-03-12 20:24:05 +0100
commit78df0c73c666387c996b42dd373cd5d41abc1172 (patch)
treea54a0e08abe0993faaeb760c0d80bba1aa3434bb
parent760c17b8156db5cbc0662d52d57902939e9e0147 (diff)
Add annotations to tartan stripe editor main extension file (#3567)
-rw-r--r--lib/extensions/tartan.py41
-rw-r--r--lib/gui/tartan/embroidery_panel.py13
-rw-r--r--lib/gui/tartan/main_panel.py57
-rw-r--r--templates/tartan.xml2
4 files changed, 58 insertions, 55 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,
diff --git a/lib/gui/tartan/embroidery_panel.py b/lib/gui/tartan/embroidery_panel.py
index ea3f4dff..d9fe20ab 100644
--- a/lib/gui/tartan/embroidery_panel.py
+++ b/lib/gui/tartan/embroidery_panel.py
@@ -147,13 +147,14 @@ class EmbroideryPanel(wx.Panel):
if output == "svg":
self.embroidery_sizer.Show(self.svg_elements_sizer)
self.embroidery_sizer.Hide(self.embroidery_element_sizer)
- for element in self.panel.elements:
- element.pop('inkstitch:fill_method')
+ for node in self.panel.nodes:
+ node.pop('inkstitch:fill_method')
else:
self.embroidery_sizer.Show(self.embroidery_element_sizer)
self.embroidery_sizer.Hide(self.svg_elements_sizer)
- for element in self.panel.elements:
- element.set('inkstitch:fill_method', 'tartan_fill')
+ for node in self.panel.nodes:
+ node.set('inkstitch:fill_method', 'tartan_fill')
+ node.style['display'] = "inline"
self.panel.settings['output'] = output
self.Layout()
self.panel.update_preview()
@@ -180,8 +181,8 @@ class EmbroideryPanel(wx.Panel):
self.panel.update_preview()
def on_param_change(self, attribute, event):
- for element in self.panel.elements:
- element.set(f'inkstitch:{attribute}', str(event.GetEventObject().GetValue()))
+ for node in self.panel.nodes:
+ node.set(f'inkstitch:{attribute}', str(event.GetEventObject().GetValue()))
self.panel.update_preview()
def set_stitch_type(self, choice):
diff --git a/lib/gui/tartan/main_panel.py b/lib/gui/tartan/main_panel.py
index 4435f473..cd54eed1 100644
--- a/lib/gui/tartan/main_panel.py
+++ b/lib/gui/tartan/main_panel.py
@@ -9,7 +9,7 @@ from copy import copy
import wx
import wx.adv
-from ...elements import FillStitch, nodes_to_elements
+from ...elements import nodes_to_elements
from ...exceptions import InkstitchException, format_uncaught_exception
from ...i18n import _
from ...stitch_plan import stitch_groups_to_stitch_plan
@@ -25,10 +25,10 @@ from . import CodePanel, CustomizePanel, EmbroideryPanel, HelpPanel
class TartanMainPanel(wx.Panel):
- def __init__(self, parent, simulator, elements, metadata=None, background_color='white'):
+ def __init__(self, parent, simulator, nodes, metadata=None, background_color='white'):
self.parent = parent
self.simulator = simulator
- self.elements = elements
+ self.nodes = nodes
self.palette = Palette()
self.metadata = metadata or dict()
self.background_color = background_color
@@ -129,7 +129,7 @@ class TartanMainPanel(wx.Panel):
})
try:
- self.settings.update(json.loads(self.elements[0].get(INKSTITCH_TARTAN)))
+ self.settings.update(json.loads(self.nodes[0].get(INKSTITCH_TARTAN)))
except (TypeError, ValueError, IndexError):
pass
@@ -147,13 +147,13 @@ class TartanMainPanel(wx.Panel):
self.embroidery_panel.angle_weft.SetValue(self.settings.angle_weft)
self.embroidery_panel.min_stripe_width.SetValue(self.settings.min_stripe_width)
self.embroidery_panel.svg_bean_stitch_repeats.SetValue(self.settings.bean_stitch_repeats)
- self.embroidery_panel.stitch_angle.SetValue(self.elements[0].get('inkstitch:tartan_angle', -45))
- self.embroidery_panel.rows_per_thread.SetValue(self.elements[0].get('inkstitch:rows_per_thread', 2))
- self.embroidery_panel.row_spacing.SetValue(self.elements[0].get('inkstitch:row_spacing_mm', 0.25))
- underlay = self.elements[0].get('inkstitch:fill_underlay', "True").lower() in ('yes', 'y', 'true', 't', '1')
+ self.embroidery_panel.stitch_angle.SetValue(self.nodes[0].get('inkstitch:tartan_angle', -45))
+ self.embroidery_panel.rows_per_thread.SetValue(self.nodes[0].get('inkstitch:rows_per_thread', 2))
+ self.embroidery_panel.row_spacing.SetValue(self.nodes[0].get('inkstitch:row_spacing_mm', 0.25))
+ underlay = self.nodes[0].get('inkstitch:fill_underlay', "True").lower() in ('yes', 'y', 'true', 't', '1')
self.embroidery_panel.underlay.SetValue(underlay)
- self.embroidery_panel.herringbone.SetValue(self.elements[0].get('inkstitch:herringbone_width_mm', 0))
- self.embroidery_panel.bean_stitch_repeats.SetValue(self.elements[0].get('inkstitch:bean_stitch_repeats', '0'))
+ self.embroidery_panel.herringbone.SetValue(self.nodes[0].get('inkstitch:herringbone_width_mm', 0))
+ self.embroidery_panel.bean_stitch_repeats.SetValue(self.nodes[0].get('inkstitch:bean_stitch_repeats', '0'))
self.update_from_code()
@@ -163,9 +163,9 @@ class TartanMainPanel(wx.Panel):
self.customize_panel.update_warp_weft()
def save_settings(self):
- """Save the settings into the SVG elements."""
- for element in self.elements:
- element.set(INKSTITCH_TARTAN, json.dumps(self.settings))
+ """Save the settings into the SVG nodes."""
+ for node in self.nodes:
+ node.set(INKSTITCH_TARTAN, json.dumps(self.settings))
def get_preset_data(self):
# called by self.presets_panel
@@ -213,16 +213,17 @@ class TartanMainPanel(wx.Panel):
stitch_groups = self._get_svg_stitch_groups()
else:
self.save_settings()
+ elements = nodes_to_elements(self.nodes)
stitch_groups = []
previous_stitch_group = None
next_elements = [None]
- if len(self.elements) > 1:
- next_elements = self.elements[1:] + next_elements
- for element, next_element in zip(self.elements, next_elements):
+ if len(elements) > 1:
+ next_elements = elements[1:] + next_elements
+ for element, next_element in zip(elements, next_elements):
check_stop_flag()
try:
# copy the embroidery element to drop the cache
- stitch_groups.extend(copy(FillStitch(element)).embroider(previous_stitch_group, next_element))
+ stitch_groups.extend(copy(element).embroider(previous_stitch_group, next_element))
if stitch_groups:
previous_stitch_group = stitch_groups[-1]
except (SystemExit, ExitThread):
@@ -242,19 +243,19 @@ class TartanMainPanel(wx.Panel):
def _get_svg_stitch_groups(self):
stitch_groups = []
previous_stitch_group = None
- for element in self.elements:
- parent = element.getparent()
- embroidery_elements = nodes_to_elements(parent.iterdescendants())
+ for node in self.nodes:
+ parent = node.getparent()
+ elements = nodes_to_elements(parent.iterdescendants())
next_elements = [None]
- if len(embroidery_elements) > 1:
- next_elements = embroidery_elements[1:] + next_elements
- for embroidery_element, next_element in zip(embroidery_elements, next_elements):
+ if len(elements) > 1:
+ next_elements = elements[1:] + next_elements
+ for element, next_element in zip(elements, next_elements):
check_stop_flag()
- if embroidery_element.node == element:
+ if element.node == node:
continue
try:
# copy the embroidery element to drop the cache
- stitch_groups.extend(copy(embroidery_element).embroider(previous_stitch_group, next_element))
+ stitch_groups.extend(copy(element).embroider(previous_stitch_group, next_element))
if stitch_groups:
previous_stitch_group = stitch_groups[-1]
except InkstitchException:
@@ -264,12 +265,12 @@ class TartanMainPanel(wx.Panel):
return stitch_groups
def update_tartan(self):
- for element in self.elements:
+ for node in self.nodes:
check_stop_flag()
if self.settings['output'] == 'svg':
- TartanSvgGroup(self.settings).generate(element)
+ TartanSvgGroup(self.settings).generate(node)
else:
- prepare_tartan_fill_element(element)
+ prepare_tartan_fill_element(node)
def on_stitch_plan_rendered(self, stitch_plan):
self.simulator.stop()
diff --git a/templates/tartan.xml b/templates/tartan.xml
index d9719a2f..3cf83093 100644
--- a/templates/tartan.xml
+++ b/templates/tartan.xml
@@ -3,7 +3,7 @@
<name>Tartan</name>
<id>org.{{ id_inkstitch }}.tartan</id>
<param name="extension" type="string" gui-hidden="true">tartan</param>
- <effect implements-custom-gui="true">
+ <effect implements-custom-gui="true" show-stderr="true">
<object-type>all</object-type>
<icon>{{ icon_path }}inx/tartan.svg</icon>
<menu-tip>Tartan stripe editor</menu-tip>