diff --git a/cura/CameraImageProvider.py b/cura/CameraImageProvider.py index ff5c51f24b..6a07f6b029 100644 --- a/cura/CameraImageProvider.py +++ b/cura/CameraImageProvider.py @@ -19,5 +19,11 @@ class CameraImageProvider(QQuickImageProvider): return image, QSize(15, 15) except AttributeError: - pass + try: + image = output_device.activeCamera.getImage() + + return image, QSize(15, 15) + except AttributeError: + pass + return QImage(), QSize(15, 15) diff --git a/plugins/UM3NetworkPrinting/ClusterControlItem.qml b/plugins/UM3NetworkPrinting/ClusterControlItem.qml index 2e67668741..50419c48ff 100644 --- a/plugins/UM3NetworkPrinting/ClusterControlItem.qml +++ b/plugins/UM3NetworkPrinting/ClusterControlItem.qml @@ -278,6 +278,14 @@ Component anchors.rightMargin: parent.rightMargin source: "camera-icon.svg" } + MouseArea + { + anchors.fill:parent + onClicked: + { + OutputDevice.setActiveCamera(modelData.camera) + } + } } } } diff --git a/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml b/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml index b39266b3e6..ff5fad5abd 100644 --- a/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml +++ b/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml @@ -89,17 +89,18 @@ Component PrinterVideoStream { - visible: OutputDevice.activePrinter != null + visible: OutputDevice.activeCamera != null anchors.fill: parent + camera: OutputDevice.activeCamera } onVisibleChanged: { - if (!monitorFrame.visible) + if (monitorFrame != null && !monitorFrame.visible) { // After switching the Tab ensure that active printer is Null, the video stream image // might be active - OutputDevice.setActivePrinter(null) + OutputDevice.setActiveCamera(null) } } } diff --git a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py index 6fffe2e3bf..7506a870a9 100644 --- a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py @@ -46,6 +46,7 @@ i18n_catalog = i18nCatalog("cura") class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): printJobsChanged = pyqtSignal() activePrinterChanged = pyqtSignal() + activeCameraChanged = pyqtSignal() # This is a bit of a hack, as the notify can only use signals that are defined by the class that they are in. # Inheritance doesn't seem to work. Tying them together does work, but i'm open for better suggestions. @@ -96,6 +97,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): self._latest_reply_handler = None # type: Optional[QNetworkReply] self._sending_job = None + self._active_camera = None # type: Optional[NetworkCamera] + def requestWrite(self, nodes: List[SceneNode], file_name: Optional[str] = None, limit_mimetypes: bool = False, file_handler: Optional[FileHandler] = None, **kwargs: str) -> None: self.writeStarted.emit(self) @@ -256,6 +259,10 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): def activePrinter(self) -> Optional[PrinterOutputModel]: return self._active_printer + @pyqtProperty(QObject, notify=activeCameraChanged) + def activeCamera(self) -> Optional[NetworkCamera]: + return self._active_camera + @pyqtSlot(QObject) def setActivePrinter(self, printer: Optional[PrinterOutputModel]) -> None: if self._active_printer != printer: @@ -264,6 +271,19 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): self._active_printer = printer self.activePrinterChanged.emit() + @pyqtSlot(QObject) + def setActiveCamera(self, camera: Optional[NetworkCamera]) -> None: + if self._active_camera != camera: + if self._active_camera: + self._active_camera.stop() + + self._active_camera = camera + + if self._active_camera: + self._active_camera.start() + + self.activeCameraChanged.emit() + def _onPostPrintJobFinished(self, reply: QNetworkReply) -> None: if self._progress_message: self._progress_message.hide() diff --git a/plugins/UM3NetworkPrinting/PrinterVideoStream.qml b/plugins/UM3NetworkPrinting/PrinterVideoStream.qml index 68758e095e..74c8ec8483 100644 --- a/plugins/UM3NetworkPrinting/PrinterVideoStream.qml +++ b/plugins/UM3NetworkPrinting/PrinterVideoStream.qml @@ -7,6 +7,8 @@ import UM 1.3 as UM Item { + property var camera: null + Rectangle { anchors.fill:parent @@ -17,7 +19,7 @@ Item MouseArea { anchors.fill: parent - onClicked: OutputDevice.setActivePrinter(null) + onClicked: OutputDevice.setActiveCamera(null) z: 0 } @@ -32,7 +34,7 @@ Item width: 20 * screenScaleFactor height: 20 * screenScaleFactor - onClicked: OutputDevice.setActivePrinter(null) + onClicked: OutputDevice.setActiveCamera(null) style: ButtonStyle { @@ -65,23 +67,24 @@ Item { if(visible) { - if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) + if(camera != null) { - OutputDevice.activePrinter.camera.start() + camera.start() } } else { - if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) + if(camera != null) { - OutputDevice.activePrinter.camera.stop() + camera.stop() } } } + source: { - if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null && OutputDevice.activePrinter.camera.latestImage) + if(camera != null && camera.latestImage != null) { - return OutputDevice.activePrinter.camera.latestImage; + return camera.latestImage; } return ""; } @@ -92,7 +95,7 @@ Item anchors.fill: cameraImage onClicked: { - OutputDevice.setActivePrinter(null) + OutputDevice.setActiveCamera(null) } z: 1 }