diff options
36 files changed, 769 insertions, 10 deletions
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/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_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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>COL file output</_name> + <id>org.inkstitch.output.col</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.col</extension> + <mimetype>application/x-embroidery-col</mimetype> + <_filetypename>Ink/Stitch: Embroidery Thread Color Format (.col)</_filetypename> + <_filetypetooltip>Save design in COL format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">col</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>CSV file output</_name> + <id>org.inkstitch.output.csv</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.csv</extension> + <mimetype>application/x-embroidery-csv</mimetype> + <_filetypename>Ink/Stitch: Comma Separated Values Format (.csv)</_filetypename> + <_filetypetooltip>Save design in CSV format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">csv</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>DST file output</_name> + <id>org.inkstitch.output.dst</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.dst</extension> + <mimetype>application/x-embroidery-dst</mimetype> + <_filetypename>Ink/Stitch: Tajima Embroidery Format (.dst)</_filetypename> + <_filetypetooltip>Save design in DST format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">dst</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>EDR file output</_name> + <id>org.inkstitch.output.edr</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.edr</extension> + <mimetype>application/x-embroidery-edr</mimetype> + <_filetypename>Ink/Stitch: Embird Embroidery Format (.edr)</_filetypename> + <_filetypetooltip>Save design in EDR format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">edr</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>EXP file output</_name> + <id>org.inkstitch.output.exp</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.exp</extension> + <mimetype>application/x-embroidery-exp</mimetype> + <_filetypename>Ink/Stitch: Melco Embroidery Format (.exp)</_filetypename> + <_filetypetooltip>Save design in EXP format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">exp</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>HUS file output</_name> + <id>org.inkstitch.output.hus</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.hus</extension> + <mimetype>application/x-embroidery-hus</mimetype> + <_filetypename>Ink/Stitch: Husqvarna Viking Embroidery Format (.hus)</_filetypename> + <_filetypetooltip>Save design in HUS format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">hus</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>INF file output</_name> + <id>org.inkstitch.output.inf</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.inf</extension> + <mimetype>application/x-embroidery-inf</mimetype> + <_filetypename>Ink/Stitch: Embroidery Color Format (.inf)</_filetypename> + <_filetypetooltip>Save design in INF format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">inf</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>JEF file output</_name> + <id>org.inkstitch.output.jef</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.jef</extension> + <mimetype>application/x-embroidery-jef</mimetype> + <_filetypename>Ink/Stitch: Janome Embroidery Format (.jef)</_filetypename> + <_filetypetooltip>Save design in JEF format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">jef</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>KSM file output</_name> + <id>org.inkstitch.output.ksm</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.ksm</extension> + <mimetype>application/x-embroidery-ksm</mimetype> + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.ksm)</_filetypename> + <_filetypetooltip>Save design in KSM format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">ksm</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>MAX file output</_name> + <id>org.inkstitch.output.max</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.max</extension> + <mimetype>application/x-embroidery-max</mimetype> + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.max)</_filetypename> + <_filetypetooltip>Save design in MAX format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">max</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>PCD file output</_name> + <id>org.inkstitch.output.pcd</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.pcd</extension> + <mimetype>application/x-embroidery-pcd</mimetype> + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.pcd)</_filetypename> + <_filetypetooltip>Save design in PCD format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">pcd</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>PCQ file output</_name> + <id>org.inkstitch.output.pcq</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.pcq</extension> + <mimetype>application/x-embroidery-pcq</mimetype> + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.pcq)</_filetypename> + <_filetypetooltip>Save design in PCQ format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">pcq</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>PCS file output</_name> + <id>org.inkstitch.output.pcs</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.pcs</extension> + <mimetype>application/x-embroidery-pcs</mimetype> + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.pcs)</_filetypename> + <_filetypetooltip>Save design in PCS format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">pcs</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>PEC file output</_name> + <id>org.inkstitch.output.pec</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.pec</extension> + <mimetype>application/x-embroidery-pec</mimetype> + <_filetypename>Ink/Stitch: Brother Embroidery Format (.pec)</_filetypename> + <_filetypetooltip>Save design in PEC format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">pec</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>PES file output</_name> + <id>org.inkstitch.output.pes</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.pes</extension> + <mimetype>application/x-embroidery-pes</mimetype> + <_filetypename>Ink/Stitch: Brother Embroidery Format (.pes)</_filetypename> + <_filetypetooltip>Save design in PES format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">pes</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>PLT file output</_name> + <id>org.inkstitch.output.plt</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.plt</extension> + <mimetype>application/x-embroidery-plt</mimetype> + <_filetypename>Ink/Stitch: AutoCAD Plot Drawing Format (.plt)</_filetypename> + <_filetypetooltip>Save design in PLT format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">plt</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>RGB file output</_name> + <id>org.inkstitch.output.rgb</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.rgb</extension> + <mimetype>application/x-embroidery-rgb</mimetype> + <_filetypename>Ink/Stitch: RGB Embroidery Format (.rgb)</_filetypename> + <_filetypetooltip>Save design in RGB format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">rgb</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>THR file output</_name> + <id>org.inkstitch.output.thr</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.thr</extension> + <mimetype>application/x-embroidery-thr</mimetype> + <_filetypename>Ink/Stitch: ThredWorks Embroidery Format (.thr)</_filetypename> + <_filetypetooltip>Save design in THR format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">thr</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>TXT file output</_name> + <id>org.inkstitch.output.txt</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.txt</extension> + <mimetype>application/x-embroidery-txt</mimetype> + <_filetypename>Ink/Stitch: Text File (.txt)</_filetypename> + <_filetypetooltip>Save design in TXT format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">txt</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>VP3 file output</_name> + <id>org.inkstitch.output.vp3</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.vp3</extension> + <mimetype>application/x-embroidery-vp3</mimetype> + <_filetypename>Ink/Stitch: Pfaff Embroidery Format (.vp3)</_filetypename> + <_filetypetooltip>Save design in VP3 format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">vp3</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>XXX file output</_name> + <id>org.inkstitch.output.xxx</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.xxx</extension> + <mimetype>application/x-embroidery-xxx</mimetype> + <_filetypename>Ink/Stitch: Singer Embroidery Format (.xxx)</_filetypename> + <_filetypetooltip>Save design in XXX format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">xxx</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension>
\ No newline at end of file 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>embroidery ZIP file output</_name> + <id>org.inkstitch.output.zip</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.zip</extension> + <mimetype>application/zip</mimetype> + <_filetypename>Ink/Stitch: ZIP export multiple formats (.zip)</_filetypename> + <_filetypetooltip>Create a ZIP with multiple embroidery file formats using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + + <param name="format-col" type="boolean" _gui-text=".COL: Embroidery Thread Color Format">false</param> + + <param name="format-csv" type="boolean" _gui-text=".CSV: Comma Separated Values Format">false</param> + + <param name="format-dst" type="boolean" _gui-text=".DST: Tajima Embroidery Format">false</param> + + <param name="format-edr" type="boolean" _gui-text=".EDR: Embird Embroidery Format">false</param> + + <param name="format-exp" type="boolean" _gui-text=".EXP: Melco Embroidery Format">false</param> + + <param name="format-hus" type="boolean" _gui-text=".HUS: Husqvarna Viking Embroidery Format">false</param> + + <param name="format-inf" type="boolean" _gui-text=".INF: Embroidery Color Format">false</param> + + <param name="format-jef" type="boolean" _gui-text=".JEF: Janome Embroidery Format">false</param> + + <param name="format-ksm" type="boolean" _gui-text=".KSM: Pfaff Embroidery Format">false</param> + + <param name="format-max" type="boolean" _gui-text=".MAX: Pfaff Embroidery Format">false</param> + + <param name="format-pcd" type="boolean" _gui-text=".PCD: Pfaff Embroidery Format">false</param> + + <param name="format-pcq" type="boolean" _gui-text=".PCQ: Pfaff Embroidery Format">false</param> + + <param name="format-pcs" type="boolean" _gui-text=".PCS: Pfaff Embroidery Format">false</param> + + <param name="format-pec" type="boolean" _gui-text=".PEC: Brother Embroidery Format">false</param> + + <param name="format-pes" type="boolean" _gui-text=".PES: Brother Embroidery Format">false</param> + + <param name="format-plt" type="boolean" _gui-text=".PLT: AutoCAD Plot Drawing Format">false</param> + + <param name="format-rgb" type="boolean" _gui-text=".RGB: RGB Embroidery Format">false</param> + + <param name="format-thr" type="boolean" _gui-text=".THR: ThredWorks Embroidery Format">false</param> + + <param name="format-txt" type="boolean" _gui-text=".TXT: Text File">false</param> + + <param name="format-vp3" type="boolean" _gui-text=".VP3: Pfaff Embroidery Format">false</param> + + <param name="format-xxx" type="boolean" _gui-text=".XXX: Singer Embroidery Format">false</param> + + <param name="extension" type="string" gui-hidden="true">zip</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension> diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index ebdd2fc9..6d3e00d8 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -4,3 +4,5 @@ from params import Params 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/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/extensions/output.py b/lib/extensions/output.py new file mode 100644 index 00000000..f4b153e6 --- /dev/null +++ b/lib/extensions/output.py @@ -0,0 +1,51 @@ +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 +from ..utils.io import save_stdout + +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() + + # 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.real_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) diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py new file mode 100644 index 00000000..ca12efdd --- /dev/null +++ b/lib/extensions/zip.py @@ -0,0 +1,88 @@ +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 +from ..utils.io import save_stdout + + +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 = [] + + # 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.")) + + 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, os.path.basename(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.real_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) diff --git a/lib/utils/io.py b/lib/utils/io.py index be1fdf24..e5a246f3 100644 --- a/lib/utils/io.py +++ b/lib/utils/io.py @@ -7,12 +7,27 @@ 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(): os.dup2(sys.stderr_dup, 2) - sys.stderr_backup.write(sys.stderr.getvalue()) - sys.stderr = sys.stderr_backup + sys.real_stderr.write(sys.stderr.getvalue()) + sys.stderr = sys.real_stderr + +# 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 = StringIO() + + +def restore_stdout(): + os.dup2(sys.stdout_dup, 1) + sys.real_stdout.write(sys.stdout.getvalue()) + sys.stdout = sys.real_stdout diff --git a/messages.po b/messages.po index b872f864..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-12 20:18-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 <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\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." 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 @@ <command reldir="extensions" interpreter="python">inkstitch.py</command> </script> </inkscape-extension> - 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>{{ format | upper }} file output</_name> + <id>org.inkstitch.output.{{ format }}</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.{{ format }}</extension> + <mimetype>application/x-embroidery-{{ format }}</mimetype> + <_filetypename>Ink/Stitch: {{ description }} (.{{ format }})</_filetypename> + <_filetypetooltip>Save design in {{ format | upper }} format using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <param name="extension" type="string" gui-hidden="true">output</param> + <param name="format" type="string" gui-hidden="true">{{ format }}</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>embroidery ZIP file output</_name> + <id>org.inkstitch.output.zip</id> + <dependency type="executable" location="extensions">inkstitch.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.zip</extension> + <mimetype>application/zip</mimetype> + <_filetypename>Ink/Stitch: ZIP export multiple formats (.zip)</_filetypename> + <_filetypetooltip>Create a ZIP with multiple embroidery file formats using Ink/Stitch</_filetypetooltip> + <dataloss>true</dataloss> + </output> +{% for format, description in formats %} + <param name="format-{{format}}" type="boolean" _gui-text=".{{format | upper}}: {{description}}">false</param> +{% endfor %} + <param name="extension" type="string" gui-hidden="true">zip</param> + <script> + <command reldir="extensions" interpreter="python">inkstitch.py</command> + </script> +</inkscape-extension> |
