Skip to content

Commit

Permalink
1.0.3rc1
Browse files Browse the repository at this point in the history
add option to relocate progress bar, #113
rework save to uploads folder option, #107
  • Loading branch information
jneilliii committed Jul 8, 2023
1 parent 1b570b8 commit a675959
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
23 changes: 11 additions & 12 deletions octoprint_prusaslicerthumbnails/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def get_settings_defaults(self):
'inline_thumbnail_scale_value': "50", 'inline_thumbnail_position_left': False,
'align_inline_thumbnail': False, 'inline_thumbnail_align_value': "left", 'state_panel_thumbnail': True,
'state_panel_thumbnail_scale_value': "100", 'resize_filelist': False, 'filelist_height': "306",
'scale_inline_thumbnail_position': False, 'sync_on_refresh': False, 'use_uploads_folder': False}
'scale_inline_thumbnail_position': False, 'sync_on_refresh': False, 'use_uploads_folder': False,
'relocate_progress': False}

# ~~ AssetPlugin mixin

Expand Down Expand Up @@ -91,8 +92,8 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
if line.startswith(";") or line.startswith("\n") or line.startswith("M10086 ;") or line[0:4] in ["W220", "W221", "W222"]:
collectedString += line
self._logger.debug(collectedString)
test_str = collectedString.replace(octoprint.util.to_native_str('\r\n'), octoprint.util.to_native_str('\n'))
test_str = test_str.replace(octoprint.util.to_native_str(';\n;\n'), octoprint.util.to_native_str(';\n\n;\n'))
test_str = collectedString.replace(octoprint.util.to_unicode('\r\n'), octoprint.util.to_unicode('\n'))
test_str = test_str.replace(octoprint.util.to_unicode(';\n;\n'), octoprint.util.to_unicode(';\n\n;\n'))
matches = re.findall(regex, test_str, re.MULTILINE)
if len(matches) == 0: # MKS lottmaxx fallback
matches = regex_mks.findall(test_str)
Expand All @@ -117,10 +118,10 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
with open(gcode_filename, "rb") as gcode_file:
gcode_file.seek(58)
thumbbytes = gcode_file.read(14454)
if imghdr.what(file=None, h=thumbbytes) == 'bmp':
if imghdr.what(file=None, h=thumbbytes) == 'bmp':
self._logger.debug("Found flashprint thumbnail.")
matches = [thumbbytes]
use_flashprint = True
use_flashprint = True
if len(matches) == 0: # Creality Neo fallback
matches = re.findall(regex_creality, test_str, re.MULTILINE)
if len(matches) > 0:
Expand All @@ -147,14 +148,14 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
elif use_qidi:
self._logger.debug(matches)
elif use_flashprint:
png_file.write(self._extract_flashprint_thumbnail(matches))
png_file.write(self._extract_flashprint_thumbnail(matches))
else:
png_file.write(base64.b64decode(matches[choosen].replace("; ", "").encode()))

# Extracts a thumbnail from hex binary data usd by FlashPrint slicer
def _extract_flashprint_thumbnail(self, gcode_encoded_images):
encoded_image = gcode_encoded_images[0]

image = Image.open(io.BytesIO(encoded_image)).resize((160,120))
rgba = image.convert("RGBA")
pixels = rgba.getdata()
Expand Down Expand Up @@ -269,10 +270,7 @@ def on_event(self, event, payload):
gcode_filename = self._file_manager.path_on_disk("local", payload["path"])
self._extract_thumbnail(gcode_filename, thumbnail_filename)
if os.path.exists(thumbnail_filename):
if not self._settings.get_boolean(["use_uploads_folder"]):
thumbnail_url = "plugin/prusaslicerthumbnails/thumbnail/{}?{:%Y%m%d%H%M%S}".format(thumbnail_path.replace(thumbnail_name, quote(thumbnail_name)), datetime.datetime.now())
else:
thumbnail_url = "downloads/files/local/{}?{:%Y%m%d%H%M%S}".format(thumbnail_path.replace(thumbnail_name, quote(thumbnail_name)), datetime.datetime.now())
thumbnail_url = "plugin/prusaslicerthumbnails/thumbnail/{}?{:%Y%m%d%H%M%S}".format(thumbnail_path.replace(thumbnail_name, quote(thumbnail_name)), datetime.datetime.now())
self._file_manager.set_additional_metadata("local", payload["path"], "thumbnail", thumbnail_url.replace("//", "/"), overwrite=True)
self._file_manager.set_additional_metadata("local", payload["path"], "thumbnail_src", self._identifier, overwrite=True)

Expand Down Expand Up @@ -334,9 +332,10 @@ def get_extension_tree(self, *args, **kwargs):
def route_hook(self, server_routes, *args, **kwargs):
from octoprint.server.util.tornado import LargeResponseHandler, path_validation_factory
from octoprint.util import is_hidden_path
thumbnail_root_path = self._file_manager.path_on_disk("local", "") if self._settings.get_boolean(["use_uploads_folder"]) else self.get_plugin_data_folder()
return [
(r"thumbnail/(.*)", LargeResponseHandler,
{'path': self.get_plugin_data_folder(), 'as_attachment': False, 'path_validation': path_validation_factory(
{'path': thumbnail_root_path, 'as_attachment': False, 'path_validation': path_validation_factory(
lambda path: not is_hidden_path(path), status_code=404)})
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(function() {
self.file_details = ko.observable();
self.crawling_files = ko.observable(false);
self.crawl_results = ko.observableArray([]);
self.progress_bar_moved = false;

self.filesViewModel.prusaslicerthumbnails_open_thumbnail = function(data) {
if(data.thumbnail_src === "prusaslicerthumbnails"){
Expand Down Expand Up @@ -157,6 +158,10 @@ $(function() {
} else {
$('#state > div > hr:first').after('<img id="prusaslicer_state_thumbnail" class="pull-left" src="'+file_data.thumbnail+'" width="' + self.settingsViewModel.settings.plugins.prusaslicerthumbnails.state_panel_thumbnail_scale_value() + '%"/>');
}
if(self.settingsViewModel.settings.plugins.prusaslicerthumbnails.relocate_progress() && !self.progress_bar_moved) {
$('#state > div > div.progress.progress-text-centered').css({'margin-bottom': 'inherit'}).insertBefore('#prusaslicer_state_thumbnail').after('<hr>');
self.progress_bar_moved = true;
}
} else {
$('#prusaslicer_state_thumbnail').remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<span class="add-on">%</span>
</span>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="enable:settings.plugins.prusaslicerthumbnails.state_panel_thumbnail() == true, checked: settings.plugins.prusaslicerthumbnails.relocate_progress"> Relocate progress bar above thumbnail (requires browser refresh).
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.prusaslicerthumbnails.inline_thumbnail"> Use inline thumbnails.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Slicer Thumbnails"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.0.2"
plugin_version = "1.0.3rc1"

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

0 comments on commit a675959

Please sign in to comment.