summaryrefslogtreecommitdiff
path: root/embroider_print.py
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2018-04-29 21:29:53 -0400
committerGitHub <noreply@github.com>2018-04-29 21:29:53 -0400
commitdc4d0ce4e92454e16f40f0a84d00a8958b75740d (patch)
treef6f2309d1800e795c7aee9fa541f6321e03619ed /embroider_print.py
parentdc5c8c6314b11e1e194939dca3ab72f039a098d3 (diff)
parent7a80e59d7751b6c228f00be4853b1443a6233840 (diff)
Merge pull request #155 from lexelby/lexelby-thread-names
set thread names in PDF printout
Diffstat (limited to 'embroider_print.py')
-rw-r--r--embroider_print.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/embroider_print.py b/embroider_print.py
index cbdaeb09..ee9193a8 100644
--- a/embroider_print.py
+++ b/embroider_print.py
@@ -21,6 +21,7 @@ from inkstitch.extensions import InkstitchExtension
from inkstitch.stitch_plan import patches_to_stitch_plan
from inkstitch.svg import render_stitch_plan
from inkstitch.utils import save_stderr, restore_stderr
+from inkstitch.threads import ThreadCatalog
from jinja2 import Environment, FileSystemLoader, select_autoescape
from datetime import date
@@ -98,6 +99,7 @@ class PrintPreviewServer(Thread):
def __init__(self, *args, **kwargs):
self.html = kwargs.pop('html')
self.metadata = kwargs.pop('metadata')
+ self.stitch_plan = kwargs.pop('stitch_plan')
Thread.__init__(self, *args, **kwargs)
self.daemon = True
self.last_request_time = None
@@ -177,6 +179,35 @@ class PrintPreviewServer(Thread):
save_defaults(request.json['value'])
return "OK"
+ @self.app.route('/palette', methods=['POST'])
+ def set_palette():
+ name = request.json['name']
+ catalog = ThreadCatalog()
+ palette = catalog.get_palette_by_name(name)
+ catalog.apply_palette(self.stitch_plan, palette)
+
+ # clear any saved color or thread names
+ for field in self.metadata:
+ if field.startswith('color-') or field.startswith('thread-'):
+ del self.metadata[field]
+
+ self.metadata['thread-palette'] = name
+
+ return "OK"
+
+ @self.app.route('/threads', methods=['GET'])
+ def get_threads():
+ threads = []
+ for color_block in self.stitch_plan:
+ threads.append({
+ 'hex': color_block.color.hex_digits,
+ 'name': color_block.color.name,
+ 'manufacturer': color_block.color.manufacturer,
+ 'number': color_block.color.number,
+ })
+
+ return jsonify(threads)
+
def stop(self):
# for whatever reason, shutting down only seems possible in
# the context of a flask request, so we'll just make one
@@ -290,6 +321,7 @@ class Print(InkstitchExtension):
patches = self.elements_to_patches(self.elements)
stitch_plan = patches_to_stitch_plan(patches)
+ palette = ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette'])
render_stitch_plan(self.document.getroot(), stitch_plan)
self.strip_namespaces()
@@ -344,13 +376,15 @@ class Print(InkstitchExtension):
},
svg_overview = overview_svg,
color_blocks = stitch_plan.color_blocks,
+ palettes = ThreadCatalog().palette_names(),
+ selected_palette = palette.name,
)
# We've totally mucked with the SVG. Restore it so that we can save
# metadata into it.
self.document = deepcopy(self.original_document)
- print_server = PrintPreviewServer(html=html, metadata=self.get_inkstitch_metadata())
+ print_server = PrintPreviewServer(html=html, metadata=self.get_inkstitch_metadata(), stitch_plan=stitch_plan)
print_server.start()
time.sleep(1)