UCPDialog.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (c) 2024 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os
  4. from PyQt6.QtCore import pyqtSignal, QObject
  5. from UM.FlameProfiler import pyqtSlot
  6. from UM.i18n import i18nCatalog
  7. from cura.CuraApplication import CuraApplication
  8. from .SettingsExportModel import SettingsExportModel
  9. i18n_catalog = i18nCatalog("cura")
  10. class UCPDialog(QObject):
  11. finished = pyqtSignal(bool)
  12. def __init__(self, parent = None) -> None:
  13. super().__init__(parent)
  14. plugin_path = os.path.dirname(__file__)
  15. dialog_path = os.path.join(plugin_path, 'UCPDialog.qml')
  16. self._model = SettingsExportModel()
  17. self._view = CuraApplication.getInstance().createQmlComponent(dialog_path,
  18. {"manager": self,
  19. "settingsExportModel": self._model})
  20. self._view.accepted.connect(self._onAccepted)
  21. self._view.rejected.connect(self._onRejected)
  22. self._finished = False
  23. self._accepted = False
  24. def show(self) -> None:
  25. self._view.show()
  26. def getModel(self) -> SettingsExportModel:
  27. return self._model
  28. @pyqtSlot()
  29. def notifyClosed(self):
  30. self._onFinished()
  31. @pyqtSlot()
  32. def _onAccepted(self):
  33. self._accepted = True
  34. self._onFinished()
  35. @pyqtSlot()
  36. def _onRejected(self):
  37. self._onFinished()
  38. def _onFinished(self):
  39. if not self._finished: # Make sure we don't send the finished signal twice, whatever happens
  40. self._finished = True
  41. self.finished.emit(self._accepted)