From 85a8b6b1cfe008eed49c678bc0af9e2bea931f3c Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 13 Apr 2018 21:23:00 -0400 Subject: inkstitch metadata framework --- print/templates/headline.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'print/templates/headline.html') diff --git a/print/templates/headline.html b/print/templates/headline.html index 649c02ea..cbc9c43a 100644 --- a/print/templates/headline.html +++ b/print/templates/headline.html @@ -3,9 +3,9 @@
-

{{ job.title }}

-

{{ client }}

-

{{ purchase_order }}

+

+

+

{{ date|datetimeformat(_('%Y.%m.%d')) }}
-- cgit v1.3.1 From 7b0804562e4ce3b440e67de6cb001ac021326990 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 16 Apr 2018 20:17:07 -0400 Subject: add 'save as defaults' button --- embroider_print.py | 45 ++++++++++++++++++++++++++++++------ inkstitch/extensions.py | 6 ++++- messages.po | 11 ++++++++- print/resources/inkstitch.js | 54 ++++++++++++++++++++++++++++++++++--------- print/resources/style.css | 25 +++++++++++++++++++- print/templates/headline.html | 5 +++- print/templates/ui.html | 5 ++-- 7 files changed, 127 insertions(+), 24 deletions(-) (limited to 'print/templates/headline.html') diff --git a/embroider_print.py b/embroider_print.py index a8daece4..fa144d1d 100644 --- a/embroider_print.py +++ b/embroider_print.py @@ -11,6 +11,8 @@ import time import logging from copy import deepcopy import wx +import appdirs +import json import inkex import inkstitch @@ -33,6 +35,29 @@ def datetimeformat(value, format='%Y/%m/%d'): return value.strftime(format) +def defaults_path(): + defaults_dir = appdirs.user_config_dir('inkstitch') + + if not os.path.exists(defaults_dir): + os.makedirs(defaults_dir) + + return os.path.join(defaults_dir, 'print_settings.json') + + +def load_defaults(): + try: + with open(defaults_path(), 'r') as defaults_file: + defaults = json.load(defaults_file) + return defaults + except: + return {} + + +def save_defaults(defaults): + with open(defaults_path(), 'w') as defaults_file: + json.dump(defaults, defaults_file) + + def open_url(url): # Avoid spurious output from xdg-open. Any output on stdout will crash # inkscape. @@ -131,20 +156,26 @@ class PrintPreviewServer(Thread): # nothing to do here -- request_started() will restart the watcher return "OK" - @self.app.route('/metadata//set', methods=['POST']) + @self.app.route('/settings/', methods=['POST']) def set_field(field_name): self.metadata[field_name] = request.json['value'] return "OK" - @self.app.route('/metadata/', methods=['GET']) + @self.app.route('/settings/', methods=['GET']) def get_field(field_name): return jsonify(self.metadata[field_name]) - @self.app.route('/metadata', methods=['GET']) - def get_metadata(): - # It's necessary to convert the metadata to a dict because json doesn't - # trust that a MutableMapping is dict-like :( - return jsonify(dict(self.metadata)) + @self.app.route('/settings', methods=['GET']) + def get_settings(): + settings = {} + settings.update(load_defaults()) + settings.update(self.metadata) + return jsonify(settings) + + @self.app.route('/defaults', methods=['POST']) + def set_defaults(): + save_defaults(request.json['value']) + return "OK" def stop(self): # for whatever reason, shutting down only seems possible in diff --git a/inkstitch/extensions.py b/inkstitch/extensions.py index 0e0e49f8..70341cd3 100644 --- a/inkstitch/extensions.py +++ b/inkstitch/extensions.py @@ -42,7 +42,11 @@ class InkStitchMetadata(MutableMapping): metadata = self.document.find(SVG_METADATA_TAG) if metadata is None: - metadata = inkex.etree.SubElement(self.document, SVG_METADATA_TAG) + metadata = inkex.etree.SubElement(self.document.getroot(), SVG_METADATA_TAG) + + # move it so that it goes right after the first element, sodipodi:namedview + self.document.getroot().remove(metadata) + self.document.getroot().insert(1, metadata) return metadata diff --git a/messages.po b/messages.po index aa2a0523..c6ff2fde 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-04-02 22:11-0400\n" +"POT-Creation-Date: 2018-04-16 20:17-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -393,3 +393,12 @@ msgstr "" msgid "Printing Size" msgstr "" +msgid "Print Layouts" +msgstr "" + +msgid "Includes all settings visible here and also the icon." +msgstr "" + +msgid "Save as defaults" +msgstr "" + diff --git a/print/resources/inkstitch.js b/print/resources/inkstitch.js index 8123a31f..ab0b587d 100644 --- a/print/resources/inkstitch.js +++ b/print/resources/inkstitch.js @@ -58,20 +58,22 @@ $(function() { var content = $(this).html(); var field_name = $(this).attr('data-field-name'); $('[data-field-name="' + field_name + '"]').text(content); - $.postJSON('/metadata/' + field_name + '/set', {value: content}); + $.postJSON('/settings/' + field_name, {value: content}); }); // load up initial metadata values - $.getJSON('/metadata', function(metadata) { - $.each(metadata, function(field_name, value) { + $.getJSON('/settings', function(settings) { + $.each(settings, function(field_name, value) { $('[data-field-name="' + field_name + '"]').each(function(i, item) { - console.log(item); - if ($(item).is(':checkbox')) { - console.log("is a checkbox"); - $(item).prop('checked', value).trigger('change'); + var item = $(item); + if (item.is(':checkbox')) { + item.prop('checked', value).trigger('change'); + } else if (item.is('img')) { + item.attr('src', value); + } else if (item.is('select')) { + item.val(value).trigger('change'); } else { - console.log("is not a checkbox"); - $(item).text(value); + item.text(value); } }); }); @@ -121,7 +123,9 @@ $(function() { // Paper Size $('select#printing-size').change(function(){ - $('.page').toggleClass('a4'); + var size = $(this).find(':selected').val(); + $('.page').toggleClass('a4', size == 'a4'); + $.postJSON('/settings/paper-size', {value: size}); }); //Checkbox @@ -133,8 +137,36 @@ $(function() { setPageNumbers(); scaleInksimulation(); - $.postJSON('/metadata/' + field_name + '/set', {value: checked}); + $.postJSON('/settings/' + field_name, {value: checked}); }); + // Logo + $('#logo-picker').change(function(e) { + var file = e.originalEvent.srcElement.files[0]; + var reader = new FileReader(); + reader.onloadend = function() { + var data = reader.result; + $('figure.brandlogo img').attr('src', data); + $.postJSON('/settings/logo', {value: data}); + }; + reader.readAsDataURL(file); + }); + + // "save as defaults" button + $('#save-settings').click(function(e) { + var settings = {}; + settings["client-overview"] = $("[data-field-name='client-overview']").is(':checked'); + settings["client-detailedview"] = $("[data-field-name='client-detailedview']").is(':checked'); + settings["operator-overview"] = $("[data-field-name='operator-overview']").is(':checked'); + settings["operator-detailedview"] = $("[data-field-name='operator-detailedview']").is(':checked'); + settings["paper-size"] = $('select#printing-size').find(':selected').val(); + + var logo = $("figure.brandlogo img").attr('src'); + if (logo.startsWith("data:")) { + settings["logo"] = logo; + } + + $.postJSON('/defaults', {'value': settings}); + }); }); diff --git a/print/resources/style.css b/print/resources/style.css index 824f8dce..8be2370d 100644 --- a/print/resources/style.css +++ b/print/resources/style.css @@ -226,6 +226,10 @@ body { cursor: pointer; } + #settings-ui fieldset { + margin-bottom: 1em; + } + /* Header */ @@ -247,11 +251,30 @@ body { margin: 2.5mm; } + figure.brandlogo label { + display: block; + width: 100%; + height: 100%; + line-height: 30mm; + text-align: center; + } + figure.brandlogo img { max-width: 30mm; max-height: 30mm; + display: inline; + vertical-align: middle; } - + + /* hide the actual file picker control, since we just want them to click the + * image instead + */ + #logo-picker { + width: 0px; + height: 0px; + opacity: 0%; + } + .operator-detailedview figure.brandlogo { height: 20mm; width: 30mm; diff --git a/print/templates/headline.html b/print/templates/headline.html index cbc9c43a..421202e4 100644 --- a/print/templates/headline.html +++ b/print/templates/headline.html @@ -1,5 +1,8 @@
diff --git a/print/templates/ui.html b/print/templates/ui.html index 9acdd1bc..f7246962 100644 --- a/print/templates/ui.html +++ b/print/templates/ui.html @@ -15,7 +15,7 @@

{{ _('Settings') }}

{{ _('Printing Size') }}: - @@ -23,11 +23,12 @@

- {{ ('Print Layouts') }}: + {{ _('Print Layouts') }}:

+
-- cgit v1.3.1 From 8e3dd74a286d4549fdb1dd9cc7a9fcfadb85bb9e Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 28 Apr 2018 13:36:03 -0400 Subject: add hint about clicking logo --- messages.po | 5 ++- print/resources/style.css | 99 +++++++++++++++++++++++++------------------ print/templates/headline.html | 3 +- 3 files changed, 63 insertions(+), 44 deletions(-) (limited to 'print/templates/headline.html') diff --git a/messages.po b/messages.po index 27a25d3e..bce29cae 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-04-18 22:30-0400\n" +"POT-Creation-Date: 2018-04-28 13:36-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -317,6 +317,9 @@ msgstr "" msgid "Page" msgstr "" +msgid "Click to choose another logo" +msgstr "" + msgid "Enter job title..." msgstr "" diff --git a/print/resources/style.css b/print/resources/style.css index 013f567c..97dee6a8 100644 --- a/print/resources/style.css +++ b/print/resources/style.css @@ -69,7 +69,7 @@ page-break-after: always; margin: 0 !important; } - + figure.inksimulation div { display: none; } @@ -81,7 +81,7 @@ #settings-ui { display: none !important; } - + #errors { display: none !important; } @@ -90,6 +90,10 @@ content: attr(data-label); padding-right: 0.5em; } + + span.logo-instructions { + display: none; + } } @page { @@ -113,7 +117,7 @@ body { .page { width: 210mm; height: 275mm; - padding: 5mm; + padding: 5mm; background: #fff; margin: 0 auto; vertical-align: text-bottom; @@ -167,13 +171,13 @@ body { .ui button.close { border: 1px solid rgb(197,5,5); - + } .ui button.close:hover { background: rgb(197,5,5); color: white; - + } .ui button.settings { @@ -211,7 +215,7 @@ body { 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; @@ -279,13 +283,24 @@ body { opacity: 0%; } + .logo-instructions { + white-space: nowrap; + + /* chrome ignores this :( + text-align: center; + */ + + font-size: 10px; + color: rgb(192, 192, 192); + } + .operator-detailedview figure.brandlogo { height: 20mm; width: 30mm; margin: 0 2.5mm; text-align: left; } - + .operator-detailedview figure.brandlogo img { max-width: 30mm; max-height: 20mm; @@ -341,15 +356,15 @@ body { div.job-details p span:first-child { font-weight: bold; - padding-right: 1mm; + padding-right: 1mm; } div.job-details p span:last-child { - text-align: left; + text-align: left; } div.job-details > div:last-child span { - text-align: right !important; + text-align: right !important; } div.client-detailedview .job-details { @@ -374,16 +389,16 @@ body { font-size: 12pt; font-weight: bold; } - + /* client dedailed view header */ .client-detailedview div.job-details p span:first-child { - width: 20mm; + width: 20mm; } - + .client-detailedview div.job-details p span:last-child { - max-width: 60mm; + max-width: 60mm; } - + /* SVG Preview Image */ @@ -397,7 +412,7 @@ body { position: relative; overflow: hidden; } - + .client-overview-main figure.inksimulation { height: 155mm; } @@ -419,7 +434,7 @@ body { background: rgba(255, 255, 255, 0.73); padding: 5px; } - + figure.inksimulation div { position: absolute; bottom: 0; @@ -429,7 +444,7 @@ body { margin-right: auto; width: fit-content; } - + figure.inksimulation button { border: none; background: grey; @@ -460,7 +475,7 @@ body { font-weight: 700; font-size: 12pt; color: black; - background: white; + background: white; border: 0.5mm solid white; margin: 0px; padding: 0px; @@ -491,44 +506,44 @@ body { line-height: 30mm; text-align: center; } - + /* detailedview color swatch */ - + .color-palette.detailed > div { height: 100%; position: relative; } - + .color-palette.detailed .color-info { position: absolute; top: 2mm; left: 45mm; } - + .color-palette.detailed .color-info > div { display: table; } - + .color-palette.detailed .color-info p { display: table-row; } - + .color-palette.detailed .color-info span { display: table-cell; padding-right: 5mm; } - + /* Operator Detailed View */ .operator-detailedview header { height: 25mm; } - + .operator-detailedveiw figure.brandlogo{ height: 15mm; width: 15mm; } - + .operator-detailedveiw figure.brandlogo img { max-width: 12.5mm; max-height: 12.5mm; @@ -542,21 +557,21 @@ body { display: table; width: 100%; } - + .operator-job-info div { display: table-row; } - + div.job-headline { display: table-header-group; font-size: 9pt; font-weight: bold; } - + div.job-headline p { height: 1em; } - + .operator-job-info p { height: 15mm; max-width: 15mm; @@ -566,11 +581,11 @@ body { overflow: hidden; border: 1px solid rgb(239,239,239); } - + .operator-job-info span { display: block; } - + .operator-job-info span.color-index { position: absolute; top: 0; @@ -578,17 +593,17 @@ body { line-height: 15mm; width: 10mm; } - + .operator-svg.operator-colorswatch { width: 15mm; } - + .operator-svg.operator-preview { min-width: 15mm; max-width: 20mm; height: 15mm; } - + .operator-svg svg { position: absolute; top: 0; @@ -597,7 +612,7 @@ body { max-width: 30mm; height: 100%; } - + /* Footer */ @@ -610,7 +625,7 @@ body { white-space: wrap; text-align: center; padding-top: 2mm; - + } footer p.num_pages { @@ -670,7 +685,7 @@ body { /* five items */ .color-swatch:first-child:nth-last-child(n+5), .color-swatch:first-child:nth-last-child(n+5) ~ .color-swatch { - font-size: 9pt; + font-size: 9pt; width: calc(100% / 5); } @@ -710,7 +725,7 @@ body { /* fourteen items */ .color-swatch:first-child:nth-last-child(n+14), .color-swatch:first-child:nth-last-child(n+14) ~ .color-swatch { - width: calc(100% / 5); + width: calc(100% / 5); } /* sixteen items */ @@ -762,7 +777,7 @@ body { .color-swatch:first-child:nth-last-child(n+40) ~ .color-swatch { width: calc(100% / 12); } - + /* fourty-nine items */ .color-swatch:first-child:nth-last-child(n+49), .color-swatch:first-child:nth-last-child(n+40) ~ .color-swatch { diff --git a/print/templates/headline.html b/print/templates/headline.html index 421202e4..7a7059b9 100644 --- a/print/templates/headline.html +++ b/print/templates/headline.html @@ -3,6 +3,7 @@ {{ logo.title }} + {{ _("Click to choose another logo") }}
@@ -10,6 +11,6 @@

- +
{{ date|datetimeformat(_('%Y.%m.%d')) }}
-- cgit v1.3.1