summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/output.py50
-rw-r--r--lib/output.py6
2 files changed, 39 insertions, 17 deletions
diff --git a/lib/extensions/output.py b/lib/extensions/output.py
index 26fd4f2e..8b99c027 100644
--- a/lib/extensions/output.py
+++ b/lib/extensions/output.py
@@ -1,37 +1,59 @@
-import sys
import os
+import sys
import tempfile
-from .base import InkstitchExtension
from ..output import write_embroidery_file
from ..stitch_plan import patches_to_stitch_plan
-from ..svg import PIXELS_PER_MM
+from .base import InkstitchExtension
class Output(InkstitchExtension):
def __init__(self, *args, **kwargs):
- InkstitchExtension.__init__(self)
- self.OptionParser.add_option("-c", "--collapse_len_mm",
- action="store", type="float",
- dest="collapse_length_mm", default=3.0,
- help="max collapse length (mm)")
- self.OptionParser.add_option("-f", "--format",
- dest="file_extension",
- help="file extension to output (example: DST)")
+ InkstitchExtension.__init__(self, *args, **kwargs)
+
+ def getoptions(self, args=sys.argv[1:]):
+ # inkex's option parsing can't handle arbitrary command line arguments
+ # that may be passed for a given output format, so we'll just parse the
+ # args ourselves. :P
+ self.settings = {}
+ extra_args = []
+ for arg in args:
+ if arg.startswith('--') and not arg.startswith('--id='):
+ name, value = arg[2:].split('=')
+
+ try:
+ value = float(value)
+ except ValueError:
+ try:
+ value = {
+ "true": True,
+ "false": False
+ }[value]
+ except (KeyError):
+ pass
+
+ self.settings[name] = value
+ else:
+ extra_args.append(arg)
+
+ self.file_extension = self.settings.pop('format')
+ del sys.argv[1:]
+
+ InkstitchExtension.getoptions(self, extra_args)
def effect(self):
if not self.get_elements():
return
patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, self.options.collapse_length_mm * PIXELS_PER_MM)
+ stitch_plan = patches_to_stitch_plan(patches)
- temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.options.file_extension, delete=False)
+ temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.file_extension, delete=False)
# in windows, failure to close here will keep the file locked
temp_file.close()
- write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot())
+ write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot(), self.settings)
if sys.platform == "win32":
import msvcrt
diff --git a/lib/output.py b/lib/output.py
index ed97ef04..5fa7791f 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -53,7 +53,7 @@ def jump_to_stop_point(pattern, svg):
pattern.add_stitch_absolute(pyembroidery.JUMP, stop_position.point.x, stop_position.point.y)
-def write_embroidery_file(file_path, stitch_plan, svg):
+def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
origin = get_origin(svg)
pattern = pyembroidery.EmbPattern()
@@ -73,7 +73,7 @@ def write_embroidery_file(file_path, stitch_plan, svg):
# also multiply by 10 to get tenths of a millimeter as required by pyembroidery
scale = 10 / PIXELS_PER_MM
- settings = {
+ settings.update({
# correct for the origin
"translate": -origin,
@@ -84,7 +84,7 @@ def write_embroidery_file(file_path, stitch_plan, svg):
# This forces a jump at the start of the design and after each trim,
# even if we're close enough not to need one.
"full_jump": True,
- }
+ })
if file_path.endswith('.csv'):
# Special treatment for CSV: instruct pyembroidery not to do any post-