diff options
Diffstat (limited to 'embroider_print.py')
| -rw-r--r-- | embroider_print.py | 34 |
1 files changed, 32 insertions, 2 deletions
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) |
