From 0501ae2fbceedeb123422bc64a1e17342dc5c5f4 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 25 Apr 2019 13:14:26 +0200 Subject: [PATCH] Handle case that printer type can be human readable string CURA-6449 --- .../Models/DiscoveredPrintersModel.py | 19 +++++++++++++++---- cura/Settings/MachineManager.py | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cura/Machines/Models/DiscoveredPrintersModel.py b/cura/Machines/Models/DiscoveredPrintersModel.py index 7e0721fcbe..a332eee50e 100644 --- a/cura/Machines/Models/DiscoveredPrintersModel.py +++ b/cura/Machines/Models/DiscoveredPrintersModel.py @@ -60,15 +60,26 @@ class DiscoveredPrinter(QObject): @pyqtProperty(str, notify = machineTypeChanged) def readableMachineType(self) -> str: from cura.CuraApplication import CuraApplication - readable_type = CuraApplication.getInstance().getMachineManager().getMachineTypeNameFromId(self._machine_type) - if not readable_type: - readable_type = catalog.i18nc("@label", "Unknown") + machine_manager = CuraApplication.getInstance().getMachineManager() + # In ClusterUM3OutputDevice, when it updates a printer information, it updates the machine type using the field + # "machine_variant", and for some reason, it's not the machine type ID/codename/... but a human-readable string + # like "Ultimaker 3". The code below handles this case. + if machine_manager.hasMachineTypeName(self._machine_type): + readable_type = self._machine_type + else: + readable_type = machine_manager.getMachineTypeNameFromId(self._machine_type) + if not readable_type: + readable_type = catalog.i18nc("@label", "Unknown") return readable_type @pyqtProperty(bool, notify = machineTypeChanged) def isUnknownMachineType(self) -> bool: from cura.CuraApplication import CuraApplication - readable_type = CuraApplication.getInstance().getMachineManager().getMachineTypeNameFromId(self._machine_type) + machine_manager = CuraApplication.getInstance().getMachineManager() + if machine_manager.hasMachineTypeName(self._machine_type): + readable_type = self._machine_type + else: + readable_type = machine_manager.getMachineTypeNameFromId(self._machine_type) return not readable_type @pyqtProperty(QObject, constant = True) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index bd766118a8..d35ce116ac 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -1640,6 +1640,10 @@ class MachineManager(QObject): return abbr_machine + def hasMachineTypeName(self, machine_type_name: str) -> bool: + results = self._container_registry.findDefinitionContainersMetadata(name = machine_type_name) + return len(results) > 0 + @pyqtSlot(str, result = str) def getMachineTypeNameFromId(self, machine_type_id: str) -> str: machine_type_name = ""