From 3889efa67a0fe4523333c57ce82197d7a25dca8d Mon Sep 17 00:00:00 2001 From: jneilliii Date: Sun, 18 Feb 2024 01:54:37 -0500 Subject: [PATCH] 0.0.14 fix cache file list issues optimize file listing to only update when retrieving file list and not while selecting or deleting a file don't remove intermediary file on local storage --- octoprint_bambu_printer/__init__.py | 13 ++-- .../static/js/bambu_printer.js | 68 ++++++++++++++++--- .../templates/bambu_printer_settings.jinja2 | 8 ++- octoprint_bambu_printer/virtual.py | 27 +++++--- setup.py | 2 +- 5 files changed, 91 insertions(+), 27 deletions(-) diff --git a/octoprint_bambu_printer/__init__.py b/octoprint_bambu_printer/__init__.py index 716eab8..a4c4ca0 100644 --- a/octoprint_bambu_printer/__init__.py +++ b/octoprint_bambu_printer/__init__.py @@ -10,11 +10,14 @@ class BambuPrintPlugin( - octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin + octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.AssetPlugin ): + + def get_assets(self): + return {'js': ["js/bambu_printer.js"]} def get_template_configs(self): - return [{"type": "settings", "custom_bindings": False}] + return [{"type": "settings", "custom_bindings": False}] #, {"type": "generic", "custom_bindings": True, "template": "bambu_printer.jinja2"}] def get_settings_defaults(self): return {"device_type": "X1C", @@ -31,7 +34,9 @@ def get_settings_defaults(self): "local_mqtt": True, "region": "", "email": "", - "auth_token": ""} + "auth_token": "", + "always_use_default_options": False + } def support_3mf_files(self): return {'machinecode': {'3mf': ["3mf"]}} @@ -50,7 +55,7 @@ def process(): elapsed = time.monotonic() - elapsed sd_upload_succeeded(filename, filename, elapsed) # remove local file after successful upload to Bambu - self._file_manager.remove_file("local", filename) + # self._file_manager.remove_file("local", filename) else: raise Exception("upload failed") except Exception as e: diff --git a/octoprint_bambu_printer/static/js/bambu_printer.js b/octoprint_bambu_printer/static/js/bambu_printer.js index 81e28b6..ebe1b51 100644 --- a/octoprint_bambu_printer/static/js/bambu_printer.js +++ b/octoprint_bambu_printer/static/js/bambu_printer.js @@ -4,26 +4,74 @@ * Author: jneilliii * License: AGPLv3 */ + $(function() { function Bambu_printerViewModel(parameters) { var self = this; - // assign the injected parameters, e.g.: - // self.loginStateViewModel = parameters[0]; - // self.settingsViewModel = parameters[1]; + self.settingsViewModel = parameters[0]; + self.filesViewModel = parameters[1]; + + /*$('#files div.upload-buttons > span.fileinput-button:first, #files div.folder-button').remove(); + $('#files div.upload-buttons > span.fileinput-button:first').removeClass('span6').addClass('input-block-level'); + + self.onBeforePrintStart = function(start_print_command) { + let confirmation_html = '' + + '
\n' + + '
\n' + + ' \n' + + '
\n' + + ' \n' + + '
\n' + + '
\n' + + '
'; + + if(!self.settingsViewModel.settings.plugins.bambu_printer.always_use_default_options()){ + confirmation_html += '\n' + + '
\n' + + '
\n' + + ' \n' + + ' \n' + + ' \n' + + '
\n' + + '
\n' + + ' \n' + + ' \n' + + ' \n' + + '
\n' + + '
\n'; + } - // TODO: Implement your plugin's view model here. + showConfirmationDialog({ + title: "Bambu Print Options", + html: confirmation_html, + cancel: gettext("Cancel"), + proceed: [gettext("Print"), gettext("Always")], + onproceed: function (idx) { + if(idx === 1){ + self.settingsViewModel.settings.plugins.bambu_printer.timelapse($('#bambu_printer_timelapse').is(':checked')); + self.settingsViewModel.settings.plugins.bambu_printer.bed_leveling($('#bambu_printer_bed_leveling').is(':checked')); + self.settingsViewModel.settings.plugins.bambu_printer.flow_cali($('#bambu_printer_flow_cali').is(':checked')); + self.settingsViewModel.settings.plugins.bambu_printer.vibration_cali($('#bambu_printer_vibration_cali').is(':checked')); + self.settingsViewModel.settings.plugins.bambu_printer.layer_inspect($('#bambu_printer_layer_inspect').is(':checked')); + self.settingsViewModel.settings.plugins.bambu_printer.use_ams($('#bambu_printer_use_ams').is(':checked')); + self.settingsViewModel.settings.plugins.bambu_printer.always_use_default_options(true); + self.settingsViewModel.saveData(); + } + // replace this with our own print command API call? + start_print_command(); + }, + nofade: true + }); + return false; + };*/ } - /* view model class, parameters for constructor, container to bind to - * Please see http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels for more details - * and a full list of the available options. - */ OCTOPRINT_VIEWMODELS.push({ construct: Bambu_printerViewModel, // ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ... - dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ], + dependencies: [ "settingsViewModel", "filesViewModel" ], // Elements to bind to, e.g. #settings_plugin_bambu_printer, #tab_plugin_bambu_printer, ... - elements: [ /* ... */ ] + elements: [ "#bambu_printer_print_options" ] }); }); diff --git a/octoprint_bambu_printer/templates/bambu_printer_settings.jinja2 b/octoprint_bambu_printer/templates/bambu_printer_settings.jinja2 index 7e4845a..727c081 100644 --- a/octoprint_bambu_printer/templates/bambu_printer_settings.jinja2 +++ b/octoprint_bambu_printer/templates/bambu_printer_settings.jinja2 @@ -27,7 +27,7 @@
- +
@@ -37,4 +37,10 @@
+ {#
+ +
+ +
+
#} diff --git a/octoprint_bambu_printer/virtual.py b/octoprint_bambu_printer/virtual.py index 939d4db..3fddf42 100644 --- a/octoprint_bambu_printer/virtual.py +++ b/octoprint_bambu_printer/virtual.py @@ -71,6 +71,7 @@ def __init__( self._sdPrintStarting = False self._sdPrintingSemaphore = threading.Event() self._sdPrintingPausedSemaphore = threading.Event() + self._sdFileListCache = {} self._selectedSdFile = None self._selectedSdFileSize = 0 self._selectedSdFilePos = 0 @@ -79,6 +80,7 @@ def __init__( self._busy_loop = None + import logging self._logger = logging.getLogger( @@ -172,8 +174,12 @@ def new_update(self, event_type): self._sdPrintStarting = False if not self._sdPrinting: filename = print_job.get("subtask_name") - if filename[-4:].lower() != ".3mf": - filename = print_job.get("gcode_file") + if not self._sdFileListCache.get(filename.lower()): + if self._sdFileListCache.get(f"{filename.lower()}.3mf"): + filename = f"{filename.lower()}.3mf" + elif self._sdFileListCache.get(f"{filename.lower()}.gcode.3mf"): + filename = f"{filename.lower()}.gcode.3mf" + self._selectSdFile(filename) self._startSdPrint(from_printer=True) @@ -670,11 +676,11 @@ def _mappedSdList(self) -> Dict[str, Dict[str, Any]]: for entry in filelistcache: if entry.startswith("/"): - filename = entry[1:] + filename = entry[1:].replace("cache/", "") else: - filename = entry - filesize = ftp.ftps_session.size("cache/"+entry) - date_str = ftp.ftps_session.sendcmd(f"MDTM cache/{entry}").replace("213 ", "") + filename = entry.replace("cache/", "") + filesize = ftp.ftps_session.size(entry) + date_str = ftp.ftps_session.sendcmd(f"MDTM {entry}").replace("213 ", "") filedate = datetime.datetime.strptime(date_str, "%Y%m%d%H%M%S").replace(tzinfo=datetime.timezone.utc).timestamp() dosname = get_dos_filename(filename, existing_filenames=list(result.keys())).lower() data = { @@ -690,15 +696,14 @@ def _mappedSdList(self) -> Dict[str, Dict[str, Any]]: return result def _getSdFileData(self, filename: str) -> Optional[Dict[str, Any]]: - files = self._mappedSdList() - data = files.get(filename.lower()) + data = self._sdFileListCache.get(filename.lower()) if isinstance(data, str): - data = files.get(data.lower()) + data = self._sdFileListCache.get(data.lower()) return data def _getSdFiles(self) -> List[Dict[str, Any]]: - files = self._mappedSdList() - return [x for x in files.values() if isinstance(x, dict)] + self._sdFileListCache = self._mappedSdList() + return [x for x in self._sdFileListCache.values() if isinstance(x, dict)] def _selectSdFile(self, filename: str, check_already_open: bool = False) -> None: if filename.startswith("/"): diff --git a/setup.py b/setup.py index e5cdd83..2cdb7bd 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-BambuPrinter" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.0.13" +plugin_version = "0.0.14" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module