UI to select different thread paette

pull/155/head
Lex Neva 2018-04-23 23:12:48 -04:00
rodzic 0700817a3b
commit c234d6ed2c
6 zmienionych plików z 145 dodań i 34 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -24,6 +24,9 @@ class _ThreadCatalog(Sequence):
for palette_file in glob(os.path.join(path, '*.gpl')):
self.palettes.append(ThreadPalette(palette_file))
def palette_names(self):
return list(sorted(palette.name for palette in self))
def __getitem__(self, item):
return self.palettes[item]
@ -36,13 +39,20 @@ class _ThreadCatalog(Sequence):
return sum(1 for thread in threads if thread in palette)
def match_and_apply_palette(self, stitch_plan):
"""Figure out which color palette was used and set thread names.
palette = self.match_palette(stitch_plan)
if palette is not None:
self.apply_palette(stitch_plan, palette)
return palette
def match_palette(self, stitch_plan):
"""Figure out which color palette was used
Scans the catalog of color palettes and chooses one that seems most
likely to be the one that the user used. A palette will only be
chosen if more tha 80% of the thread colors in the stitch plan are
exact matches for threads in the palette. All other threads will be
matched to the closest thread in the palette.
exact matches for threads in the palette.
"""
threads = [color_block.color for color_block in stitch_plan]
@ -53,14 +63,18 @@ class _ThreadCatalog(Sequence):
if matches < 0.8 * len(stitch_plan):
# if less than 80% of the colors are an exact match,
# don't use this palette
return
return None
else:
return palette
for thread in threads:
nearest = palette.nearest_color(thread)
def apply_palette(self, stitch_plan, palette):
for color_block in stitch_plan:
nearest = palette.nearest_color(color_block.color)
color_block.color.name = nearest.name
color_block.color.number = nearest.number
color_block.color.manufacturer = nearest.manufacturer
thread.name = nearest.name
thread.number = nearest.number
thread.manufacturer = nearest.manufacturer
_catalog = None

Wyświetl plik

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-04-28 20:42-0400\n"
"POT-Creation-Date: 2018-04-29 21:29-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -339,7 +339,7 @@ msgstr ""
msgid "rgb"
msgstr ""
msgid "thread used"
msgid "thread"
msgstr ""
msgid "# stitches"
@ -406,6 +406,9 @@ msgstr ""
msgid "Total nr trims"
msgstr ""
msgid "thread used"
msgstr ""
msgid "Enter operator notes..."
msgstr ""
@ -448,15 +451,36 @@ msgstr ""
msgid "⚠ lost connection to Ink/Stitch"
msgstr ""
msgid "Page Setup"
msgstr ""
msgid "Printing Size"
msgstr ""
msgid "Print Layouts"
msgstr ""
msgid "Includes all settings visible here and also the icon."
msgid "Includes these Page Setup settings and also the icon."
msgstr ""
msgid "Save as defaults"
msgstr ""
msgid "Design"
msgstr ""
msgid "Thread Palette"
msgstr ""
msgid ""
"Changing the thread palette will cause thread names and catalog numbers "
"to be recalculated based on the new palette. Any changes you have made "
"to color or thread names will be lost. Are you sure?"
msgstr ""
msgid "Yes"
msgstr ""
msgid "No"
msgstr ""

Wyświetl plik

@ -154,7 +154,7 @@ $(function() {
$('[contenteditable="true"]').on('focusout', function() {
/* change svg scale */
var content = $.trim($(this).text());
var content = $(this).html();
var field_name = $(this).attr('data-field-name');
if(field_name == 'svg-scale') {
var scale = parseInt(content);
@ -255,6 +255,26 @@ $(function() {
$.postJSON('/settings/paper-size', {value: size});
});
// Thread Palette
$('select#thread-palette').change(function(){
$('.modal').show();
}).on('update', function() {
$(this).data('current-value', $(this).find(':selected').val());
console.log("selected: " + $(this).data('current-value'));
}).trigger('update');
$('#modal-yes').on('click', function(){
// do shit with the newly-selected palette...
$("select#thread-palette").trigger("update");
$('.modal').hide();
});
$('#modal-no').on('click', function(){
var select = $("select#thread-palette");
select.find('[value="' + select.data('current-value') + '"]').prop('selected', true);
$('.modal').hide();
});
//Checkbox
$(':checkbox').change(function() {
var checked = $(this).prop('checked');

Wyświetl plik

@ -214,9 +214,6 @@ body {
border-bottom: 1px solid rgb(188, 188, 188);
border-bottom: 1px solid rgba(129, 129, 129, 0.5);
box-shadow: 0 1px 1px 1px rgba(194, 191, 191, 0.5);
}
#settings-ui div {
text-align: left;
font-size: 12pt;
}
@ -238,6 +235,33 @@ body {
margin-bottom: 1em;
}
#modal-background {
display: none;
z-index: 3;
position: fixed;
background: black;
opacity: 0.5;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
#modal-content {
display: none;
z-index: 4;
position: fixed;
width: 50%;
height: 25%%;
top: 200px;
left: 25%;
background: rgb(255, 255, 255);
border-bottom: 1px solid rgb(188, 188, 188);
box-shadow: 0 1px 1px 1px rgb(194, 191, 191);
text-align: center;
font-size: 16pt;
}
/* Header */

Wyświetl plik

@ -9,26 +9,53 @@
{{ _('⚠ lost connection to Ink/Stitch') }}
</div>
</div>
<div id="settings-ui">
<p id="close-settings">X</p>
<h1>{{ _('Settings') }}</h1>
<div>
<p>{{ _('Printing Size') }}:
<select id="printing-size" data-field-name="paper-size">
<option value="letter" selected="selected">Letter</option>
<option value="a4">A4</option>
<fieldset>
<legend>{{ _('Page Setup') }}</legend>
<div>
<p>{{ _('Printing Size') }}:
<select id="printing-size" data-field-name="paper-size">
<option value="letter" selected="selected">Letter</option>
<option value="a4">A4</option>
</select>
</p>
</div>
<div>
<fieldset>
<legend>{{ _('Print Layouts') }}</legend>
<p><input type="checkbox" id="client-overview" data-field-name="client-overview" /><label for="client-overview">Client Overview</label></p>
<p><input type="checkbox" id="client-detailedview" data-field-name="client-detailedview" /><label for="client-detailedview">Client Detailed View</label></p>
<p><input type="checkbox" id="operator-overview" data-field-name="operator-overview" CHECKED /><label for="operator-overview">Operator Overview</label></p>
<p><input type="checkbox" id="operator-detailedview" data-field-name="operator-detailedview" CHECKED /><label for="operator-detailedview">Operator Detailed View</label></p>
</fieldset>
<button id="save-settings" title="{{ _("Includes these Page Setup settings and also the icon.") }}">{{ _("Save as defaults") }}</button>
</div>
</fieldset>
<fieldset>
<legend>{{ _('Design') }}</legend>
<p>{{ _('Thread Palette') }}:
<select id="thread-palette" data-field-name="thread-palette">
{% if selected_palette is none %}
<option value="" selected>None</option>
{% endif %}
{% for palette in palettes %}
<option value="{{ palette }}" {{ "selected" if palette == selected_palette else "" }}>{{ palette }}</option>
{% endfor %}
</select>
</p>
</div>
<div>
<fieldset>
<legend>{{ _('Print Layouts') }}:</legend>
<p><input type="checkbox" id="client-overview" data-field-name="client-overview" /><label for="client-overview">Client Overview</label></p>
<p><input type="checkbox" id="client-detailedview" data-field-name="client-detailedview" /><label for="client-detailedview">Client Detailed View</label></p>
<p><input type="checkbox" id="operator-overview" data-field-name="operator-overview" CHECKED /><label for="operator-overview">Operator Overview</label></p>
<p><input type="checkbox" id="operator-detailedview" data-field-name="operator-detailedview" CHECKED /><label for="operator-detailedview">Operator Detailed View</label></p>
</fieldset>
<button id="save-settings" title="{{ _("Includes all settings visible here and also the icon.") }}">{{ _("Save as defaults") }}</button>
</div>
</fieldset>
</div>
<div id="modal-background" class="modal"></div>
<div id="modal-content" class="modal">
<p>
{{ _("Changing the thread palette will cause thread names and catalog numbers to be recalculated based on the new palette. Any changes you have made to color or thread names will be lost. Are you sure?") }}
</p>
<p>
<button id="modal-yes">{{ _("Yes") }}</button>
<button id="modal-no">{{ _("No") }}</button>
</p>
</div>