From 8bb2671a28aaf213ba3ee98f967a0c26b336016e Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 2 Sep 2022 15:35:59 +0200 Subject: [PATCH 1/8] Don't show abstract machines in configuration page So they cannot be removed through the preferences CURA-9289 --- cura/Machines/Models/GlobalStacksModel.py | 22 ++++++++++++++++++++++ resources/qml/Preferences/MachinesPage.qml | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cura/Machines/Models/GlobalStacksModel.py b/cura/Machines/Models/GlobalStacksModel.py index 8f13d34ccf..69f2ec3822 100644 --- a/cura/Machines/Models/GlobalStacksModel.py +++ b/cura/Machines/Models/GlobalStacksModel.py @@ -44,6 +44,7 @@ class GlobalStacksModel(ListModel): self._filter_connection_type = None # type: Optional[ConnectionType] self._filter_online_only = False self._filter_capabilities: List[str] = [] # Required capabilities that all listed printers must have. + self._filter_abstract_machines: Optional[bool] = None # Listen to changes CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerChanged) @@ -54,6 +55,7 @@ class GlobalStacksModel(ListModel): filterConnectionTypeChanged = pyqtSignal() filterCapabilitiesChanged = pyqtSignal() filterOnlineOnlyChanged = pyqtSignal() + filterAbstractMachinesChanged = pyqtSignal() def setFilterConnectionType(self, new_filter: Optional[ConnectionType]) -> None: if self._filter_connection_type != new_filter: @@ -98,6 +100,22 @@ class GlobalStacksModel(ListModel): """ return self._filter_capabilities + def setFilterAbstractMachines(self, new_filter: Optional[bool]) -> None: + if self._filter_abstract_machines != new_filter: + self._filter_abstract_machines = new_filter + self.filterAbstractMachinesChanged.emit() + + @pyqtProperty(bool, fset = setFilterAbstractMachines, notify = filterAbstractMachinesChanged) + def filterAbstractMachines(self) -> Optional[bool]: + """ + Weather we include abstract printers, non-abstract printers or both + + if this is set to None both abstract and non-abstract printers will be included in the list + set to True will only include abstract printers + set to False will only inclde non-abstract printers + """ + return self._filter_abstract_machines + def _onContainerChanged(self, container) -> None: """Handler for container added/removed events from registry""" @@ -130,6 +148,10 @@ class GlobalStacksModel(ListModel): if self._filter_online_only and not is_online: continue + is_abstract_machine = parseBool(container_stack.getMetaDataEntry("is_abstract_machine", False)) + if self._filter_abstract_machines is not None and self._filter_abstract_machines is not is_abstract_machine: + continue + capabilities = set(container_stack.getMetaDataEntry(META_CAPABILITIES, "").split(",")) if set(self._filter_capabilities) - capabilities: # Not all required capabilities are met. continue diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index c77545bc03..258b45292e 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -17,7 +17,7 @@ UM.ManagementPage title: catalog.i18nc("@title:tab", "Printers") detailsPlaneCaption: base.currentItem && base.currentItem.name ? base.currentItem.name : "" - model: Cura.GlobalStacksModel { } + model: Cura.GlobalStacksModel { filterAbstractMachines: false } sectionRole: "discoverySource" From 27fc11b8404ed84a9b95b2fdddab239d2cd3c93b Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 2 Sep 2022 15:48:22 +0200 Subject: [PATCH 2/8] Prevent abstract machines from being deleted in the config menu CURA-9277 --- cura/Machines/Models/GlobalStacksModel.py | 3 ++- resources/qml/Preferences/MachinesPage.qml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cura/Machines/Models/GlobalStacksModel.py b/cura/Machines/Models/GlobalStacksModel.py index 69f2ec3822..62b470daee 100644 --- a/cura/Machines/Models/GlobalStacksModel.py +++ b/cura/Machines/Models/GlobalStacksModel.py @@ -172,6 +172,7 @@ class GlobalStacksModel(ListModel): "metadata": container_stack.getMetaData().copy(), "discoverySource": section_name, "removalWarning": removal_warning, - "isOnline": is_online}) + "isOnline": is_online, + "isAbstractMachine": is_abstract_machine}) items.sort(key=lambda i: (not i["hasRemoteConnection"], i["name"])) self.setItems(items) diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index 258b45292e..16f144cf85 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -17,7 +17,7 @@ UM.ManagementPage title: catalog.i18nc("@title:tab", "Printers") detailsPlaneCaption: base.currentItem && base.currentItem.name ? base.currentItem.name : "" - model: Cura.GlobalStacksModel { filterAbstractMachines: false } + model: Cura.GlobalStacksModel { } sectionRole: "discoverySource" @@ -139,7 +139,7 @@ UM.ManagementPage Cura.MenuItem { text: catalog.i18nc("@action:button", "Remove") - enabled: base.currentItem != null && model.count > 1 + enabled: base.currentItem != null && model.count > 1 && !base.currentItem.isAbstractMachine onTriggered: confirmDialog.open() } Cura.MenuItem From 6d0acbe0952408cbe4c08961127a99ee7d8be59e Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 2 Sep 2022 16:28:10 +0200 Subject: [PATCH 3/8] Always show correct number of connected machines Calculate number of connected machines _after_ the abstract machine its connected is removed from the list CURA-9277 --- cura/Machines/Models/MachineListModel.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index 55db072180..d3ae8f7acb 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -89,12 +89,13 @@ class MachineListModel(ListModel): machines_manager = CuraApplication.getInstance().getMachineManager() online_machine_stacks = machines_manager.getMachinesWithDefinition(definition_id, online_only = True) - # Create a list item for abstract machine - self.addItem(abstract_machine, len(online_machine_stacks)) other_machine_stacks.remove(abstract_machine) if abstract_machine in online_machine_stacks: online_machine_stacks.remove(abstract_machine) + # Create a list item for abstract machine + self.addItem(abstract_machine, len(online_machine_stacks)) + # Create list of machines that are children of the abstract machine for stack in online_machine_stacks: if self._show_cloud_printers: From ce6d7d72bd0194e3146e153450ce7d3fa7045d30 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Mon, 5 Sep 2022 11:14:13 +0200 Subject: [PATCH 4/8] Fix calculating number of removed devices CURA-9277 --- .../UM3NetworkPrinting/src/Messages/RemovedPrintersMessage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/Messages/RemovedPrintersMessage.py b/plugins/UM3NetworkPrinting/src/Messages/RemovedPrintersMessage.py index c875eb183a..caed6ddf91 100644 --- a/plugins/UM3NetworkPrinting/src/Messages/RemovedPrintersMessage.py +++ b/plugins/UM3NetworkPrinting/src/Messages/RemovedPrintersMessage.py @@ -31,7 +31,7 @@ class RemovedPrintersMessage(Message): super().__init__(title=self.i18n_catalog.i18ncp("info:status", "A cloud connection is not available for a printer", "A cloud connection is not available for some printers", - len(self.removed_devices)), + len(self._removed_devices)), message_type=Message.MessageType.WARNING, text = message_text) From 48b8585ce669a1e52bb21968a727acc8268cae3e Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Mon, 5 Sep 2022 11:44:29 +0200 Subject: [PATCH 5/8] Make sure online printers are always shown in the correct tab CURA-9277 --- cura/Machines/Models/MachineListModel.py | 27 +++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index d3ae8f7acb..ead1061a05 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -89,17 +89,27 @@ class MachineListModel(ListModel): machines_manager = CuraApplication.getInstance().getMachineManager() online_machine_stacks = machines_manager.getMachinesWithDefinition(definition_id, online_only = True) + def online_machines_has_connection_filter(machine_stack): + # This is required because machines loaded from projects have the is_online="True" but no connection type. + # We want to display them the same way as unconnected printers in this case. + has_connection = False + for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]: + has_connection |= connection_type in machine_stack.configuredConnectionTypes + return has_connection + + online_machine_stacks = list(filter(online_machines_has_connection_filter, online_machine_stacks)) + other_machine_stacks.remove(abstract_machine) if abstract_machine in online_machine_stacks: online_machine_stacks.remove(abstract_machine) # Create a list item for abstract machine - self.addItem(abstract_machine, len(online_machine_stacks)) + self.addItem(abstract_machine, True, len(online_machine_stacks)) # Create list of machines that are children of the abstract machine for stack in online_machine_stacks: if self._show_cloud_printers: - self.addItem(stack) + self.addItem(stack, True) # Remove this machine from the other stack list if stack in other_machine_stacks: other_machine_stacks.remove(stack) @@ -119,25 +129,18 @@ class MachineListModel(ListModel): }) for stack in other_machine_stacks: - self.addItem(stack) + self.addItem(stack, False) - def addItem(self, container_stack: ContainerStack, machine_count: int = 0) -> None: + def addItem(self, container_stack: ContainerStack, is_online, machine_count: int = 0) -> None: if parseBool(container_stack.getMetaDataEntry("hidden", False)): return - # This is required because machines loaded from projects have the is_online="True" but no connection type. - # We want to display them the same way as unconnected printers in this case. - has_connection = False - has_connection |= parseBool(container_stack.getMetaDataEntry("is_abstract_machine", False)) - for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]: - has_connection |= connection_type in container_stack.configuredConnectionTypes - self.appendItem({ "componentType": "MACHINE", "name": container_stack.getName(), "id": container_stack.getId(), "metadata": container_stack.getMetaData().copy(), - "isOnline": parseBool(container_stack.getMetaDataEntry("is_online", False)) and has_connection, + "isOnline": is_online, "isAbstractMachine": parseBool(container_stack.getMetaDataEntry("is_abstract_machine", False)), "machineCount": machine_count, }) From b6a461bd08d0e5f5a471586e1e1212e0187439f6 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Mon, 5 Sep 2022 17:32:23 +0200 Subject: [PATCH 6/8] Revert "Prevent abstract machines from being deleted in the config menu" This reverts commit 27fc11b8404ed84a9b95b2fdddab239d2cd3c93b. --- cura/Machines/Models/GlobalStacksModel.py | 3 +-- resources/qml/Preferences/MachinesPage.qml | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cura/Machines/Models/GlobalStacksModel.py b/cura/Machines/Models/GlobalStacksModel.py index 62b470daee..69f2ec3822 100644 --- a/cura/Machines/Models/GlobalStacksModel.py +++ b/cura/Machines/Models/GlobalStacksModel.py @@ -172,7 +172,6 @@ class GlobalStacksModel(ListModel): "metadata": container_stack.getMetaData().copy(), "discoverySource": section_name, "removalWarning": removal_warning, - "isOnline": is_online, - "isAbstractMachine": is_abstract_machine}) + "isOnline": is_online}) items.sort(key=lambda i: (not i["hasRemoteConnection"], i["name"])) self.setItems(items) diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index 16f144cf85..258b45292e 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -17,7 +17,7 @@ UM.ManagementPage title: catalog.i18nc("@title:tab", "Printers") detailsPlaneCaption: base.currentItem && base.currentItem.name ? base.currentItem.name : "" - model: Cura.GlobalStacksModel { } + model: Cura.GlobalStacksModel { filterAbstractMachines: false } sectionRole: "discoverySource" @@ -139,7 +139,7 @@ UM.ManagementPage Cura.MenuItem { text: catalog.i18nc("@action:button", "Remove") - enabled: base.currentItem != null && model.count > 1 && !base.currentItem.isAbstractMachine + enabled: base.currentItem != null && model.count > 1 onTriggered: confirmDialog.open() } Cura.MenuItem From 6253fb2fdc1340a0c457771c7eb6b44f081a5215 Mon Sep 17 00:00:00 2001 From: Casper Lamboo Date: Tue, 6 Sep 2022 13:19:50 +0200 Subject: [PATCH 7/8] Add typing to function argument CURA-9277 Co-authored-by: Joey de l'Arago --- cura/Machines/Models/MachineListModel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index ead1061a05..8750da6305 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -131,7 +131,7 @@ class MachineListModel(ListModel): for stack in other_machine_stacks: self.addItem(stack, False) - def addItem(self, container_stack: ContainerStack, is_online, machine_count: int = 0) -> None: + def addItem(self, container_stack: ContainerStack, is_online: bool, machine_count: int = 0) -> None: if parseBool(container_stack.getMetaDataEntry("hidden", False)): return From 148263a06828e6b5669854a6f0feacba7d4bc2ce Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Tue, 6 Sep 2022 13:52:10 +0200 Subject: [PATCH 8/8] Move `hasNetworkedConnection` to `GlobalStack` From code review CURA-9277 Co-authored-by: Joey --- cura/Machines/Models/MachineListModel.py | 10 +--------- cura/Settings/GlobalStack.py | 6 ++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index 8750da6305..919d593200 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -89,15 +89,7 @@ class MachineListModel(ListModel): machines_manager = CuraApplication.getInstance().getMachineManager() online_machine_stacks = machines_manager.getMachinesWithDefinition(definition_id, online_only = True) - def online_machines_has_connection_filter(machine_stack): - # This is required because machines loaded from projects have the is_online="True" but no connection type. - # We want to display them the same way as unconnected printers in this case. - has_connection = False - for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]: - has_connection |= connection_type in machine_stack.configuredConnectionTypes - return has_connection - - online_machine_stacks = list(filter(online_machines_has_connection_filter, online_machine_stacks)) + online_machine_stacks = list(filter(lambda machine: machine.hasNetworkedConnection(), online_machine_stacks)) other_machine_stacks.remove(abstract_machine) if abstract_machine in online_machine_stacks: diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index b94ca45763..041bd19d3a 100755 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -347,6 +347,12 @@ class GlobalStack(CuraContainerStack): nameChanged = pyqtSignal() name = pyqtProperty(str, fget=getName, fset=setName, notify=nameChanged) + def hasNetworkedConnection(self) -> bool: + has_connection = False + for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]: + has_connection |= connection_type in self.configuredConnectionTypes + return has_connection + ## private: global_stack_mime = MimeType( name = "application/x-cura-globalstack",