diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2023-10-02 17:17:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-02 17:17:04 +0200 |
| commit | 61b76c7e8e1414039704b776f431fde5f0886fa4 (patch) | |
| tree | 794b4ebc809a17553ae59a8fc6d9089c7c7e9949 /lib | |
| parent | 327a64402e87007bb4f2375c632006153c89715d (diff) | |
Add test swatches extension (#2528)
* remove duplicates (tags)
* sort extensions (init)
* add test swatches extension
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extensions/__init__.py | 80 | ||||
| -rw-r--r-- | lib/extensions/test_swatches.py | 55 | ||||
| -rw-r--r-- | lib/svg/tags.py | 2 |
3 files changed, 96 insertions, 41 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index d0900f2d..7987a717 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -51,60 +51,62 @@ from .simulator import Simulator from .stitch_plan_preview import StitchPlanPreview from .stitch_plan_preview_undo import StitchPlanPreviewUndo from .stroke_to_lpe_satin import StrokeToLpeSatin +from .test_swatches import TestSwatches from .update_svg import UpdateSvg from .zigzag_line_to_satin import ZigzagLineToSatin from .zip import Zip from.lettering_along_path import LetteringAlongPath -__all__ = extensions = [StitchPlanPreview, - StitchPlanPreviewUndo, - DensityMap, - Install, - Params, - Print, - Input, - Output, - Zip, - Flip, - SelectionToPattern, - SelectionToGuideLine, - ObjectCommands, - ObjectCommandsToggleVisibility, - LayerCommands, - GlobalCommands, +__all__ = extensions = [ApplyThreadlist, + AutoRun, + AutoSatin, + BreakApart, + Cleanup, CommandsScaleSymbols, ConvertToSatin, - StrokeToLpeSatin, - ZigzagLineToSatin, ConvertToStroke, - JumpToStroke, - FillToStroke, CutSatin, - AutoSatin, - AutoRun, + CutworkSegmentation, + DensityMap, + DuplicateParams, + FillToStroke, + Flip, + GeneratePalette, + GlobalCommands, + GradientBlocks, + Input, + Install, + InstallCustomPalette, + JumpToStroke, + LayerCommands, Lettering, - LetteringGenerateJson, - LetteringUpdateJsonGlyphlist, - LetteringRemoveKerning, + LetteringAlongPath, LetteringCustomFontDir, LetteringForceLockStitches, - LetteringAlongPath, + LetteringGenerateJson, + LetteringRemoveKerning, + LetteringUpdateJsonGlyphlist, LettersToFont, - Troubleshoot, - RemoveEmbroiderySettings, - Cleanup, - UpdateSvg, - BreakApart, - GradientBlocks, - ApplyThreadlist, - InstallCustomPalette, - GeneratePalette, + ObjectCommands, + ObjectCommandsToggleVisibility, + Output, PaletteSplitText, PaletteToText, - Simulator, - Reorder, - DuplicateParams, + Params, Preferences, + Print, + RemoveEmbroiderySettings, + Reorder, SelectElements, - CutworkSegmentation] + SelectionToGuideLine, + SelectionToPattern, + Simulator, + StitchPlanPreview, + StitchPlanPreviewUndo, + StrokeToLpeSatin, + TestSwatches, + Troubleshoot, + UpdateSvg, + ZigzagLineToSatin, + Zip] diff --git a/lib/extensions/test_swatches.py b/lib/extensions/test_swatches.py new file mode 100644 index 00000000..a5b12d2f --- /dev/null +++ b/lib/extensions/test_swatches.py @@ -0,0 +1,55 @@ +# Authors: see git history +# +# Copyright (c) 2023 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from inkex import errormsg + +from ..i18n import _ +from ..svg.tags import EMBROIDERABLE_TAGS +from .base import InkstitchExtension + + +class TestSwatches(InkstitchExtension): + ''' + This generates swatches from selection by altering one param each time. + ''' + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) + self.arg_parser.add_argument("--options") + self.arg_parser.add_argument("--info") + + self.arg_parser.add_argument("-p", "--param", type=str, default="max_stitch_length_mm", dest="param") + self.arg_parser.add_argument("-s", "--start-value", type=float, default="max_stitch_length_mm", dest="start_value") + self.arg_parser.add_argument("-i", "--step", type=float, default="0.5", dest="step") + self.arg_parser.add_argument("-r", "--num-rows", type=int, default="5", dest="num_rows") + self.arg_parser.add_argument("-c", "--num-cols", type=int, default="5", dest="num_cols") + self.arg_parser.add_argument("-d", "--spacing", type=float, default="1", dest="spacing") + + def effect(self): + if not self.svg.selection: + errormsg(_("Please select one or more elements.")) + return + + for element in self.svg.selection: + dimensions = element.bounding_box() + param_value = self.options.start_value + for rows in range(0, self.options.num_rows): + for cols in range(0, self.options.num_cols): + new_element = element.duplicate() + translate_x = cols * dimensions.width + cols * self.options.spacing + translate_y = rows * dimensions.height + rows * self.options.spacing + new_element.transform.add_translate((translate_x, translate_y)) + if new_element.TAG == "g": + for embroidery_element in new_element.iterdescendants(EMBROIDERABLE_TAGS): + # Since this won't effect functionality, we can simply ignore the fact + # that this will also set the value to guide lines etc. + self._set_param(embroidery_element, param_value) + else: + self._set_param(new_element, param_value) + param_value += self.options.step + # remove old element + element.getparent().remove(element) + + def _set_param(self, element, value): + element.set(f'inkstitch:{ self.options.param }', value) diff --git a/lib/svg/tags.py b/lib/svg/tags.py index b99073f1..5713c399 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -98,7 +98,6 @@ inkstitch_attribs = [ 'underlay_underpath', 'underpath', 'flip', - 'expand_mm', 'clip', # stroke 'stroke_method', @@ -124,7 +123,6 @@ inkstitch_attribs = [ 'satin_method', 'short_stitch_distance_mm', 'short_stitch_inset', - 'running_stitch_length_mm', 'reverse_rails', 'swap_satin_rails', 'center_walk_underlay', |
