From d4c95e080ffb80ceb6f10b663c7547b25689a840 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 21 Apr 2018 16:23:13 -0400 Subject: [PATCH] assign thread color names in printout --- inkstitch/extensions.py | 7 +++++- inkstitch/threads/catalog.py | 2 +- print/resources/inkstitch.js | 29 +++++++++++----------- print/templates/color_swatch.html | 18 +++++++------- print/templates/operator_detailedview.html | 13 +++++----- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/inkstitch/extensions.py b/inkstitch/extensions.py index 8d8a5fbb6..5befec9fa 100644 --- a/inkstitch/extensions.py +++ b/inkstitch/extensions.py @@ -55,7 +55,12 @@ class InkStitchMetadata(MutableMapping): # implement these five methods and we get a full dict-like interface. def __setitem__(self, name, value): - self._find_item(name).text = json.dumps(value) + item = self._find_item(name) + + if value: + item.text = json.dumps(value) + else: + item.getparent().remove(item) def _find_item(self, name): tag = inkex.addNS(name, "inkstitch") diff --git a/inkstitch/threads/catalog.py b/inkstitch/threads/catalog.py index 0f959a522..5bf75f676 100644 --- a/inkstitch/threads/catalog.py +++ b/inkstitch/threads/catalog.py @@ -54,7 +54,7 @@ class _ThreadCatalog(Sequence): return for thread in threads: - nearest = palette.find_nearest(thread) + nearest = palette.nearest_color(thread) thread.name = nearest.name thread.number = nearest.number diff --git a/print/resources/inkstitch.js b/print/resources/inkstitch.js index 498b12112..4a4e44561 100644 --- a/print/resources/inkstitch.js +++ b/print/resources/inkstitch.js @@ -24,17 +24,17 @@ function setPageNumbers() { // Scale SVG (fit || full size) function scaleSVG(element, scale = 'fit') { - + // always center svg transform = "translate(-50%, -50%)"; - + if(scale == 'fit') { var scale = Math.min( - element.width() / element.find('svg').width(), + element.width() / element.find('svg').width(), element.height() / element.find('svg').height() ); } - + transform += " scale(" + scale + ")"; var label = parseInt(scale*100); @@ -71,17 +71,17 @@ function setSVGTransform(figure, transform) { $(function() { setTimeout(ping, 1000); setPageNumbers(); - + /* SCALING AND MOVING SVG */ - + /* Mousewheel scaling */ $('figure.inksimulation').on( 'DOMMouseScroll mousewheel', function (e) { if(e.ctrlKey == true) { - + var svg = $(this).find('svg'); var transform = svg.css('transform').match(/-?[\d\.]+/g); var scale = parseFloat(transform[0]); - + if (e.originalEvent.detail > 0 || e.originalEvent.wheelDelta < 0) { // scroll down = zoom out scale *= 0.97; @@ -91,7 +91,7 @@ $(function() { //scroll up scale *= 1.03; } - + // set modified scale transform[0] = scale; transform[3] = scale; @@ -102,19 +102,19 @@ $(function() { return false; } }); - + /* Fit SVG */ $('button.svg-fit').click(function() { var svgfigure = $(this).closest('figure'); scaleSVG(svgfigure, 'fit'); }); - + /* Full Size SVG */ $('button.svg-full').click(function() { var svgfigure = $(this).closest('figure'); scaleSVG(svgfigure, '1'); }); - + /* Drag SVG */ $('figure.inksimulation').on('mousedown', function(e) { var p0 = { x: e.pageX, y: e.pageY }; @@ -141,7 +141,7 @@ $(function() { // set it using setSVGTransform() to ensure that it's saved to the server setSVGTransform($(this), $(this).find('svg').css('transform')); }); - + /* Apply transforms to All */ $('button.svg-apply').click(function() { var transform = $(this).parent().siblings('svg').css('transform'); @@ -154,7 +154,7 @@ $(function() { $('[contenteditable="true"]').on('focusout', function() { /* change svg scale */ - var content = $(this).html(); + var content = $.trim($(this).text()); var field_name = $(this).attr('data-field-name'); if(field_name == 'svg-scale') { var scale = parseInt(content); @@ -295,4 +295,3 @@ $(function() { $.postJSON('/defaults', {'value': settings}); }); }); - diff --git a/print/templates/color_swatch.html b/print/templates/color_swatch.html index 21cc0c21a..6785b0806 100644 --- a/print/templates/color_swatch.html +++ b/print/templates/color_swatch.html @@ -1,18 +1,18 @@ - + {% if printview != 'detailedview' %}
- {{ _('Color') }}: {{ color_block.color.thread_name }} + {{ _('Color') }}: {{ color_block.color.name }} {# We don't want to see rgb if we have more than 7 colorSwatches #} {% if color_blocks|length < 7 %} {{ _('rgb') }}: {{ color_block.color.rgb }} {% endif %} {# We don't want to see thread_used if we have more than 7 colorSwatches to show #} - {% if color_blocks|length < 7 %} - {{ _('thread used') }}: {{ color_block.color.thread_description }} + {% if color_blocks|length < 7 %} + {{ _('thread') }}: {{ color_block.color.manufacturer }} {{ "#" + color_block.color.number if color_block.color.number }} {% endif %} {# We don't want to see num_stitch if we have more than 49 colorSwatches to show #} {% if color_blocks|length < 49 %} @@ -27,9 +27,9 @@
- + {% else %} - +
@@ -37,9 +37,9 @@
-

{{ _('Color') }}:{{ color_block.color.thread_name }}

+

{{ _('Color') }}:{{ color_block.color.name }}

{{ _('rgb') }}:{{ color_block.color.rgb }}

-

{{ _('thread used') }}:{{ color_block.color.thread_description }}

+

{{ _('thread') }}:{{ color_block.color.manufacturer }} {{ "#" + color_block.color.number if color_block.color.number }}

{{ _('# stitches') }}:{{ color_block.num_stitches }}

{{ _('# stops') }}:{{ color_block.num_stops }}

{{ _('# trims') }}:{{ color_block.num_trims }}

@@ -47,5 +47,5 @@
- + {%endif %} diff --git a/print/templates/operator_detailedview.html b/print/templates/operator_detailedview.html index f78028d7c..0b948cb0f 100644 --- a/print/templates/operator_detailedview.html +++ b/print/templates/operator_detailedview.html @@ -1,7 +1,7 @@
{% include 'headline.html' %}
- +
@@ -39,7 +39,7 @@
{% endif %} {% for color_block in color_block_part %} - +

@@ -53,11 +53,12 @@ {{ color_block.svg_preview|safe }}

- {{ color_block.color.thread_name }} + {{ color_block.color.name }} {{ color_block.color.rgb }} + {{ color_block.color.manufacturer }} {{ "#" + color_block.color.number if color_block.color.number }}

- {{ _('thread used') }}: {{ color_block.color.thread_description }} + {{ _('thread used') }}: {{ _('# stitches') }}: {{ color_block.num_stitches }}

@@ -71,7 +72,5 @@ {% endfor %}

- + {% include 'footer.html' %} - -