diff options
author | joeydelarago <joeydelarago@gmail.com> | 2022-08-23 11:35:00 +0300 |
---|---|---|
committer | joeydelarago <joeydelarago@gmail.com> | 2022-08-23 11:35:00 +0300 |
commit | 7ffa770fb47c2a4acbb0700378ef0b96ea519523 (patch) | |
tree | 63f4f5d1f19942576799682f9881a430b1dc9e81 | |
parent | d1ae3136aa8c617967756a50c673030093782945 (diff) |
Searching container registry returns ContainerStacks.
Made typing more generic to work with an ContainerStack to compensate.
Made AbstractMachine getMachines a classmethod so it can be called with ContainerStacks.
CURA-9514
-rwxr-xr-x | cura/CuraApplication.py | 2 | ||||
-rw-r--r-- | cura/Machines/Models/AbstractStacksModel.py | 9 | ||||
-rw-r--r-- | cura/Settings/AbstractMachine.py | 15 | ||||
-rw-r--r-- | resources/qml/PrinterSelector/MachineSelectorList.qml | 2 |
4 files changed, 22 insertions, 6 deletions
diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f701c94797..2afbfbd3e8 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -115,6 +115,7 @@ from . import CuraActions from . import PlatformPhysics from . import PrintJobPreviewImageProvider from .AutoSave import AutoSave +from .Machines.Models.AbstractStacksModel import AbstractStacksModel from .Machines.Models.ActiveIntentQualitiesModel import ActiveIntentQualitiesModel from .Machines.Models.IntentSelectionModel import IntentSelectionModel from .SingleInstance import SingleInstance @@ -1194,6 +1195,7 @@ class CuraApplication(QtApplication): qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer") qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel") qmlRegisterType(GlobalStacksModel, "Cura", 1, 0, "GlobalStacksModel") + qmlRegisterType(AbstractStacksModel, "Cura", 1, 0, "AbstractStacksModel") self.processEvents() qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel") diff --git a/cura/Machines/Models/AbstractStacksModel.py b/cura/Machines/Models/AbstractStacksModel.py index 96360a978c..e9b991962b 100644 --- a/cura/Machines/Models/AbstractStacksModel.py +++ b/cura/Machines/Models/AbstractStacksModel.py @@ -5,10 +5,12 @@ from PyQt6.QtCore import Qt, QTimer from typing import Optional, Dict from UM.Qt.ListModel import ListModel +from UM.Settings.ContainerStack import ContainerStack from UM.i18n import i18nCatalog from UM.Util import parseBool from cura.PrinterOutput.PrinterOutputDevice import ConnectionType +from cura.Settings.AbstractMachine import AbstractMachine from cura.Settings.CuraContainerRegistry import CuraContainerRegistry from cura.Settings.GlobalStack import GlobalStack @@ -62,8 +64,11 @@ class AbstractStacksModel(ListModel): abstract_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type="abstract_machine") + abstract_machine_stacks.sort(key=lambda machine: machine.getName(), reverse=True) + for abstract_machine in abstract_machine_stacks: - machine_stacks = container_stacks # FIXME: This should point to abstract_machine.getPrinters() + machine_stacks = AbstractMachine.getMachines(abstract_machine) + # Create item for abstract printer items.append(self.createItem(abstract_machine)) @@ -76,7 +81,7 @@ class AbstractStacksModel(ListModel): self.setItems(items) - def createItem(self, container_stack: GlobalStack) -> Optional[Dict]: + def createItem(self, container_stack: ContainerStack) -> Optional[Dict]: if parseBool(container_stack.getMetaDataEntry("hidden", False)): return diff --git a/cura/Settings/AbstractMachine.py b/cura/Settings/AbstractMachine.py index a89201a294..a904058290 100644 --- a/cura/Settings/AbstractMachine.py +++ b/cura/Settings/AbstractMachine.py @@ -14,13 +14,22 @@ class AbstractMachine(GlobalStack): super().__init__(container_id) self.setMetaDataEntry("type", "abstract_machine") - def getMachines(self) -> List[ContainerStack]: - from cura.CuraApplication import CuraApplication + @classmethod + def getMachines(cls, abstract_machine: ContainerStack) -> List[ContainerStack]: + """ Fetches containers for all machines that match definition with an abstract machine. + :param abstractMachine: The abstract machine stack. + :return: A list of Containers or an empty list if stack is not an "abstract_machine" + """ + if not abstract_machine.getMetaDataEntry("type") == "abstract_machine": + return [] + + from cura.CuraApplication import CuraApplication # In function to avoid circular import application = CuraApplication.getInstance() registry = application.getContainerRegistry() - printer_type = self.definition.getId() + printer_type = abstract_machine.definition.getId() + return [machine for machine in registry.findContainerStacks(type="machine") if machine.definition.id == printer_type and ConnectionType.CloudConnection in machine.configuredConnectionTypes] diff --git a/resources/qml/PrinterSelector/MachineSelectorList.qml b/resources/qml/PrinterSelector/MachineSelectorList.qml index ae2706f9ab..822bdad3c5 100644 --- a/resources/qml/PrinterSelector/MachineSelectorList.qml +++ b/resources/qml/PrinterSelector/MachineSelectorList.qml @@ -10,7 +10,7 @@ import Cura 1.0 as Cura ListView { id: listView - model: Cura.GlobalStacksModel {} + model: Cura.AbstractStacksModel {} section.property: "hasRemoteConnection" property real contentHeight: childrenRect.height |