LayerViewProxy.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty
  2. from UM.FlameProfiler import pyqtSlot
  3. from UM.Application import Application
  4. import LayerView
  5. class LayerViewProxy(QObject):
  6. def __init__(self, parent = None):
  7. super().__init__(parent)
  8. self._current_layer = 0
  9. self._controller = Application.getInstance().getController()
  10. self._controller.activeViewChanged.connect(self._onActiveViewChanged)
  11. self._onActiveViewChanged()
  12. currentLayerChanged = pyqtSignal()
  13. maxLayersChanged = pyqtSignal()
  14. activityChanged = pyqtSignal()
  15. globalStackChanged = pyqtSignal()
  16. preferencesChanged = pyqtSignal()
  17. @pyqtProperty(bool, notify = activityChanged)
  18. def layerActivity(self):
  19. active_view = self._controller.getActiveView()
  20. if type(active_view) == LayerView.LayerView.LayerView:
  21. return active_view.getActivity()
  22. @pyqtProperty(int, notify = maxLayersChanged)
  23. def numLayers(self):
  24. active_view = self._controller.getActiveView()
  25. if type(active_view) == LayerView.LayerView.LayerView:
  26. return active_view.getMaxLayers()
  27. @pyqtProperty(int, notify = currentLayerChanged)
  28. def currentLayer(self):
  29. active_view = self._controller.getActiveView()
  30. if type(active_view) == LayerView.LayerView.LayerView:
  31. return active_view.getCurrentLayer()
  32. @pyqtProperty(int, notify = currentLayerChanged)
  33. def minimumLayer(self):
  34. active_view = self._controller.getActiveView()
  35. if type(active_view) == LayerView.LayerView.LayerView:
  36. return active_view.getMinimumLayer()
  37. busyChanged = pyqtSignal()
  38. @pyqtProperty(bool, notify = busyChanged)
  39. def busy(self):
  40. active_view = self._controller.getActiveView()
  41. if type(active_view) == LayerView.LayerView.LayerView:
  42. return active_view.isBusy()
  43. return False
  44. @pyqtProperty(bool, notify = preferencesChanged)
  45. def compatibilityMode(self):
  46. active_view = self._controller.getActiveView()
  47. if type(active_view) == LayerView.LayerView.LayerView:
  48. return active_view.getCompatibilityMode()
  49. return False
  50. @pyqtSlot(int)
  51. def setCurrentLayer(self, layer_num):
  52. active_view = self._controller.getActiveView()
  53. if type(active_view) == LayerView.LayerView.LayerView:
  54. active_view.setLayer(layer_num)
  55. @pyqtSlot(int)
  56. def setMinimumLayer(self, layer_num):
  57. active_view = self._controller.getActiveView()
  58. if type(active_view) == LayerView.LayerView.LayerView:
  59. active_view.setMinimumLayer(layer_num)
  60. @pyqtSlot(int)
  61. def setLayerViewType(self, layer_view_type):
  62. active_view = self._controller.getActiveView()
  63. if type(active_view) == LayerView.LayerView.LayerView:
  64. active_view.setLayerViewType(layer_view_type)
  65. @pyqtSlot(result = int)
  66. def getLayerViewType(self):
  67. active_view = self._controller.getActiveView()
  68. if type(active_view) == LayerView.LayerView.LayerView:
  69. return active_view.getLayerViewType()
  70. return 0
  71. # Opacity 0..1
  72. @pyqtSlot(int, float)
  73. def setExtruderOpacity(self, extruder_nr, opacity):
  74. active_view = self._controller.getActiveView()
  75. if type(active_view) == LayerView.LayerView.LayerView:
  76. active_view.setExtruderOpacity(extruder_nr, opacity)
  77. @pyqtSlot(int)
  78. def setShowTravelMoves(self, show):
  79. active_view = self._controller.getActiveView()
  80. if type(active_view) == LayerView.LayerView.LayerView:
  81. active_view.setShowTravelMoves(show)
  82. @pyqtSlot(int)
  83. def setShowHelpers(self, show):
  84. active_view = self._controller.getActiveView()
  85. if type(active_view) == LayerView.LayerView.LayerView:
  86. active_view.setShowHelpers(show)
  87. @pyqtSlot(int)
  88. def setShowSkin(self, show):
  89. active_view = self._controller.getActiveView()
  90. if type(active_view) == LayerView.LayerView.LayerView:
  91. active_view.setShowSkin(show)
  92. @pyqtSlot(int)
  93. def setShowInfill(self, show):
  94. active_view = self._controller.getActiveView()
  95. if type(active_view) == LayerView.LayerView.LayerView:
  96. active_view.setShowInfill(show)
  97. @pyqtProperty(int, notify = globalStackChanged)
  98. def extruderCount(self):
  99. active_view = self._controller.getActiveView()
  100. if type(active_view) == LayerView.LayerView.LayerView:
  101. return active_view.getExtruderCount()
  102. return 0
  103. def _layerActivityChanged(self):
  104. self.activityChanged.emit()
  105. def _onLayerChanged(self):
  106. self.currentLayerChanged.emit()
  107. self._layerActivityChanged()
  108. def _onMaxLayersChanged(self):
  109. self.maxLayersChanged.emit()
  110. def _onBusyChanged(self):
  111. self.busyChanged.emit()
  112. def _onGlobalStackChanged(self):
  113. self.globalStackChanged.emit()
  114. def _onPreferencesChanged(self):
  115. self.preferencesChanged.emit()
  116. def _onActiveViewChanged(self):
  117. active_view = self._controller.getActiveView()
  118. if type(active_view) == LayerView.LayerView.LayerView:
  119. active_view.currentLayerNumChanged.connect(self._onLayerChanged)
  120. active_view.maxLayersChanged.connect(self._onMaxLayersChanged)
  121. active_view.busyChanged.connect(self._onBusyChanged)
  122. active_view.globalStackChanged.connect(self._onGlobalStackChanged)
  123. active_view.preferencesChanged.connect(self._onPreferencesChanged)