summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/input.py39
-rw-r--r--lib/output.py7
-rw-r--r--lib/threads/color.py8
3 files changed, 17 insertions, 37 deletions
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index 21248dd9..99bb70ab 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -8,48 +8,29 @@ import inkex
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):
- # libembroidery likes to dump a bunch of debugging stuff to stdout
- save_stdout()
-
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=
@@ -69,4 +50,4 @@ class Input(object):
# Note: this is NOT the same as centering the design in the canvas!
layer.set('transform', 'translate(%s,%s)' % (extents[0], extents[1]))
- print >> sys.real_stdout, etree.tostring(svg)
+ print etree.tostring(svg)
diff --git a/lib/output.py b/lib/output.py
index 1c580f04..0d7f9918 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -7,13 +7,6 @@ from .utils import Point
from .svg import PIXELS_PER_MM, get_doc_size, get_viewbox_transform
-def add_thread(pattern, thread):
- """Add a thread to a pattern and return the thread's index"""
-
- libembroidery.embPattern_addThread(pattern, thread)
-
- return libembroidery.embThreadList_count(pattern.threadList) - 1
-
def get_command(stitch):
if stitch.jump:
return pyembroidery.JUMP
diff --git a/lib/threads/color.py b/lib/threads/color.py
index d94f8825..cc6c0c48 100644
--- a/lib/threads/color.py
+++ b/lib/threads/color.py
@@ -1,7 +1,7 @@
import simplestyle
import re
import colorsys
-
+from pyembroidery.EmbThread import EmbThread
class ThreadColor(object):
hex_str_re = re.compile('#([0-9a-z]{3}|[0-9a-z]{6})', re.I)
@@ -9,6 +9,12 @@ class ThreadColor(object):
def __init__(self, color, name=None, number=None, manufacturer=None):
if color is None:
self.rgb = (0, 0, 0)
+ elif isinstance(color, EmbThread):
+ self.name = color.description
+ self.number = color.catalog_number
+ self.manufacturer = color.brand
+ self.rgb = (color.get_red(), color.get_green(), color.get_blue())
+ return
elif isinstance(color, (list, tuple)):
self.rgb = tuple(color)
elif self.hex_str_re.match(color):