summaryrefslogtreecommitdiff
path: root/lib/extensions/input.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-07-25 21:39:39 -0400
committerLex Neva <github.com@lexneva.name>2018-07-25 21:39:39 -0400
commit6c5e256d73500be4674e8778d80b12c5b6228335 (patch)
tree979795c683ae5dbf683cfe53c9eece4939955246 /lib/extensions/input.py
parent5b5188ef9918d196173a4a543532c497140e639c (diff)
parentd14880db5820ce2175bda7bbe761c21fd6c454d0 (diff)
Merge remote-tracking branch 'origin/master' into lexelby-mac-build-mk2
Diffstat (limited to 'lib/extensions/input.py')
-rw-r--r--lib/extensions/input.py40
1 files changed, 10 insertions, 30 deletions
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index 251859c5..cb5ac452 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -3,49 +3,29 @@ from os.path import realpath, dirname, join as path_join
import sys
from inkex import etree
import inkex
-
-# help python find libembroidery when running in a local repo clone
-if getattr(sys, 'frozen', None) is None:
- sys.path.append(realpath(path_join(dirname(__file__), '..', '..')))
-
-from libembroidery import *
+import pyembroidery
from ..svg import PIXELS_PER_MM, render_stitch_plan
from ..svg.tags import INKSCAPE_LABEL
from ..i18n import _
-from ..stitch_plan import StitchPlan
+from ..stitch_plan import StitchPlan, ColorBlock
+from ..utils.io import save_stdout
class Input(object):
- def pattern_stitches(self, pattern):
- stitch_pointer = pattern.stitchList
- while stitch_pointer:
- yield stitch_pointer.stitch
- stitch_pointer = stitch_pointer.next
-
-
def affect(self, args):
embroidery_file = args[0]
- pattern = embPattern_create()
- embPattern_read(pattern, embroidery_file)
- embPattern_flipVertical(pattern)
+ pattern = pyembroidery.read(embroidery_file)
stitch_plan = StitchPlan()
color_block = None
- current_color = None
-
- for stitch in self.pattern_stitches(pattern):
- if stitch.color != current_color:
- thread = embThreadList_getAt(pattern.threadList, stitch.color)
- color = thread.color
- color_block = stitch_plan.new_color_block((color.r, color.g, color.b))
- current_color = stitch.color
- if not stitch.flags & END:
- color_block.add_stitch(stitch.xx * PIXELS_PER_MM, stitch.yy * PIXELS_PER_MM,
- jump=stitch.flags & JUMP,
- color_change=stitch.flags & STOP,
- trim=stitch.flags & TRIM)
+ for raw_stitches, thread in pattern.get_as_colorblocks():
+ color_block = stitch_plan.new_color_block(thread)
+ for x, y, command in raw_stitches:
+ color_block.add_stitch(x * PIXELS_PER_MM / 10.0, y * PIXELS_PER_MM / 10.0,
+ jump=(command == pyembroidery.JUMP),
+ trim=(command == pyembroidery.TRIM))
extents = stitch_plan.extents
svg = etree.Element("svg", nsmap=inkex.NSS, attrib=