diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index de36f43fc3..7bcc5ce25b 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -670,6 +670,12 @@ class CuraApplication(QtApplication): qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name) + ## Get the backend of the application (the program that does the heavy lifting). + # \returns Backend \type{Backend} + @pyqtSlot(result = "QObject*") + def getBackend(self): + return self._backend + def onSelectionChanged(self): if Selection.hasSelection(): if self.getController().getActiveTool(): diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 9a597d6ce0..10a9dd6dca 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -13,6 +13,7 @@ from UM.Resources import Resources from UM.Settings.Validator import ValidatorState #To find if a setting is in an error state. We can't slice then. from UM.Platform import Platform from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator +from PyQt5.QtCore import QObject, pyqtSlot from cura.Settings.ExtruderManager import ExtruderManager @@ -30,7 +31,7 @@ import Arcus from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") -class CuraEngineBackend(Backend): +class CuraEngineBackend(QObject, Backend): ## Starts the back-end plug-in. # # This registers all the signal listeners and prepares for communication @@ -146,6 +147,7 @@ class CuraEngineBackend(Backend): ## Emitted when the slicing process is aborted forcefully. slicingCancelled = Signal() + @pyqtSlot() def stopSlicing(self): self.backendStateChange.emit(BackendState.NotStarted) if self._slicing: # We were already slicing. Stop the old job. @@ -159,6 +161,14 @@ class CuraEngineBackend(Backend): if self._error_message: self._error_message.hide() + ## Manually triggers a reslice + @pyqtSlot() + def forceSlice(self): + if self._use_timer: + self._change_timer.start() + else: + self.slice() + ## Perform a slice of the scene. def slice(self): Logger.log("d", "Starting slice job...") @@ -449,13 +459,6 @@ class CuraEngineBackend(Backend): def _createSocket(self): super()._createSocket(os.path.abspath(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "Cura.proto"))) - ## Manually triggers a reslice - def forceSlice(self): - if self._use_timer: - self._change_timer.start() - else: - self.slice() - ## Called when anything has changed to the stuff that needs to be sliced. # # This indicates that we should probably re-slice soon. @@ -578,4 +581,4 @@ class CuraEngineBackend(Backend): return auto_slice = self.determineAutoSlicing() if auto_slice: - self._change_timer.start() \ No newline at end of file + self._change_timer.start() diff --git a/resources/qml/SaveButton.qml b/resources/qml/SaveButton.qml index e3a00b766b..a26e2a2957 100644 --- a/resources/qml/SaveButton.qml +++ b/resources/qml/SaveButton.qml @@ -133,12 +133,11 @@ Item { text: [1, 5].indexOf(UM.Backend.state) != -1 ? catalog.i18nc("@label:Printjob", "Prepare") : catalog.i18nc("@label:Printjob", "Cancel") onClicked: { + var backend = CuraApplication.getBackend() if ([1, 5].indexOf(UM.Backend.state) != -1) { - CuraApplication.log("Prepare...."); - CuraApplication.slice(); + backend.forceSlice(); } else { - CuraApplication.log("Cancel...."); - CuraApplication.sliceStop(); + backend.stopSlicing(); } }