From 40a343128043b7d2ebe3a770dfae887e969fc5e0 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 12 Jun 2018 20:54:51 -0400 Subject: add output INX generator --- bin/gen-input-inx | 4 ++-- bin/gen-output-inx | 45 ++++++++++++++++++++++++++++++++++++++++++ inx/inkstitch_output_COL.inx | 19 ++++++++++++++++++ inx/inkstitch_output_CSV.inx | 19 ++++++++++++++++++ inx/inkstitch_output_DST.inx | 19 ++++++++++++++++++ inx/inkstitch_output_EDR.inx | 19 ++++++++++++++++++ inx/inkstitch_output_EXP.inx | 19 ++++++++++++++++++ inx/inkstitch_output_HUS.inx | 19 ++++++++++++++++++ inx/inkstitch_output_INF.inx | 19 ++++++++++++++++++ inx/inkstitch_output_JEF.inx | 19 ++++++++++++++++++ inx/inkstitch_output_KSM.inx | 19 ++++++++++++++++++ inx/inkstitch_output_MAX.inx | 19 ++++++++++++++++++ inx/inkstitch_output_PCD.inx | 19 ++++++++++++++++++ inx/inkstitch_output_PCQ.inx | 19 ++++++++++++++++++ inx/inkstitch_output_PCS.inx | 19 ++++++++++++++++++ inx/inkstitch_output_PEC.inx | 19 ++++++++++++++++++ inx/inkstitch_output_PES.inx | 19 ++++++++++++++++++ inx/inkstitch_output_PLT.inx | 19 ++++++++++++++++++ inx/inkstitch_output_RGB.inx | 19 ++++++++++++++++++ inx/inkstitch_output_THR.inx | 19 ++++++++++++++++++ inx/inkstitch_output_TXT.inx | 19 ++++++++++++++++++ inx/inkstitch_output_VP3.inx | 19 ++++++++++++++++++ inx/inkstitch_output_XXX.inx | 19 ++++++++++++++++++ templates/embroider_input.inx | 1 - templates/embroider_output.inx | 19 ++++++++++++++++++ 25 files changed, 465 insertions(+), 3 deletions(-) create mode 100755 bin/gen-output-inx create mode 100644 inx/inkstitch_output_COL.inx create mode 100644 inx/inkstitch_output_CSV.inx create mode 100644 inx/inkstitch_output_DST.inx create mode 100644 inx/inkstitch_output_EDR.inx create mode 100644 inx/inkstitch_output_EXP.inx create mode 100644 inx/inkstitch_output_HUS.inx create mode 100644 inx/inkstitch_output_INF.inx create mode 100644 inx/inkstitch_output_JEF.inx create mode 100644 inx/inkstitch_output_KSM.inx create mode 100644 inx/inkstitch_output_MAX.inx create mode 100644 inx/inkstitch_output_PCD.inx create mode 100644 inx/inkstitch_output_PCQ.inx create mode 100644 inx/inkstitch_output_PCS.inx create mode 100644 inx/inkstitch_output_PEC.inx create mode 100644 inx/inkstitch_output_PES.inx create mode 100644 inx/inkstitch_output_PLT.inx create mode 100644 inx/inkstitch_output_RGB.inx create mode 100644 inx/inkstitch_output_THR.inx create mode 100644 inx/inkstitch_output_TXT.inx create mode 100644 inx/inkstitch_output_VP3.inx create mode 100644 inx/inkstitch_output_XXX.inx create mode 100644 templates/embroider_output.inx diff --git a/bin/gen-input-inx b/bin/gen-input-inx index 5f21ce84..6351d062 100755 --- a/bin/gen-input-inx +++ b/bin/gen-input-inx @@ -21,9 +21,9 @@ def libembroidery_input_formats(): while(curFormat): extension = embFormat_extension(curFormat) description = embFormat_description(curFormat) - writerState = embFormat_readerState(curFormat) + reader_state = embFormat_readerState(curFormat) - if writerState.strip() and embFormat_type(curFormat) != EMBFORMAT_OBJECTONLY: + if reader_state.strip() and embFormat_type(curFormat) != EMBFORMAT_OBJECTONLY: # extension includes the dot, so we'll remove it yield extension[1:], description diff --git a/bin/gen-output-inx b/bin/gen-output-inx new file mode 100755 index 00000000..f167dbee --- /dev/null +++ b/bin/gen-output-inx @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import sys, os +from os.path import dirname +from libembroidery import * +from jinja2 import Environment, FileSystemLoader, select_autoescape + + +def build_environment(): + template_dir = os.path.join(dirname(dirname(os.path.realpath(__file__))), "templates") + + return Environment( + loader = FileSystemLoader(template_dir), + autoescape = True + ) + + +def libembroidery_output_formats(): + formatList = embFormatList_create() + curFormat = formatList + while(curFormat): + extension = embFormat_extension(curFormat) + description = embFormat_description(curFormat) + writer_state = embFormat_writerState(curFormat) + + if writer_state.strip() and embFormat_type(curFormat) != EMBFORMAT_OBJECTONLY: + # extension includes the dot, so we'll remove it + yield extension[1:], description + + curFormat = curFormat.next + + +def main(): + env = build_environment() + template = env.get_template('embroider_output.inx') + + for format, description in libembroidery_output_formats(): + inx = template.render(format=format, description=description) + + with open("inx/inkstitch_output_%s.inx" % format.upper(), 'w') as inx_file: + inx_file.write(inx) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/inx/inkstitch_output_COL.inx b/inx/inkstitch_output_COL.inx new file mode 100644 index 00000000..8a240a38 --- /dev/null +++ b/inx/inkstitch_output_COL.inx @@ -0,0 +1,19 @@ + + + <_name>COL file output + org.inkstitch.output.col + inkstitch.py + inkex.py + + .col + application/x-embroidery-col + <_filetypename>Ink/Stitch: Embroidery Thread Color Format (.col) + <_filetypetooltip>Save design in COL format using Ink/Stitch + true + + output + col + + \ No newline at end of file diff --git a/inx/inkstitch_output_CSV.inx b/inx/inkstitch_output_CSV.inx new file mode 100644 index 00000000..d2f340cd --- /dev/null +++ b/inx/inkstitch_output_CSV.inx @@ -0,0 +1,19 @@ + + + <_name>CSV file output + org.inkstitch.output.csv + inkstitch.py + inkex.py + + .csv + application/x-embroidery-csv + <_filetypename>Ink/Stitch: Comma Separated Values Format (.csv) + <_filetypetooltip>Save design in CSV format using Ink/Stitch + true + + output + csv + + \ No newline at end of file diff --git a/inx/inkstitch_output_DST.inx b/inx/inkstitch_output_DST.inx new file mode 100644 index 00000000..2230600a --- /dev/null +++ b/inx/inkstitch_output_DST.inx @@ -0,0 +1,19 @@ + + + <_name>DST file output + org.inkstitch.output.dst + inkstitch.py + inkex.py + + .dst + application/x-embroidery-dst + <_filetypename>Ink/Stitch: Tajima Embroidery Format (.dst) + <_filetypetooltip>Save design in DST format using Ink/Stitch + true + + output + dst + + \ No newline at end of file diff --git a/inx/inkstitch_output_EDR.inx b/inx/inkstitch_output_EDR.inx new file mode 100644 index 00000000..0756b37a --- /dev/null +++ b/inx/inkstitch_output_EDR.inx @@ -0,0 +1,19 @@ + + + <_name>EDR file output + org.inkstitch.output.edr + inkstitch.py + inkex.py + + .edr + application/x-embroidery-edr + <_filetypename>Ink/Stitch: Embird Embroidery Format (.edr) + <_filetypetooltip>Save design in EDR format using Ink/Stitch + true + + output + edr + + \ No newline at end of file diff --git a/inx/inkstitch_output_EXP.inx b/inx/inkstitch_output_EXP.inx new file mode 100644 index 00000000..ce98dbc0 --- /dev/null +++ b/inx/inkstitch_output_EXP.inx @@ -0,0 +1,19 @@ + + + <_name>EXP file output + org.inkstitch.output.exp + inkstitch.py + inkex.py + + .exp + application/x-embroidery-exp + <_filetypename>Ink/Stitch: Melco Embroidery Format (.exp) + <_filetypetooltip>Save design in EXP format using Ink/Stitch + true + + output + exp + + \ No newline at end of file diff --git a/inx/inkstitch_output_HUS.inx b/inx/inkstitch_output_HUS.inx new file mode 100644 index 00000000..44536f2a --- /dev/null +++ b/inx/inkstitch_output_HUS.inx @@ -0,0 +1,19 @@ + + + <_name>HUS file output + org.inkstitch.output.hus + inkstitch.py + inkex.py + + .hus + application/x-embroidery-hus + <_filetypename>Ink/Stitch: Husqvarna Viking Embroidery Format (.hus) + <_filetypetooltip>Save design in HUS format using Ink/Stitch + true + + output + hus + + \ No newline at end of file diff --git a/inx/inkstitch_output_INF.inx b/inx/inkstitch_output_INF.inx new file mode 100644 index 00000000..47c2b63e --- /dev/null +++ b/inx/inkstitch_output_INF.inx @@ -0,0 +1,19 @@ + + + <_name>INF file output + org.inkstitch.output.inf + inkstitch.py + inkex.py + + .inf + application/x-embroidery-inf + <_filetypename>Ink/Stitch: Embroidery Color Format (.inf) + <_filetypetooltip>Save design in INF format using Ink/Stitch + true + + output + inf + + \ No newline at end of file diff --git a/inx/inkstitch_output_JEF.inx b/inx/inkstitch_output_JEF.inx new file mode 100644 index 00000000..af92a836 --- /dev/null +++ b/inx/inkstitch_output_JEF.inx @@ -0,0 +1,19 @@ + + + <_name>JEF file output + org.inkstitch.output.jef + inkstitch.py + inkex.py + + .jef + application/x-embroidery-jef + <_filetypename>Ink/Stitch: Janome Embroidery Format (.jef) + <_filetypetooltip>Save design in JEF format using Ink/Stitch + true + + output + jef + + \ No newline at end of file diff --git a/inx/inkstitch_output_KSM.inx b/inx/inkstitch_output_KSM.inx new file mode 100644 index 00000000..ad5ae4dd --- /dev/null +++ b/inx/inkstitch_output_KSM.inx @@ -0,0 +1,19 @@ + + + <_name>KSM file output + org.inkstitch.output.ksm + inkstitch.py + inkex.py + + .ksm + application/x-embroidery-ksm + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.ksm) + <_filetypetooltip>Save design in KSM format using Ink/Stitch + true + + output + ksm + + \ No newline at end of file diff --git a/inx/inkstitch_output_MAX.inx b/inx/inkstitch_output_MAX.inx new file mode 100644 index 00000000..45a5ba01 --- /dev/null +++ b/inx/inkstitch_output_MAX.inx @@ -0,0 +1,19 @@ + + + <_name>MAX file output + org.inkstitch.output.max + inkstitch.py + inkex.py + + .max + application/x-embroidery-max + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.max) + <_filetypetooltip>Save design in MAX format using Ink/Stitch + true + + output + max + + \ No newline at end of file diff --git a/inx/inkstitch_output_PCD.inx b/inx/inkstitch_output_PCD.inx new file mode 100644 index 00000000..b42f79de --- /dev/null +++ b/inx/inkstitch_output_PCD.inx @@ -0,0 +1,19 @@ + + + <_name>PCD file output + org.inkstitch.output.pcd + inkstitch.py + inkex.py + + .pcd + application/x-embroidery-pcd + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.pcd) + <_filetypetooltip>Save design in PCD format using Ink/Stitch + true + + output + pcd + + \ No newline at end of file diff --git a/inx/inkstitch_output_PCQ.inx b/inx/inkstitch_output_PCQ.inx new file mode 100644 index 00000000..1764f670 --- /dev/null +++ b/inx/inkstitch_output_PCQ.inx @@ -0,0 +1,19 @@ + + + <_name>PCQ file output + org.inkstitch.output.pcq + inkstitch.py + inkex.py + + .pcq + application/x-embroidery-pcq + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.pcq) + <_filetypetooltip>Save design in PCQ format using Ink/Stitch + true + + output + pcq + + \ No newline at end of file diff --git a/inx/inkstitch_output_PCS.inx b/inx/inkstitch_output_PCS.inx new file mode 100644 index 00000000..ef07c4bd --- /dev/null +++ b/inx/inkstitch_output_PCS.inx @@ -0,0 +1,19 @@ + + + <_name>PCS file output + org.inkstitch.output.pcs + inkstitch.py + inkex.py + + .pcs + application/x-embroidery-pcs + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.pcs) + <_filetypetooltip>Save design in PCS format using Ink/Stitch + true + + output + pcs + + \ No newline at end of file diff --git a/inx/inkstitch_output_PEC.inx b/inx/inkstitch_output_PEC.inx new file mode 100644 index 00000000..15880ce6 --- /dev/null +++ b/inx/inkstitch_output_PEC.inx @@ -0,0 +1,19 @@ + + + <_name>PEC file output + org.inkstitch.output.pec + inkstitch.py + inkex.py + + .pec + application/x-embroidery-pec + <_filetypename>Ink/Stitch: Brother Embroidery Format (.pec) + <_filetypetooltip>Save design in PEC format using Ink/Stitch + true + + output + pec + + \ No newline at end of file diff --git a/inx/inkstitch_output_PES.inx b/inx/inkstitch_output_PES.inx new file mode 100644 index 00000000..cd7e7369 --- /dev/null +++ b/inx/inkstitch_output_PES.inx @@ -0,0 +1,19 @@ + + + <_name>PES file output + org.inkstitch.output.pes + inkstitch.py + inkex.py + + .pes + application/x-embroidery-pes + <_filetypename>Ink/Stitch: Brother Embroidery Format (.pes) + <_filetypetooltip>Save design in PES format using Ink/Stitch + true + + output + pes + + \ No newline at end of file diff --git a/inx/inkstitch_output_PLT.inx b/inx/inkstitch_output_PLT.inx new file mode 100644 index 00000000..649ef76b --- /dev/null +++ b/inx/inkstitch_output_PLT.inx @@ -0,0 +1,19 @@ + + + <_name>PLT file output + org.inkstitch.output.plt + inkstitch.py + inkex.py + + .plt + application/x-embroidery-plt + <_filetypename>Ink/Stitch: AutoCAD Plot Drawing Format (.plt) + <_filetypetooltip>Save design in PLT format using Ink/Stitch + true + + output + plt + + \ No newline at end of file diff --git a/inx/inkstitch_output_RGB.inx b/inx/inkstitch_output_RGB.inx new file mode 100644 index 00000000..e60d729e --- /dev/null +++ b/inx/inkstitch_output_RGB.inx @@ -0,0 +1,19 @@ + + + <_name>RGB file output + org.inkstitch.output.rgb + inkstitch.py + inkex.py + + .rgb + application/x-embroidery-rgb + <_filetypename>Ink/Stitch: RGB Embroidery Format (.rgb) + <_filetypetooltip>Save design in RGB format using Ink/Stitch + true + + output + rgb + + \ No newline at end of file diff --git a/inx/inkstitch_output_THR.inx b/inx/inkstitch_output_THR.inx new file mode 100644 index 00000000..c460bdfc --- /dev/null +++ b/inx/inkstitch_output_THR.inx @@ -0,0 +1,19 @@ + + + <_name>THR file output + org.inkstitch.output.thr + inkstitch.py + inkex.py + + .thr + application/x-embroidery-thr + <_filetypename>Ink/Stitch: ThredWorks Embroidery Format (.thr) + <_filetypetooltip>Save design in THR format using Ink/Stitch + true + + output + thr + + \ No newline at end of file diff --git a/inx/inkstitch_output_TXT.inx b/inx/inkstitch_output_TXT.inx new file mode 100644 index 00000000..805deffe --- /dev/null +++ b/inx/inkstitch_output_TXT.inx @@ -0,0 +1,19 @@ + + + <_name>TXT file output + org.inkstitch.output.txt + inkstitch.py + inkex.py + + .txt + application/x-embroidery-txt + <_filetypename>Ink/Stitch: Text File (.txt) + <_filetypetooltip>Save design in TXT format using Ink/Stitch + true + + output + txt + + \ No newline at end of file diff --git a/inx/inkstitch_output_VP3.inx b/inx/inkstitch_output_VP3.inx new file mode 100644 index 00000000..dff29de4 --- /dev/null +++ b/inx/inkstitch_output_VP3.inx @@ -0,0 +1,19 @@ + + + <_name>VP3 file output + org.inkstitch.output.vp3 + inkstitch.py + inkex.py + + .vp3 + application/x-embroidery-vp3 + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.vp3) + <_filetypetooltip>Save design in VP3 format using Ink/Stitch + true + + output + vp3 + + \ No newline at end of file diff --git a/inx/inkstitch_output_XXX.inx b/inx/inkstitch_output_XXX.inx new file mode 100644 index 00000000..ad4135b0 --- /dev/null +++ b/inx/inkstitch_output_XXX.inx @@ -0,0 +1,19 @@ + + + <_name>XXX file output + org.inkstitch.output.xxx + inkstitch.py + inkex.py + + .xxx + application/x-embroidery-xxx + <_filetypename>Ink/Stitch: Singer Embroidery Format (.xxx) + <_filetypetooltip>Save design in XXX format using Ink/Stitch + true + + output + xxx + + \ No newline at end of file diff --git a/templates/embroider_input.inx b/templates/embroider_input.inx index 24bba7e4..15ccdef8 100644 --- a/templates/embroider_input.inx +++ b/templates/embroider_input.inx @@ -15,4 +15,3 @@ inkstitch.py - diff --git a/templates/embroider_output.inx b/templates/embroider_output.inx new file mode 100644 index 00000000..4f971fb3 --- /dev/null +++ b/templates/embroider_output.inx @@ -0,0 +1,19 @@ + + + <_name>{{ format | upper }} file output + org.inkstitch.output.{{ format }} + inkstitch.py + inkex.py + + .{{ format }} + application/x-embroidery-{{ format }} + <_filetypename>Ink/Stitch: {{ description }} (.{{ format }}) + <_filetypetooltip>Save design in {{ format | upper }} format using Ink/Stitch + true + + output + {{ format }} + + -- cgit v1.2.3 From ede0e766d899d2f0aafd36915e5b599972f549c7 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 12 Jun 2018 21:28:02 -0400 Subject: add output extension --- lib/extensions/__init__.py | 1 + lib/extensions/output.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 lib/extensions/output.py diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index ebdd2fc9..a4654d2c 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -4,3 +4,4 @@ from params import Params from print_pdf import Print from simulate import Simulate from input import Input +from output import Output diff --git a/lib/extensions/output.py b/lib/extensions/output.py new file mode 100644 index 00000000..72bbe37d --- /dev/null +++ b/lib/extensions/output.py @@ -0,0 +1,49 @@ +import sys +import traceback +import os +import inkex +import tempfile + +from .base import InkstitchExtension +from ..i18n import _ +from ..output import write_embroidery_file +from ..stitch_plan import patches_to_stitch_plan +from ..svg import render_stitch_plan, PIXELS_PER_MM + + +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)") + + 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) + + # libembroidery wants to write to an actual file rather than stdout + temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.options.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()) + + # inkscape will read the file contents from stdout and copy + # to the destination file that the user chose + with open(temp_file.name) as output_file: + sys.stdout.write(output_file.read()) + + # clean up the temp file + os.remove(temp_file.name) + + # don't let inkex output the SVG! + sys.exit(0) -- cgit v1.2.3 From b4dd5a1e8fac21b4d40e3a839715834ea243e49a Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 12 Jun 2018 21:48:38 -0400 Subject: add zip INX generator and INX --- bin/gen-zip-inx | 44 +++++++++++++++++++++++++++ inx/inkstitch_output_ZIP.inx | 61 ++++++++++++++++++++++++++++++++++++++ messages.po | 2 +- templates/embroider_zip_output.inx | 21 +++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100755 bin/gen-zip-inx create mode 100644 inx/inkstitch_output_ZIP.inx create mode 100644 templates/embroider_zip_output.inx diff --git a/bin/gen-zip-inx b/bin/gen-zip-inx new file mode 100755 index 00000000..5fbc8f1e --- /dev/null +++ b/bin/gen-zip-inx @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +import sys, os +from os.path import dirname +from libembroidery import * +from jinja2 import Environment, FileSystemLoader, select_autoescape + + +def build_environment(): + template_dir = os.path.join(dirname(dirname(os.path.realpath(__file__))), "templates") + + return Environment( + loader = FileSystemLoader(template_dir), + autoescape = True + ) + + +def libembroidery_output_formats(): + formatList = embFormatList_create() + curFormat = formatList + while(curFormat): + extension = embFormat_extension(curFormat) + description = embFormat_description(curFormat) + writer_state = embFormat_writerState(curFormat) + + if writer_state.strip() and embFormat_type(curFormat) != EMBFORMAT_OBJECTONLY: + # extension includes the dot, so we'll remove it + yield extension[1:], description + + curFormat = curFormat.next + + +def main(): + env = build_environment() + template = env.get_template('embroider_zip_output.inx') + + inx = template.render(formats=libembroidery_output_formats()) + + with open("inx/inkstitch_output_ZIP.inx", 'w') as inx_file: + inx_file.write(inx) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/inx/inkstitch_output_ZIP.inx b/inx/inkstitch_output_ZIP.inx new file mode 100644 index 00000000..b5b2cf1c --- /dev/null +++ b/inx/inkstitch_output_ZIP.inx @@ -0,0 +1,61 @@ + + + <_name>embroidery ZIP file output + org.inkstitch.output.zip + inkstitch.py + inkex.py + + .zip + application/zip + <_filetypename>Ink/Stitch: ZIP export multiple formats (.zip) + <_filetypetooltip>Create a ZIP with multiple embroidery file formats using Ink/Stitch + true + + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + false + + zip + + diff --git a/messages.po b/messages.po index b872f864..36af2e50 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-06-12 20:18-0400\n" +"POT-Creation-Date: 2018-06-15 21:44-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/templates/embroider_zip_output.inx b/templates/embroider_zip_output.inx new file mode 100644 index 00000000..5d162357 --- /dev/null +++ b/templates/embroider_zip_output.inx @@ -0,0 +1,21 @@ + + + <_name>embroidery ZIP file output + org.inkstitch.output.zip + inkstitch.py + inkex.py + + .zip + application/zip + <_filetypename>Ink/Stitch: ZIP export multiple formats (.zip) + <_filetypetooltip>Create a ZIP with multiple embroidery file formats using Ink/Stitch + true + +{% for format, description in formats %} + false +{% endfor %} + zip + + -- cgit v1.2.3 From ea1135c1451ab2db54fd52fbf48a8eee9c5a43e0 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 12 Jun 2018 22:15:32 -0400 Subject: add ZIP batch export extension --- lib/extensions/__init__.py | 1 + lib/extensions/base.py | 9 +++++ lib/extensions/embroider.py | 3 +- lib/extensions/zip.py | 80 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 lib/extensions/zip.py diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index a4654d2c..6d3e00d8 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -5,3 +5,4 @@ from print_pdf import Print from simulate import Simulate from input import Input from output import Output +from zip import Zip diff --git a/lib/extensions/base.py b/lib/extensions/base.py index 4589132f..831b6dc6 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -200,6 +200,15 @@ class InkstitchExtension(inkex.Effect): def get_inkstitch_metadata(self): return InkStitchMetadata(self.document) + def get_base_file_name(self): + svg_filename = self.document.getroot().get(inkex.addNS('docname', 'sodipodi'), "embroidery.svg") + + if svg_filename.endswith('.svg'): + svg_filename = svg_filename[:-4] + + return svg_filename + + def parse(self): """Override inkex.Effect to add Ink/Stitch xml namespace""" diff --git a/lib/extensions/embroider.py b/lib/extensions/embroider.py index a213be64..1e994e27 100644 --- a/lib/extensions/embroider.py +++ b/lib/extensions/embroider.py @@ -44,8 +44,7 @@ class Embroider(InkstitchExtension): if self.options.output_file: output_path = os.path.join(self.options.path, self.options.output_file) else: - svg_filename = self.document.getroot().get(inkex.addNS('docname', 'sodipodi'), "embroidery.svg") - csv_filename = svg_filename.replace('.svg', '.%s' % self.options.output_format) + csv_filename = '%s.%s' % (self.get_base_file_name(), self.options.output_format) output_path = os.path.join(self.options.path, csv_filename) def add_suffix(path, suffix): diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py new file mode 100644 index 00000000..4720ad1e --- /dev/null +++ b/lib/extensions/zip.py @@ -0,0 +1,80 @@ +import sys +import traceback +import os +import inkex +import tempfile +from zipfile import ZipFile +from libembroidery import * + +from .base import InkstitchExtension +from ..i18n import _ +from ..output import write_embroidery_file +from ..stitch_plan import patches_to_stitch_plan +from ..svg import render_stitch_plan, PIXELS_PER_MM + + +class Zip(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)") + + # it's kind of obnoxious that I have to do this... + self.formats = [] + formatList = embFormatList_create() + curFormat = formatList + while(curFormat): + # extension includes the dot, so we'll remove it + extension = embFormat_extension(curFormat)[1:] + description = embFormat_description(curFormat) + writer_state = embFormat_writerState(curFormat) + + if writer_state.strip() and embFormat_type(curFormat) != EMBFORMAT_OBJECTONLY: + self.OptionParser.add_option('--format-%s' % extension, type="inkbool", dest=extension) + self.formats.append(extension) + curFormat = curFormat.next + + 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) + + base_file_name = self.get_base_file_name() + path = tempfile.mkdtemp() + + files = [] + + for format in self.formats: + if getattr(self.options, format): + output_file = os.path.join(path, "%s.%s" % (base_file_name, format)) + write_embroidery_file(output_file, stitch_plan, self.document.getroot()) + files.append(output_file) + + if not files: + self.errormsg(_("No embroidery file formats selected.")) + + temp_file = tempfile.NamedTemporaryFile(suffix=".zip", delete=False) + + # in windows, failure to close here will keep the file locked + temp_file.close() + + with ZipFile(temp_file.name, "w") as zip_file: + for file in files: + zip_file.write(file) + + # inkscape will read the file contents from stdout and copy + # to the destination file that the user chose + with open(temp_file.name) as output_file: + sys.stdout.write(output_file.read()) + + os.remove(temp_file.name) + for file in files: + os.remove(file) + os.rmdir(path) + + # don't let inkex output the SVG! + sys.exit(0) -- cgit v1.2.3 From f9a5e4c03a073d403222f0d5b7810cdaab90145a Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 13 Jun 2018 12:53:05 -0400 Subject: remove tmp directory from zip file paths --- lib/extensions/zip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index 4720ad1e..a7616536 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -64,7 +64,7 @@ class Zip(InkstitchExtension): with ZipFile(temp_file.name, "w") as zip_file: for file in files: - zip_file.write(file) + zip_file.write(file, os.path.basename(file)) # inkscape will read the file contents from stdout and copy # to the destination file that the user chose -- cgit v1.2.3 From 4c46c2eec1fb7cf9e85617030214bcb170b8b533 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 13 Jun 2018 20:10:22 -0400 Subject: fix zip file corruption --- lib/extensions/output.py | 4 +++- lib/extensions/zip.py | 10 +++++++++- lib/utils/io.py | 21 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/extensions/output.py b/lib/extensions/output.py index 72bbe37d..924c2d3a 100644 --- a/lib/extensions/output.py +++ b/lib/extensions/output.py @@ -35,12 +35,14 @@ class Output(InkstitchExtension): # in windows, failure to close here will keep the file locked temp_file.close() + # libembroidery likes to debug log things to stdout. No way to disable it. + save_stdout() write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot()) # inkscape will read the file contents from stdout and copy # to the destination file that the user chose with open(temp_file.name) as output_file: - sys.stdout.write(output_file.read()) + sys.real_stdout.write(output_file.read()) # clean up the temp file os.remove(temp_file.name) diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index a7616536..ca12efdd 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -11,6 +11,7 @@ from ..i18n import _ from ..output import write_embroidery_file from ..stitch_plan import patches_to_stitch_plan from ..svg import render_stitch_plan, PIXELS_PER_MM +from ..utils.io import save_stdout class Zip(InkstitchExtension): @@ -48,12 +49,19 @@ class Zip(InkstitchExtension): files = [] + # libembroidery likes to debug log things to stdout. No way to disable it. + save_stdout() for format in self.formats: if getattr(self.options, format): output_file = os.path.join(path, "%s.%s" % (base_file_name, format)) write_embroidery_file(output_file, stitch_plan, self.document.getroot()) files.append(output_file) + # I'd love to do restore_stderr() here, but if I do, libembroidery's + # stuff still prints out and corrupts the zip! That's because it uses + # C's buffered stdout, so it hasn't actually written anything to the + # real standard output yet. + if not files: self.errormsg(_("No embroidery file formats selected.")) @@ -69,7 +77,7 @@ class Zip(InkstitchExtension): # inkscape will read the file contents from stdout and copy # to the destination file that the user chose with open(temp_file.name) as output_file: - sys.stdout.write(output_file.read()) + sys.real_stdout.write(output_file.read()) os.remove(temp_file.name) for file in files: diff --git a/lib/utils/io.py b/lib/utils/io.py index be1fdf24..44d48c2a 100644 --- a/lib/utils/io.py +++ b/lib/utils/io.py @@ -7,12 +7,31 @@ def save_stderr(): # GTK likes to spam stderr, which inkscape will show in a dialog. null = open(os.devnull, 'w') sys.stderr_dup = os.dup(sys.stderr.fileno()) + sys.real_stderr = os.fdopen(sys.stderr_dup, 'w') os.dup2(null.fileno(), 2) sys.stderr_backup = sys.stderr sys.stderr = StringIO() def restore_stderr(): + sys.real_stderr.close() os.dup2(sys.stderr_dup, 2) - sys.stderr_backup.write(sys.stderr.getvalue()) + sys.real_stderr.write(sys.stderr.getvalue()) sys.stderr = sys.stderr_backup + +# It's probably possible to generalize this code, but when I tried, +# the result was incredibly unreadable. +def save_stdout(): + null = open(os.devnull, 'w') + sys.stdout_dup = os.dup(sys.stdout.fileno()) + sys.real_stdout = os.fdopen(sys.stdout_dup, 'w') + os.dup2(null.fileno(), 1) + sys.stdout_backup = sys.stdout + sys.stdout = StringIO() + + +def restore_stdout(): + sys.real_stdout.close() + os.dup2(sys.stdout_dup, 1) + sys.real_stdout.write(sys.stdout.getvalue()) + sys.stdout = sys.stdout_backup -- cgit v1.2.3 From b674c192ee5ff7b3bbc48837379d1cea5f61b3bc Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 13 Jun 2018 20:45:51 -0400 Subject: fix issue with input plugin --- lib/extensions/input.py | 6 +++++- lib/utils/io.py | 8 ++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/extensions/input.py b/lib/extensions/input.py index 251859c5..21248dd9 100644 --- a/lib/extensions/input.py +++ b/lib/extensions/input.py @@ -14,6 +14,7 @@ from ..svg import PIXELS_PER_MM, render_stitch_plan from ..svg.tags import INKSCAPE_LABEL from ..i18n import _ from ..stitch_plan import StitchPlan +from ..utils.io import save_stdout class Input(object): @@ -25,6 +26,9 @@ class Input(object): 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) @@ -65,4 +69,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 etree.tostring(svg) + print >> sys.real_stdout, etree.tostring(svg) diff --git a/lib/utils/io.py b/lib/utils/io.py index 44d48c2a..e5a246f3 100644 --- a/lib/utils/io.py +++ b/lib/utils/io.py @@ -9,15 +9,13 @@ def save_stderr(): sys.stderr_dup = os.dup(sys.stderr.fileno()) sys.real_stderr = os.fdopen(sys.stderr_dup, 'w') os.dup2(null.fileno(), 2) - sys.stderr_backup = sys.stderr sys.stderr = StringIO() def restore_stderr(): - sys.real_stderr.close() os.dup2(sys.stderr_dup, 2) sys.real_stderr.write(sys.stderr.getvalue()) - sys.stderr = sys.stderr_backup + sys.stderr = sys.real_stderr # It's probably possible to generalize this code, but when I tried, # the result was incredibly unreadable. @@ -26,12 +24,10 @@ def save_stdout(): sys.stdout_dup = os.dup(sys.stdout.fileno()) sys.real_stdout = os.fdopen(sys.stdout_dup, 'w') os.dup2(null.fileno(), 1) - sys.stdout_backup = sys.stdout sys.stdout = StringIO() def restore_stdout(): - sys.real_stdout.close() os.dup2(sys.stdout_dup, 1) sys.real_stdout.write(sys.stdout.getvalue()) - sys.stdout = sys.stdout_backup + sys.stdout = sys.real_stdout -- cgit v1.2.3 From 0659bc294e943bcaa10f63966e667003623e6da4 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 16 Jun 2018 22:33:02 -0400 Subject: fix output regression --- lib/extensions/output.py | 2 +- messages.po | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/extensions/output.py b/lib/extensions/output.py index 924c2d3a..f4b153e6 100644 --- a/lib/extensions/output.py +++ b/lib/extensions/output.py @@ -9,7 +9,7 @@ from ..i18n import _ from ..output import write_embroidery_file from ..stitch_plan import patches_to_stitch_plan from ..svg import render_stitch_plan, PIXELS_PER_MM - +from ..utils.io import save_stdout class Output(InkstitchExtension): def __init__(self, *args, **kwargs): diff --git a/messages.po b/messages.po index 36af2e50..fb081eb1 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-06-15 21:44-0400\n" +"POT-Creation-Date: 2018-06-16 22:33-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -319,6 +319,9 @@ msgstr "" msgid "Embroidery Simulation" msgstr "" +msgid "No embroidery file formats selected." +msgstr "" + msgid "" "Unable to autofill. This most often happens because your shape is made " "up of multiple sections that aren't connected." -- cgit v1.2.3