summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/apply_threadlist.py47
-rw-r--r--lib/extensions/input.py8
-rw-r--r--lib/extensions/zip.py4
-rwxr-xr-xlib/inx/extensions.py2
-rwxr-xr-xlib/inx/inputs.py2
-rw-r--r--lib/inx/outputs.py8
-rw-r--r--lib/output.py18
7 files changed, 63 insertions, 26 deletions
diff --git a/lib/extensions/apply_threadlist.py b/lib/extensions/apply_threadlist.py
index 31861513..2779a901 100644
--- a/lib/extensions/apply_threadlist.py
+++ b/lib/extensions/apply_threadlist.py
@@ -8,6 +8,7 @@ import re
import sys
import inkex
+import pyembroidery
from ..i18n import _
from ..threads import ThreadCatalog
@@ -22,6 +23,8 @@ class ApplyThreadlist(InkstitchExtension):
'''
def __init__(self, *args, **kwargs):
InkstitchExtension.__init__(self, *args, **kwargs)
+ self.arg_parser.add_argument("-o", "--options", type=str, default=None, dest="page_1")
+ self.arg_parser.add_argument("-i", "--info", type=str, default=None, dest="page_2")
self.arg_parser.add_argument("-f", "--filepath", type=str, default="", dest="filepath")
self.arg_parser.add_argument("-m", "--method", type=int, default=1, dest="method")
self.arg_parser.add_argument("-t", "--palette", type=str, default=None, dest="palette")
@@ -34,26 +37,18 @@ class ApplyThreadlist(InkstitchExtension):
return
path = self.options.filepath
- if not os.path.exists(path):
- inkex.errormsg(_("File not found."))
- sys.exit(1)
- if os.path.isdir(path):
- inkex.errormsg(_("The filepath specified is not a file but a dictionary.\nPlease choose a threadlist file to import."))
- sys.exit(1)
+ self.verify_path(path)
method = self.options.method
- if method == 1:
+
+ if path.endswith(('col', 'inf', 'edr')):
+ colors = self.parse_color_format(path)
+ elif method == 1:
colors = self.parse_inkstitch_threadlist(path)
else:
colors = self.parse_threadlist_by_catalog_number(path)
- if all(c is None for c in colors):
- inkex.errormsg(_("Couldn't find any matching colors in the file."))
- if method == 1:
- inkex.errormsg(_('Please try to import as "other threadlist" and specify a color palette below.'))
- else:
- inkex.errormsg(_("Please chose an other color palette for your design."))
- sys.exit(1)
+ self.verify_colors(colors, method)
# Iterate through the color blocks to apply colors
element_color = ""
@@ -70,6 +65,23 @@ class ApplyThreadlist(InkstitchExtension):
style = element.node.get('style').replace("%s" % element_color, "%s" % colors[i])
element.node.set('style', style)
+ def verify_path(self, path):
+ if not os.path.exists(path):
+ inkex.errormsg(_("File not found."))
+ sys.exit(1)
+ if os.path.isdir(path):
+ inkex.errormsg(_("The filepath specified is not a file but a dictionary.\nPlease choose a threadlist file to import."))
+ sys.exit(1)
+
+ def verify_colors(self, colors, method):
+ if all(c is None for c in colors):
+ inkex.errormsg(_("Couldn't find any matching colors in the file."))
+ if method == 1:
+ inkex.errormsg(_('Please try to import as "other threadlist" and specify a color palette below.'))
+ else:
+ inkex.errormsg(_("Please chose an other color palette for your design."))
+ sys.exit(1)
+
def parse_inkstitch_threadlist(self, path):
colors = []
with open(path) as threadlist:
@@ -83,6 +95,13 @@ class ApplyThreadlist(InkstitchExtension):
colors.append(None)
return colors
+ def parse_color_format(self, path):
+ colors = []
+ threads = pyembroidery.read(path).threadlist
+ for color in threads:
+ colors.append(color.hex_color())
+ return colors
+
def parse_threadlist_by_catalog_number(self, path):
palette_name = self.options.palette
palette = ThreadCatalog().get_palette_by_name(palette_name)
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index 066b9003..4240be0e 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -5,11 +5,19 @@
from lxml import etree
+from inkex import errormsg
+
+from ..i18n import _
from ..stitch_plan import generate_stitch_plan
class Input(object):
def run(self, args):
embroidery_file = args[0]
+ if args[0].endswith(('edr', 'col', 'inf')):
+ msg = _("Ink/Stitch cannot import color formats directly. But you can open the embroidery file and apply the color with "
+ "Extensions > Ink/Stitch > Thread Color Management > Apply Threadlist")
+ errormsg(msg)
+ exit(0)
stitch_plan = generate_stitch_plan(embroidery_file)
print(etree.tostring(stitch_plan).decode('utf-8'))
diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py
index 280c2a14..e80bc34c 100644
--- a/lib/extensions/zip.py
+++ b/lib/extensions/zip.py
@@ -9,10 +9,10 @@ import tempfile
from copy import deepcopy
from zipfile import ZipFile
-from inkex import Boolean
from lxml import etree
import pyembroidery
+from inkex import Boolean
from ..i18n import _
from ..output import write_embroidery_file
@@ -28,7 +28,7 @@ class Zip(InkstitchExtension):
# it's kind of obnoxious that I have to do this...
self.formats = []
for format in pyembroidery.supported_formats():
- if 'writer' in format and format['category'] == 'embroidery':
+ if 'writer' in format and format['category'] in ['embroidery', 'color', 'image', 'stitch']:
extension = format['extension']
self.arg_parser.add_argument('--format-%s' % extension, type=Boolean, dest=extension)
self.formats.append(extension)
diff --git a/lib/inx/extensions.py b/lib/inx/extensions.py
index 9a197c5d..0ff3e889 100755
--- a/lib/inx/extensions.py
+++ b/lib/inx/extensions.py
@@ -30,7 +30,7 @@ def object_commands():
def pyembroidery_debug_formats():
for format in pyembroidery.supported_formats():
- if 'writer' in format and format['category'] != 'embroidery':
+ if 'writer' in format and format['category'] not in ['embroidery', 'image', 'color', 'stitch']:
yield format['extension'], format['description']
diff --git a/lib/inx/inputs.py b/lib/inx/inputs.py
index 2cf84df9..716e1708 100755
--- a/lib/inx/inputs.py
+++ b/lib/inx/inputs.py
@@ -10,7 +10,7 @@ from .utils import build_environment, write_inx_file
def pyembroidery_input_formats():
for format in pyembroidery.supported_formats():
- if 'reader' in format and format['category'] == 'embroidery':
+ if 'reader' in format and format['category'] in ['embroidery', 'color', 'stitch']:
yield format['extension'], format['description']
diff --git a/lib/inx/outputs.py b/lib/inx/outputs.py
index 1ac1daf8..3a4ac9d0 100644
--- a/lib/inx/outputs.py
+++ b/lib/inx/outputs.py
@@ -12,7 +12,13 @@ def pyembroidery_output_formats():
for format in pyembroidery.supported_formats():
if 'writer' in format:
description = format['description']
- if format['category'] != "embroidery":
+ if format['category'] == "color":
+ description = "%s [COLOR]" % description
+ elif format['category'] == "image":
+ description = "%s [IMAGE]" % description
+ elif format['category'] == "stitch":
+ description = "%s [STITCH]" % description
+ elif format['category'] != "embroidery":
description = "%s [DEBUG]" % description
yield format['extension'], description, format['mimetype'], format['category']
diff --git a/lib/output.py b/lib/output.py
index e330354d..65e6f64d 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -4,8 +4,8 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import sys
-import inkex
+import inkex
import pyembroidery
from .commands import global_command
@@ -33,8 +33,8 @@ def _string_to_floats(string):
return [float(num) for num in floats]
-def get_origin(svg, xxx_todo_changeme):
- (minx, miny, maxx, maxy) = xxx_todo_changeme
+def get_origin(svg, bounding_box):
+ (minx, miny, maxx, maxy) = bounding_box
origin_command = global_command(svg, "origin")
if origin_command:
@@ -52,7 +52,12 @@ def jump_to_stop_point(pattern, svg):
def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
+ # convert from pixels to millimeters
+ # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
+ scale = 10 / PIXELS_PER_MM
+
origin = get_origin(svg, stitch_plan.bounding_box)
+ origin = origin * scale
pattern = pyembroidery.EmbPattern()
stitch = Stitch(0, 0)
@@ -68,10 +73,6 @@ def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
pattern.add_stitch_absolute(pyembroidery.END, stitch.x, stitch.y)
- # convert from pixels to millimeters
- # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
- scale = 10 / PIXELS_PER_MM
-
settings.update({
# correct for the origin
"translate": -origin,
@@ -92,6 +93,9 @@ def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
settings['max_stitch'] = float('inf')
settings['max_jump'] = float('inf')
settings['explicit_trim'] = False
+ elif file_path.endswith('.png'):
+ settings['linewidth'] = 1
+ settings['background'] = 'white'
try:
pyembroidery.write(pattern, file_path, settings)