From 378f079e6d15757ed6cb0b2e04f50642b5adaaac Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 21 Apr 2018 15:49:58 -0400 Subject: add ThreadCatalog and palette matching --- embroider_print.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'embroider_print.py') diff --git a/embroider_print.py b/embroider_print.py index cbdaeb09..7ab24876 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 @@ -290,6 +291,7 @@ class Print(InkstitchExtension): patches = self.elements_to_patches(self.elements) stitch_plan = patches_to_stitch_plan(patches) + ThreadCatalog().match_and_apply_palette(stitch_plan) render_stitch_plan(self.document.getroot(), stitch_plan) self.strip_namespaces() -- cgit v1.2.3 From c234d6ed2c7d8cd7b7991643dbec4383bed9e2dc Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 23 Apr 2018 23:12:48 -0400 Subject: UI to select different thread paette --- embroider_print.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'embroider_print.py') diff --git a/embroider_print.py b/embroider_print.py index 7ab24876..43efa758 100644 --- a/embroider_print.py +++ b/embroider_print.py @@ -291,7 +291,7 @@ class Print(InkstitchExtension): patches = self.elements_to_patches(self.elements) stitch_plan = patches_to_stitch_plan(patches) - ThreadCatalog().match_and_apply_palette(stitch_plan) + palette = ThreadCatalog().match_and_apply_palette(stitch_plan) render_stitch_plan(self.document.getroot(), stitch_plan) self.strip_namespaces() @@ -346,6 +346,8 @@ 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 -- cgit v1.2.3 From 8608508e0237b06bea5aac7558c695fd7bc8492b Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 24 Apr 2018 00:22:45 -0400 Subject: allow selection of a different thread palette --- embroider_print.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'embroider_print.py') diff --git a/embroider_print.py b/embroider_print.py index 43efa758..ee9193a8 100644 --- a/embroider_print.py +++ b/embroider_print.py @@ -99,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 @@ -178,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 @@ -291,7 +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) + 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() @@ -354,7 +384,7 @@ class Print(InkstitchExtension): # 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) -- cgit v1.2.3