From 1c1c195b931705e8746b28ab65f0411501fca4ce Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 30 Nov 2017 15:01:28 +0100 Subject: [PATCH] When an printer gets added / removed, this is now correctly shown CL-541 --- .../ClusterUM3OutputDevice.py | 19 ++++++++++++++++++- .../PrintCoreConfiguration.qml | 2 +- resources/qml/MonitorButton.qml | 5 ++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py index f4675a2e0a..b64716c958 100644 --- a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py @@ -268,6 +268,9 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): return printer_list_changed = False # TODO: Ensure that printers that have been removed are also removed locally. + + printers_seen = [] + for printer_data in result: uuid = printer_data["uuid"] @@ -282,6 +285,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): self._printers.append(printer) printer_list_changed = True + printers_seen.append(printer) + printer.updateName(printer_data["friendly_name"]) printer.updateKey(uuid) printer.updateType(printer_data["machine_variant"]) @@ -292,7 +297,11 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): for index in range(0, self._number_of_extruders): extruder = printer.extruders[index] - extruder_data = printer_data["configuration"][index] + try: + extruder_data = printer_data["configuration"][index] + except IndexError: + break + try: hotend_id = extruder_data["print_core_id"] except KeyError: @@ -322,6 +331,14 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): color = color, name = name) extruder.updateActiveMaterial(material) + removed_printers = [printer for printer in self._printers if printer not in printers_seen] + + for removed_printer in removed_printers: + self._printers.remove(removed_printer) + printer_list_changed = True + if self._active_printer == removed_printer: + self._active_printer = None + self.activePrinterChanged.emit() if printer_list_changed: self.printersChanged.emit() diff --git a/plugins/UM3NetworkPrinting/PrintCoreConfiguration.qml b/plugins/UM3NetworkPrinting/PrintCoreConfiguration.qml index f0aeebd217..70fa65da5e 100644 --- a/plugins/UM3NetworkPrinting/PrintCoreConfiguration.qml +++ b/plugins/UM3NetworkPrinting/PrintCoreConfiguration.qml @@ -15,7 +15,7 @@ Item Label { id: materialLabel - text: printCoreConfiguration.activeMaterial.name + text: printCoreConfiguration.activeMaterial != null ? printCoreConfiguration.activeMaterial.name : "" elide: Text.ElideRight width: parent.width font: UM.Theme.getFont("very_small") diff --git a/resources/qml/MonitorButton.qml b/resources/qml/MonitorButton.qml index 778884ba00..d4861c830a 100644 --- a/resources/qml/MonitorButton.qml +++ b/resources/qml/MonitorButton.qml @@ -82,7 +82,10 @@ Item case "error": return UM.Theme.getColor("status_stopped"); } - + if(base.activePrintJob == null) + { + return UM.Theme.getColor("text"); + } switch(base.activePrintJob.state) { case "printing":