diff --git a/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml b/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml index 5d819d9450..df102915ff 100644 --- a/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml +++ b/plugins/UM3NetworkPrinting/ClusterMonitorItem.qml @@ -62,7 +62,6 @@ Component } } - ScrollView { id: printerScrollView @@ -93,10 +92,10 @@ Component } } - /*PrinterVideoStream + PrinterVideoStream { - visible: OutputDevice.selectedPrinterName != "" + visible: OutputDevice.activePrinter != null anchors.fill:parent - }*/ + } } } diff --git a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py index 76d4c70752..3cee20a54f 100644 --- a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py @@ -15,10 +15,12 @@ from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply from PyQt5.QtGui import QDesktopServices -from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty +from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject from time import time from datetime import datetime +from typing import Optional + import json import os @@ -27,6 +29,7 @@ i18n_catalog = i18nCatalog("cura") class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): printJobsChanged = pyqtSignal() + activePrinterChanged = 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. @@ -54,6 +57,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): self._error_message = None self._progress_message = None + self._active_printer = None # type: Optional[PrinterOutputModel] + def requestWrite(self, nodes, file_name=None, filter_by_machine=False, file_handler=None, **kwargs): # Notify the UI that a switch to the print monitor should happen Application.getInstance().showPrintMonitor.emit(True) @@ -105,11 +110,20 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): self.postFormWithParts("print_jobs/", parts, onFinished=self._onPostPrintJobFinished, onProgress=self._onUploadPrintJobProgress) + @pyqtProperty(QObject, notify=activePrinterChanged) + def activePrinter(self) -> Optional["PrinterOutputModel"]: + return self._active_printer + + @pyqtSlot(QObject) + def setActivePrinter(self, printer): + if self._active_printer != printer: + self._active_printer = printer + self.activePrinterChanged.emit() + def _onPostPrintJobFinished(self, reply): self._progress_message.hide() self._compressing_gcode = False self._sending_gcode = False - Application.getInstance().showPrintMonitor.emit(False) def _onUploadPrintJobProgress(self, bytes_sent, bytes_total): if bytes_total > 0: diff --git a/plugins/UM3NetworkPrinting/PrinterInfoBlock.qml b/plugins/UM3NetworkPrinting/PrinterInfoBlock.qml index 3a7fd1fc74..6d7d6c8a7d 100644 --- a/plugins/UM3NetworkPrinting/PrinterInfoBlock.qml +++ b/plugins/UM3NetworkPrinting/PrinterInfoBlock.qml @@ -61,11 +61,11 @@ Rectangle { id: mouse anchors.fill:parent - onClicked: OutputDevice.selectPrinter(printer.unique_name, printer.friendly_name) + onClicked: OutputDevice.setActivePrinter(printer) hoverEnabled: true; // Only clickable if no printer is selected - enabled: OutputDevice.selectedPrinterName == "" && printer.state !== "unreachable" + enabled: OutputDevice.activePrinter == null && printer.state !== "unreachable" } Row diff --git a/plugins/UM3NetworkPrinting/PrinterVideoStream.qml b/plugins/UM3NetworkPrinting/PrinterVideoStream.qml index 6793d74ac5..d0a9e08232 100644 --- a/plugins/UM3NetworkPrinting/PrinterVideoStream.qml +++ b/plugins/UM3NetworkPrinting/PrinterVideoStream.qml @@ -17,7 +17,7 @@ Item MouseArea { anchors.fill: parent - onClicked: OutputDevice.selectAutomaticPrinter() + onClicked: OutputDevice.setActivePrinter(null) z: 0 } diff --git a/resources/qml/MonitorButton.qml b/resources/qml/MonitorButton.qml index a60eb0b3f3..778884ba00 100644 --- a/resources/qml/MonitorButton.qml +++ b/resources/qml/MonitorButton.qml @@ -70,8 +70,10 @@ Item property variant statusColor: { - if(!printerConnected || !printerAcceptsCommands) + if(!printerConnected || !printerAcceptsCommands || activePrinter == null) + { return UM.Theme.getColor("text"); + } switch(activePrinter.state) { @@ -117,7 +119,10 @@ Item } var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0] - + if(activePrinter == null) + { + return ""; + } if(activePrinter.state == "maintenance") { return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer"); @@ -262,7 +267,7 @@ Item property bool userClicked: false property string lastJobState: "" - visible: printerConnected && activePrinter.canPause + visible: printerConnected && activePrinter != null &&activePrinter.canPause enabled: (!userClicked) && printerConnected && printerAcceptsCommands && activePrintJob != null && (["paused", "printing"].indexOf(activePrintJob.state) >= 0) @@ -305,7 +310,7 @@ Item { id: abortButton - visible: printerConnected && activePrinter.canAbort + visible: printerConnected && activePrinter != null && activePrinter.canAbort enabled: printerConnected && printerAcceptsCommands && activePrintJob != null && (["paused", "printing", "pre_print"].indexOf(activePrintJob.state) >= 0)