From e04bdb357156452a52ad91041e06efc74d08f65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 15 Nov 2016 10:28:14 +0100 Subject: [PATCH] Allow access to the current printed file position --- src/octoprint/printer/standard.py | 9 +++++++++ src/octoprint/util/comm.py | 14 +++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 5a9719bc..ac5b5be9 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -405,6 +405,15 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._setProgressData(completion=0) self._setCurrentZ(None) + def get_file_position(self): + if self._comm is None: + return None + + if self._selectedFile is None: + return None + + return self._comm.getFilePosition() + def start_print(self, pos=None): """ Starts the currently loaded print job. diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index aab9a111..d3c81d43 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -939,15 +939,23 @@ class MachineCom(object): ##~~ record aborted file positions - def _recordFilePosition(self): + def getFilePosition(self): if self._currentFile is None: - return + return None origin = self._currentFile.getFileLocation() filename = self._currentFile.getFilename() pos = self._currentFile.getFilepos() - self._callback.on_comm_record_fileposition(origin, filename, pos) + return dict(origin=origin, + filename=filename, + pos=pos) + + def _recordFilePosition(self): + if self._currentFile is None: + return + data = self.getFilePosition() + self._callback.on_comm_record_fileposition(data["origin"], data["filename"], data["pos"]) ##~~ communication monitoring and handling