diff options
author | c.lamboo <casperlamboo@gmail.com> | 2022-08-26 12:16:10 +0300 |
---|---|---|
committer | c.lamboo <casperlamboo@gmail.com> | 2022-08-26 12:16:10 +0300 |
commit | f000b75661765b3087a7e1fb53c4bd37c3d081e8 (patch) | |
tree | 1dd2152a06c8b9494d9dac5111467cac56c53655 | |
parent | 8b84db705943217072003bec7d97439506a91eb0 (diff) |
Move `getMachinesWithDefinition` to `MachinesManager`
CURA-9514, CURA-9277
-rw-r--r-- | cura/Machines/Models/MachineListModel.py | 6 | ||||
-rwxr-xr-x | cura/Settings/GlobalStack.py | 25 | ||||
-rwxr-xr-x | cura/Settings/MachineManager.py | 27 |
3 files changed, 31 insertions, 27 deletions
diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index 4b80410018..c1796c5f3f 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -9,7 +9,7 @@ from UM.i18n import i18nCatalog from UM.Util import parseBool from cura.Settings.CuraContainerRegistry import CuraContainerRegistry -from cura.Settings.GlobalStack import GlobalStack, getMachinesWithDefinition +from cura.Settings.GlobalStack import GlobalStack class MachineListModel(ListModel): @@ -65,7 +65,9 @@ class MachineListModel(ListModel): for abstract_machine in abstract_machine_stacks: definition_id = abstract_machine.definition.getId() - online_machine_stacks = getMachinesWithDefinition(definition_id, online_only = True) + from cura.CuraApplication import CuraApplication + 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)) diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index 6a14f10fe4..3c13f236ab 100755 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -349,31 +349,6 @@ class GlobalStack(CuraContainerStack): nameChanged = pyqtSignal() name = pyqtProperty(str, fget=getName, fset=setName, notify=nameChanged) - -def getMachinesWithDefinition(definition_id: str, online_only = False) -> List[ContainerStack]: - """ Fetches all container stacks that match definition_id. - - :param definition_id: The id of the machine definition. - :return: A list of Containers that match definition_id - """ - from cura.CuraApplication import CuraApplication # In function to avoid circular import - application = CuraApplication.getInstance() - registry = application.getContainerRegistry() - - machines = registry.findContainerStacks(type="machine") - # Filter machines that match definition - machines = filter(lambda machine: machine.definition.id == definition_id, machines) - # Filter only LAN and Cloud printers - machines = filter(lambda machine: ConnectionType.CloudConnection in machine.configuredConnectionTypes or - ConnectionType.NetworkConnection in machine.configuredConnectionTypes, machines) - if online_only: - # LAN printers can have is_online = False but should still be included, their online status is only checked when - # they are the active printer. - machines = filter(lambda machine: parseBool(machine.getMetaDataEntry("is_online", False) or - ConnectionType.NetworkConnection in machine.configuredConnectionTypes), machines) - - return list(machines) - ## private: global_stack_mime = MimeType( name = "application/x-cura-globalstack", diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 64d34d6c3e..389c5ded75 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -19,6 +19,7 @@ from UM.Logger import Logger from UM.Message import Message from UM.Settings.SettingFunction import SettingFunction +from UM.Settings.ContainerStack import ContainerStack from UM.Signal import postponeSignals, CompressTechnique import cura.CuraApplication # Imported like this to prevent circular references. @@ -186,6 +187,32 @@ class MachineManager(QObject): self.outputDevicesChanged.emit() + def getMachinesWithDefinition(self, definition_id: str, online_only=False) -> List[ContainerStack]: + """ Fetches all container stacks that match definition_id. + + :param definition_id: The id of the machine definition. + :return: A list of Containers that match definition_id + """ + from cura.CuraApplication import CuraApplication # In function to avoid circular import + application = CuraApplication.getInstance() + registry = application.getContainerRegistry() + + machines = registry.findContainerStacks(type="machine") + # Filter machines that match definition + machines = filter(lambda machine: machine.definition.id == definition_id, machines) + # Filter only LAN and Cloud printers + machines = filter(lambda machine: ConnectionType.CloudConnection in machine.configuredConnectionTypes or + ConnectionType.NetworkConnection in machine.configuredConnectionTypes, + machines) + if online_only: + # LAN printers can have is_online = False but should still be included, + # their online status is only checked when they are the active printer. + machines = filter(lambda machine: parseBool(machine.getMetaDataEntry("is_online", False) or + ConnectionType.NetworkConnection in machine.configuredConnectionTypes), + machines) + + return list(machines) + @pyqtProperty(QObject, notify = currentConfigurationChanged) def currentConfiguration(self) -> PrinterConfigurationModel: return self._current_printer_configuration |