PrintJobOutputModel.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, pyqtSlot
  4. from typing import Optional
  5. MYPY = False
  6. if MYPY:
  7. from cura.PrinterOutput.PrinterOutputController import PrinterOutputController
  8. from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
  9. class PrintJobOutputModel(QObject):
  10. stateChanged = pyqtSignal()
  11. timeTotalChanged = pyqtSignal()
  12. timeElapsedChanged = pyqtSignal()
  13. nameChanged = pyqtSignal()
  14. keyChanged = pyqtSignal()
  15. assignedPrinterChanged = pyqtSignal()
  16. ownerChanged = pyqtSignal()
  17. def __init__(self, output_controller: "PrinterOutputController", key: str = "", name: str = "", parent=None):
  18. super().__init__(parent)
  19. self._output_controller = output_controller
  20. self._state = ""
  21. self._time_total = 0
  22. self._time_elapsed = 0
  23. self._name = name # Human readable name
  24. self._key = key # Unique identifier
  25. self._assigned_printer = None # type: Optional[PrinterOutputModel]
  26. self._owner = "" # Who started/owns the print job?
  27. @pyqtProperty(str, notify=ownerChanged)
  28. def owner(self):
  29. return self._owner
  30. def updateOwner(self, owner):
  31. if self._owner != owner:
  32. self._owner = owner
  33. self.ownerChanged.emit()
  34. @pyqtProperty(QObject, notify=assignedPrinterChanged)
  35. def assignedPrinter(self):
  36. return self._assigned_printer
  37. def updateAssignedPrinter(self, assigned_printer: "PrinterOutputModel"):
  38. if self._assigned_printer != assigned_printer:
  39. old_printer = self._assigned_printer
  40. self._assigned_printer = assigned_printer
  41. if old_printer is not None:
  42. # If the previously assigned printer is set, this job is moved away from it.
  43. old_printer.updateActivePrintJob(None)
  44. self.assignedPrinterChanged.emit()
  45. @pyqtProperty(str, notify=keyChanged)
  46. def key(self):
  47. return self._key
  48. def updateKey(self, key: str):
  49. if self._key != key:
  50. self._key = key
  51. self.keyChanged.emit()
  52. @pyqtProperty(str, notify = nameChanged)
  53. def name(self):
  54. return self._name
  55. def updateName(self, name: str):
  56. if self._name != name:
  57. self._name = name
  58. self.nameChanged.emit()
  59. @pyqtProperty(int, notify = timeTotalChanged)
  60. def timeTotal(self):
  61. return self._time_total
  62. @pyqtProperty(int, notify = timeElapsedChanged)
  63. def timeElapsed(self):
  64. return self._time_elapsed
  65. @pyqtProperty(str, notify=stateChanged)
  66. def state(self):
  67. return self._state
  68. def updateTimeTotal(self, new_time_total):
  69. if self._time_total != new_time_total:
  70. self._time_total = new_time_total
  71. self.timeTotalChanged.emit()
  72. def updateTimeElapsed(self, new_time_elapsed):
  73. if self._time_elapsed != new_time_elapsed:
  74. self._time_elapsed = new_time_elapsed
  75. self.timeElapsedChanged.emit()
  76. def updateState(self, new_state):
  77. if self._state != new_state:
  78. self._state = new_state
  79. self.stateChanged.emit()
  80. @pyqtSlot(str)
  81. def setState(self, state):
  82. self._output_controller.setJobState(self, state)