Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions octoprint_SpoolManager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ def get_settings_defaults(self):
settings[SettingsKeys.SETTINGS_KEY_QR_CODE_BACKGROUND_COLOR] = "#ffffff"
settings[SettingsKeys.SETTINGS_KEY_QR_CODE_WIDTH] = "100"
settings[SettingsKeys.SETTINGS_KEY_QR_CODE_HEIGHT] = "100"
settings[SettingsKeys.SETTINGS_KEY_QR_CODE_LABEL_WIDTH_MM] = "89"
settings[SettingsKeys.SETTINGS_KEY_QR_CODE_LABEL_HEIGHT_MM] = "36"

## Export / Import
settings[SettingsKeys.SETTINGS_KEY_IMPORT_CSV_MODE] = SettingsKeys.KEY_IMPORTCSV_MODE_APPEND
Expand Down
43 changes: 41 additions & 2 deletions octoprint_SpoolManager/api/SpoolManagerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,17 +765,56 @@ def generateSpoolQRCodeHTMLView(self, databaseId):
safeFinish = re.sub(r"[^\w\s#,()-]", "", str(spoolModel.finish))
finishHtml = "<h3>Spoolfinish: " + safeFinish + "</h3>"
htmlContent = \
"<div class='spm-label-text'>" \
"<h3>Database Id: " + str(spoolModel.databaseId) + "</h3>" \
"<h3>Spoolname: " + spoolModel.displayName + "</h3>" \
+ colorHtml \
+ finishHtml + \
"<img loading='lazy' src='" + qrCodeImageUrl + "' />"
"</div>" \
"<img loading='lazy' src='" + qrCodeImageUrl + "' />" \
"<button class='spm-print-btn' onclick='window.print()'>Print Label</button>"
else:
htmlContent = "<h3>Spool with database Id not found</h3>"

# Label printing (print button, @page label size) based on ideas from
# https://github.com/mdziekon/OctoPrint-SpoolManager/issues/47 (ScottGibb)
# and PRs mdziekon#54 / dojohnso#59 (reimplemented, not merged)
# label size for printing, from settings (fallback: Dymo 99012 address label)
def _labelDimension(settingsKey, defaultValue):
try:
value = float(self._settings.get([settingsKey]))
if (value <= 0):
return defaultValue
return value
except (TypeError, ValueError):
return defaultValue
labelWidthMM = _labelDimension(SettingsKeys.SETTINGS_KEY_QR_CODE_LABEL_WIDTH_MM, 89.0)
labelHeightMM = _labelDimension(SettingsKeys.SETTINGS_KEY_QR_CODE_LABEL_HEIGHT_MM, 36.0)
labelWidth = "%g" % labelWidthMM
labelHeight = "%g" % labelHeightMM
qrMaxHeight = "%g" % max(labelHeightMM - 4.0, 1.0)

qrCodeStyle = \
"<style>" \
"body{display:flex;flex-direction:column;align-items:center;" \
"justify-content:center;text-align:center;}" \
"img{max-width:100%;}" \
"h3{font-size:2em;margin:0.2em 0;}" \
".spm-print-btn{margin-top:12px;padding:6px 18px;font-size:1.1em;cursor:pointer;}" \
"@page{size:" + labelWidth + "mm " + labelHeight + "mm;margin:0;}" \
"@media print{" \
".spm-print-btn{display:none;}" \
"body{margin:0;height:" + labelHeight + "mm;flex-direction:row;justify-content:flex-start;" \
"align-items:center;gap:2mm;text-align:left;}" \
".spm-label-text{order:2;overflow:hidden;}" \
"img{max-height:" + qrMaxHeight + "mm;width:auto;order:1;margin-left:2mm;}" \
"h3{font-size:8pt;margin:0;}" \
"}" \
"</style>"

qrCodeHTMLViewTemplate = ""\
"<html>" \
"<head><link rel='icon' href='data:,'></head>" \
"<head><link rel='icon' href='data:,'>" + qrCodeStyle + "</head>" \
+ htmlContent +\
"</html>" \
""
Expand Down
2 changes: 2 additions & 0 deletions octoprint_SpoolManager/common/SettingsKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class SettingsKeys():
SETTINGS_KEY_QR_CODE_BACKGROUND_COLOR = "qrCodeBackgroundColor"
SETTINGS_KEY_QR_CODE_WIDTH = "qrCodeWidth"
SETTINGS_KEY_QR_CODE_HEIGHT = "qrCodeHeight"
SETTINGS_KEY_QR_CODE_LABEL_WIDTH_MM = "qrCodeLabelWidthMM"
SETTINGS_KEY_QR_CODE_LABEL_HEIGHT_MM = "qrCodeLabelHeightMM"

## Export / Import
SETTINGS_KEY_IMPORT_CSV_MODE = "importCSVMode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ Example: {material}-{color}-{id} becomes PETG-Silver-42."><i class="fas fa-info-
textInput: spoolDialog.spoolItemForEditing.finishCustomText" />
</div>
</div>
{# Preview-Label button, simple view only (full view: QR-code thumbnail is the link).
Idea from mdziekon#54 / dojohnso#59 (ScottGibb), reimplemented #}
<div class="control-group" style="margin-top: 12px;" data-bind="visible: spoolDialog.simpleMode() && spoolDialog.isExistingSpool() && pluginSettings.qrCodeEnabled()">
<label class="control-label">QR Label</label>
<div class="controls">
<a class="btn btn-small" target="_new"
data-bind="attr: $root.generateQRCodeImageSourceAttribute(spoolDialog.spoolItemForEditing.databaseId(),
spoolDialog.spoolItemForEditing.displayName(),
'htmlView')">Preview Label</a>
</div>
</div>
<div class="control-group no-bottom-gap" data-bind="visible: !spoolDialog.simpleMode()">
<label class="control-label">Flow Rate Compensation<sup>4</sup></label>
<div class="controls">
Expand Down
16 changes: 16 additions & 0 deletions octoprint_SpoolManager/templates/SpoolManager_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ FPE; 2.16
</div>
</div>
<hr/>
<div class="control-group">
<label class="control-label">Label size (print)</label>
<div class="controls">
<div class="input-append">
<input type="number" step="1" min="1" class="input-mini text-right" data-bind="value: pluginSettings.qrCodeLabelWidthMM">
<span class="add-on">mm</span>
</div>
&times;
<div class="input-append">
<input type="number" step="1" min="1" class="input-mini text-right" data-bind="value: pluginSettings.qrCodeLabelHeightMM">
<span class="add-on">mm</span>
</div>
<span class="help-block">Page size (width &times; height) used when printing the label via "Preview Label". Default 89 &times; 36 mm (Dymo 99012 address label).</span>
</div>
</div>
<hr/>
<div class="control-group">
<div class="controls">
<label class="checkbox">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
#
plugin_version = "1.8.0a3.dev87"
plugin_version = "1.8.0a3.dev90"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down