diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index ba2d44d4d..6ae36dc50 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -82,6 +82,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._selectedFile = None self._estimator_factory = PrintTimeEstimator + self._estimator = None analysis_queue_hooks = plugin_manager().get_hooks("octoprint.printer.estimation.factory") for name, hook in analysis_queue_hooks.items(): try: @@ -134,7 +135,17 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): eventManager().subscribe(Events.METADATA_ANALYSIS_FINISHED, self._on_event_MetadataAnalysisFinished) eventManager().subscribe(Events.METADATA_STATISTICS_UPDATED, self._on_event_MetadataStatisticsUpdated) - def _create_estimator(self, job_type): + def _create_estimator(self, job_type=None): + if job_type is None: + with self._selectedFileMutex: + if self._selectedFile is None: + return + + if self._selectedFile["sd"]: + job_type = "sdcard" + else: + job_type = "local" + self._estimator = self._estimator_factory(job_type) #~~ handling of PrinterCallbacks @@ -494,12 +505,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if self._selectedFile is None: return - if self._selectedFile["sd"]: - job_type = "sdcard" - else: - job_type = "local" - - self._create_estimator(job_type) self._fileManager.delete_recovery_data() self._lastProgressReport = None @@ -749,6 +754,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): cleanedPrintTime = self._comm.getCleanedPrintTime() printTimeLeft = printTimeLeftOrigin = None + estimator = self._estimator if progress is not None: progress_int = int(progress * 100) if self._lastProgressReport != progress_int: @@ -761,7 +767,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): elif progress == 1.0: printTimeLeft = 0 printTimeLeftOrigin = None - else: + elif estimator is not None: statisticalTotalPrintTime = None statisticalTotalPrintTimeType = None with self._selectedFileMutex: @@ -770,11 +776,11 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): statisticalTotalPrintTime = self._selectedFile["estimatedPrintTime"] statisticalTotalPrintTimeType = self._selectedFile.get("estimatedPrintTimeType", None) - printTimeLeft, printTimeLeftOrigin = self._estimator.estimate(progress, - printTime, - cleanedPrintTime, - statisticalTotalPrintTime, - statisticalTotalPrintTimeType) + printTimeLeft, printTimeLeftOrigin = estimator.estimate(progress, + printTime, + cleanedPrintTime, + statisticalTotalPrintTime, + statisticalTotalPrintTimeType) return self._dict(completion=progress * 100 if progress is not None else None, filepos=filepos, @@ -1031,6 +1037,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): else: eventManager().fire(Events.FILE_DESELECTED) + self._create_estimator() + self._setJobData(full_path, size, sd, user=user) self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags())) @@ -1039,6 +1047,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self.start_print(pos=self._posAfterSelect, user=user) def on_comm_print_job_started(self, suppress_script=False): + self._stateMonitor.trigger_progress_update() payload = self._payload_for_print_job_event() if payload: eventManager().fire(Events.PRINT_STARTED, payload)