LayerViewProxy.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, pyqtProperty
  2. from UM.Application import Application
  3. import LayerView
  4. class LayerViewProxy(QObject):
  5. def __init__(self, parent = None):
  6. super().__init__(parent)
  7. self._current_layer = 0
  8. self._controller = Application.getInstance().getController()
  9. self._controller.activeViewChanged.connect(self._onActiveViewChanged)
  10. self._onActiveViewChanged()
  11. currentLayerChanged = pyqtSignal()
  12. maxLayersChanged = pyqtSignal()
  13. activityChanged = pyqtSignal()
  14. @pyqtProperty(bool, notify = activityChanged)
  15. def getLayerActivity(self):
  16. active_view = self._controller.getActiveView()
  17. if type(active_view) == LayerView.LayerView.LayerView:
  18. return active_view.getActivity()
  19. @pyqtProperty(int, notify = maxLayersChanged)
  20. def numLayers(self):
  21. active_view = self._controller.getActiveView()
  22. if type(active_view) == LayerView.LayerView.LayerView:
  23. return active_view.getMaxLayers()
  24. #return 100
  25. @pyqtProperty(int, notify = currentLayerChanged)
  26. def currentLayer(self):
  27. active_view = self._controller.getActiveView()
  28. if type(active_view) == LayerView.LayerView.LayerView:
  29. return active_view.getCurrentLayer()
  30. @pyqtSlot(int)
  31. def setCurrentLayer(self, layer_num):
  32. active_view = self._controller.getActiveView()
  33. if type(active_view) == LayerView.LayerView.LayerView:
  34. active_view.setLayer(layer_num)
  35. def _layerActivityChanged(self):
  36. self.activityChanged.emit()
  37. def _onLayerChanged(self):
  38. self.currentLayerChanged.emit()
  39. self._layerActivityChanged()
  40. def _onMaxLayersChanged(self):
  41. self.maxLayersChanged.emit()
  42. def _onActiveViewChanged(self):
  43. active_view = self._controller.getActiveView()
  44. if type(active_view) == LayerView.LayerView.LayerView:
  45. active_view.currentLayerNumChanged.connect(self._onLayerChanged)
  46. active_view.maxLayersChanged.connect(self._onMaxLayersChanged)