diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2023-07-22 06:43:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-22 06:43:40 +0200 |
| commit | 233340c0e72e96ba4c2b80fe0737c0a13884dcf7 (patch) | |
| tree | 76c0869cd81ac39525218d8721fd5fed7dc4d9e0 | |
| parent | 7dcb253d9b444ffadda389eca0b18280c7f428c4 (diff) | |
zip: add input field for custom file names (#2426)
| -rw-r--r-- | lib/extensions/zip.py | 40 | ||||
| -rw-r--r-- | templates/zip.xml | 44 |
2 files changed, 54 insertions, 30 deletions
diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index 155478f3..65e31b6c 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -27,6 +27,11 @@ class Zip(InkstitchExtension): def __init__(self, *args, **kwargs): InkstitchExtension.__init__(self) + self.arg_parser.add_argument('--notebook', type=Boolean, default=True) + self.arg_parser.add_argument('--file-formats', type=Boolean, default=True) + self.arg_parser.add_argument('--panelization', type=Boolean, default=True) + self.arg_parser.add_argument('--output-options', type=Boolean, default=True) + # it's kind of obnoxious that I have to do this... self.formats = [] for format in pyembroidery.supported_formats(): @@ -35,13 +40,16 @@ class Zip(InkstitchExtension): self.arg_parser.add_argument('--format-%s' % extension, type=Boolean, dest=extension) self.formats.append(extension) self.arg_parser.add_argument('--format-svg', type=Boolean, dest='svg') + self.formats.append('svg') self.arg_parser.add_argument('--format-threadlist', type=Boolean, dest='threadlist') + self.formats.append('threadlist') + self.arg_parser.add_argument('--x-repeats', type=int, dest='x_repeats', default=1) self.arg_parser.add_argument('--y-repeats', type=int, dest='y_repeats', default=1) self.arg_parser.add_argument('--x-spacing', type=float, dest='x_spacing', default=100) self.arg_parser.add_argument('--y-spacing', type=float, dest='y_spacing', default=100) - self.formats.append('svg') - self.formats.append('threadlist') + + self.arg_parser.add_argument('--custom-file-name', type=str, dest='custom_file_name', default='') def effect(self): if not self.get_elements(): @@ -54,15 +62,9 @@ class Zip(InkstitchExtension): stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) if self.options.x_repeats != 1 or self.options.y_repeats != 1: - dx = self.options.x_spacing * PIXELS_PER_MM - dy = self.options.y_spacing * PIXELS_PER_MM - offsets = [] - for x in range(self.options.x_repeats): - for y in range(self.options.y_repeats): - offsets.append(Point(x * dx, y * dy)) - stitch_plan = stitch_plan.make_offsets(offsets) - - base_file_name = self.get_base_file_name() + stitch_plan = self._make_offsets(stitch_plan) + + base_file_name = self._get_file_name() path = tempfile.mkdtemp() files = [] @@ -108,6 +110,22 @@ class Zip(InkstitchExtension): # don't let inkex output the SVG! sys.exit(0) + def _get_file_name(self): + if self.options.custom_file_name: + base_file_name = self.options.custom_file_name + else: + base_file_name = self.get_base_file_name() + return base_file_name + + def _make_offsets(self, stitch_plan): + dx = self.options.x_spacing * PIXELS_PER_MM + dy = self.options.y_spacing * PIXELS_PER_MM + offsets = [] + for x in range(self.options.x_repeats): + for y in range(self.options.y_repeats): + offsets.append(Point(x * dx, y * dy)) + return stitch_plan.make_offsets(offsets) + def get_threadlist(self, stitch_plan, design_name): ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette']) thread_used = [] diff --git a/templates/zip.xml b/templates/zip.xml index 1eafd662..86be0e65 100644 --- a/templates/zip.xml +++ b/templates/zip.xml @@ -9,25 +9,31 @@ <filetypetooltip>Create a ZIP with multiple embroidery file formats using Ink/Stitch</filetypetooltip> <dataloss>true</dataloss> </output> - <label>Panelization options (defaults to single design):</label> - <param name="x-repeats" type="int" min="1" max="20" gui-text="Horizontal repeats">1</param> - <param name="x-spacing" type="float" min="-1000" max="1000" gui-text="Horizontal spacing (mm)">100</param> - <param name="y-repeats" type="int" min="1" max="20" gui-text="Vertical repeats">1</param> - <param name="y-spacing" type="float" min="-1000" max="1000" gui-text="Vertical spacing (mm)">100</param> - - - <spacer/> - <label>Output formats:</label> - {%- for format, description, mimetype, category in formats %} - {%- if category != "vector" and category != "debug" %} - <param name="format-{{ format }}" type="boolean" _gui-text=".{{ format | upper }}: {{ description }}">false</param> - {%- endif %} - {%- endfor %} - - <param name="format-threadlist" type="boolean" gui-text=".TXT: Threadlist [COLOR]">false</param> - <param name="format-svg" type="boolean" gui-text=".SVG: Scalable Vector Graphic">false</param> - - <param name="extension" type="string" gui-hidden="true">zip</param> + <param name="notebook" type="notebook"> + <page name="file-formats" gui-text="File Formats"> + <label>Output formats:</label> + {%- for format, description, mimetype, category in formats %} + {%- if category != "vector" and category != "debug" %} + <param name="format-{{ format }}" type="boolean" _gui-text=".{{ format | upper }}: {{ description }}">false</param> + {%- endif %} + {%- endfor %} + <param name="format-threadlist" type="boolean" gui-text=".TXT: Threadlist [COLOR]">false</param> + <param name="format-svg" type="boolean" gui-text=".SVG: Scalable Vector Graphic">false</param> + <param name="extension" type="string" gui-hidden="true">zip</param> + </page> + <page name="panelization" gui-text="Panelization Options"> + <label>For single design set horizontal and vertical repeats to 1</label> + <spacer /> + <param name="x-repeats" type="int" min="1" max="20" gui-text="Horizontal repeats">1</param> + <param name="x-spacing" type="float" min="-1000" max="1000" gui-text="Horizontal spacing (mm)">100</param> + <param name="y-repeats" type="int" min="1" max="20" gui-text="Vertical repeats">1</param> + <param name="y-spacing" type="float" min="-1000" max="1000" gui-text="Vertical spacing (mm)">100</param> + </page> + <page name="output-options" gui-text="Output Options"> + <param name="custom-file-name" type="string" gui-text="Custom file name" + gui-description="Defines the file names inside the zip archive. Leave empty for default file name."></param> + </page> + </param> <script> {{ command_tag | safe }} </script> |
