PauseBackend.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright ;(c) 2016 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from PyQt5.QtCore import QTimer
  4. from UM.Extension import Extension
  5. from UM.Application import Application
  6. from UM.PluginRegistry import PluginRegistry
  7. from UM.Logger import Logger
  8. from UM.Backend.Backend import BackendState
  9. from PyQt5.QtQml import QQmlComponent, QQmlContext
  10. from PyQt5.QtCore import QUrl, pyqtSlot, QObject
  11. import os.path
  12. class PauseBackend(QObject, Extension):
  13. def __init__(self, parent = None):
  14. super().__init__(parent = parent)
  15. self._additional_component = None
  16. self._additional_components_view = None
  17. Application.getInstance().engineCreatedSignal.connect(self._createAdditionalComponentsView)
  18. def _createAdditionalComponentsView(self):
  19. Logger.log("d", "Creating additional ui components for Pause Backend plugin.")
  20. path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("PauseBackendPlugin"), "PauseBackend.qml"))
  21. self._additional_component = QQmlComponent(Application.getInstance()._engine, path)
  22. # We need access to engine (although technically we can't)
  23. self._additional_components_context = QQmlContext(Application.getInstance()._engine.rootContext())
  24. self._additional_components_context.setContextProperty("manager", self)
  25. self._additional_components_view = self._additional_component.create(self._additional_components_context)
  26. if not self._additional_components_view:
  27. Logger.log("w", "Could not create additional components for Pause Backend plugin.")
  28. return
  29. Application.getInstance().addAdditionalComponent("saveButton", self._additional_components_view.findChild(QObject, "pauseResumeButton"))
  30. @pyqtSlot()
  31. def pauseBackend(self):
  32. backend = Application.getInstance().getBackend()
  33. backend.pauseSlicing()
  34. @pyqtSlot()
  35. def resumeBackend(self):
  36. backend = Application.getInstance().getBackend()
  37. backend.continueSlicing()
  38. backend.forceSlice()