diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2020-03-22 09:16:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-22 09:16:28 +0100 |
| commit | 88ba830a991ae68ee1a11c989961da78fbb3ef5c (patch) | |
| tree | edbfff0d0282edf14a581cd64978c111ebb3b3ed | |
| parent | 660c3f2cfab8112b8b5999e7896e838f1eed9106 (diff) | |
add stitch plan extension (#640)
| -rw-r--r-- | lib/extensions/__init__.py | 3 | ||||
| -rw-r--r-- | lib/extensions/stitch_plan_preview.py | 24 | ||||
| -rw-r--r-- | templates/stitch_plan_preview.inx | 15 |
3 files changed, 41 insertions, 1 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index 38276a64..cd8d79fb 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -15,10 +15,11 @@ from params import Params from print_pdf import Print from remove_embroidery_settings import RemoveEmbroiderySettings from simulate import Simulate +from stitch_plan_preview import StitchPlanPreview from zip import Zip - __all__ = extensions = [Embroider, + StitchPlanPreview, Install, Params, Print, diff --git a/lib/extensions/stitch_plan_preview.py b/lib/extensions/stitch_plan_preview.py new file mode 100644 index 00000000..b89e24a7 --- /dev/null +++ b/lib/extensions/stitch_plan_preview.py @@ -0,0 +1,24 @@ +from ..stitch_plan import patches_to_stitch_plan +from ..svg import render_stitch_plan +from .base import InkstitchExtension + + +class StitchPlanPreview(InkstitchExtension): + + def effect(self): + # delete old stitch plan + svg = self.document.getroot() + layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") + if layer is not None: + del layer[:] + + # create new stitch plan + if not self.get_elements(): + return + patches = self.elements_to_patches(self.elements) + stitch_plan = patches_to_stitch_plan(patches) + render_stitch_plan(svg, stitch_plan) + + # translate stitch plan to the right side of the canvas + layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") + layer.set('transform', 'translate(%s)' % svg.get('viewBox', '0 0 800 0').split(' ')[2]) diff --git a/templates/stitch_plan_preview.inx b/templates/stitch_plan_preview.inx new file mode 100644 index 00000000..e047af10 --- /dev/null +++ b/templates/stitch_plan_preview.inx @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <name>{% trans %}Stitch Plan Preview{% endtrans %}</name> + <id>org.inkstitch.stitch_plan_preview.{{ locale }}</id> + <param name="extension" type="string" gui-hidden="true">stitch_plan_preview</param> + <effect> + <object-type>all</object-type> + <effects-menu> + <submenu name="Ink/Stitch" /> + </effects-menu> + </effect> + <script> + {{ command_tag | safe }} + </script> +</inkscape-extension> |
