diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2024-06-26 22:51:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-26 22:51:15 +0200 |
| commit | 5f23dea1a1fa1708cc66d6aa951970bbd927515f (patch) | |
| tree | 859216fde8fcba8ebbec05cf2323f7a7dee8a4a8 /lib/extensions/thread_list.py | |
| parent | d2e571a3fbfa82baa1c0411fb4ee277692f574d3 (diff) | |
Make PNG (simple/realistic) and threadlist available in export file formats (#3019)
Diffstat (limited to 'lib/extensions/thread_list.py')
| -rw-r--r-- | lib/extensions/thread_list.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/extensions/thread_list.py b/lib/extensions/thread_list.py new file mode 100644 index 00000000..5603107a --- /dev/null +++ b/lib/extensions/thread_list.py @@ -0,0 +1,78 @@ +# Authors: see git history +# +# Copyright (c) 2024 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +import sys + +from ..i18n import _ +from ..stitch_plan import stitch_groups_to_stitch_plan +from ..threads import ThreadCatalog +from .base import InkstitchExtension + + +class ThreadList(InkstitchExtension): + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self) + + def effect(self): + if not self.get_elements(): + return + + self.metadata = self.get_inkstitch_metadata() + collapse_len = self.metadata['collapse_len_mm'] + min_stitch_len = self.metadata['min_stitch_len_mm'] + stitch_groups = self.elements_to_stitch_groups(self.elements) + stitch_plan = stitch_groups_to_stitch_plan(stitch_groups, collapse_len=collapse_len, min_stitch_len=min_stitch_len) + ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette']) + + thread_list = get_threadlist(stitch_plan, self.get_base_file_name()) + + # inkscape will read the file contents from stdout and copy + # to the destination file that the user chose + sys.stdout.write(thread_list) + + # don't let inkex output the SVG! + sys.exit(0) + + +def get_threadlist(stitch_plan, design_name): + width = round(stitch_plan.dimensions_mm[0], 2) + height = round(stitch_plan.dimensions_mm[1], 2) + + thread_used = [] + + thread_output = "%s\n" % _("Design Details") + thread_output += "==============================\n\n" + + thread_output += _("Title") + thread_output += f": {design_name}\n" + + thread_output += _("Size") + thread_output += f" (mm): {width}, {height}" + + thread_output += _("Stitches") + thread_output += f": {stitch_plan.num_stitches}\n" + + thread_output += _("Colors") + thread_output += f": {stitch_plan.num_colors}\n\n" + + thread_output += _("Thread Order") + thread_output += "\n===========================\n\n" + + for i, color_block in enumerate(stitch_plan): + thread = color_block.color + + thread_output += str(i + 1) + " " + string = f"{thread.name} #{thread.number} - {thread.manufacturer} (#{thread.hex_digits.lower()})" + thread_output += string + "\n" + thread_used.append(string) + + thread_output += "\n" + thread_output += _("Thread Used") + "\n" + thread_output += "===========================" + "\n\n" + + for thread in set(thread_used): + thread_output += thread + "\n" + + return thread_output |
