diff options
author | Ghostkeeper <rubend@tutanota.com> | 2021-12-02 19:55:53 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2021-12-02 19:55:53 +0300 |
commit | b76df21b4b0f8ed734369317e31cd70a4bc73785 (patch) | |
tree | 5730337eed84f46a2c4cca59bd11e81b2a9285e3 /cura/Machines/Models | |
parent | f5604dfb1e2b95742214797e7f2828b67911e8f2 (diff) |
Filter printer list by capabilities
And an example of such usage: In the material sync via cloud we only want to sync with printers that can receive those materials.
We might want to add a message for the user to also make sure the firmware is up to date. Because if the firmware is not up to date now it will show no printers and instruct the user how to connect the printer to the cloud.
Contributes to issue CURA-8671.
Diffstat (limited to 'cura/Machines/Models')
-rw-r--r-- | cura/Machines/Models/GlobalStacksModel.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/cura/Machines/Models/GlobalStacksModel.py b/cura/Machines/Models/GlobalStacksModel.py index 586bd11819..cc750f2244 100644 --- a/cura/Machines/Models/GlobalStacksModel.py +++ b/cura/Machines/Models/GlobalStacksModel.py @@ -2,7 +2,7 @@ # Cura is released under the terms of the LGPLv3 or higher. from PyQt5.QtCore import Qt, QTimer, pyqtProperty, pyqtSignal -from typing import Optional +from typing import List, Optional from UM.Qt.ListModel import ListModel from UM.i18n import i18nCatalog @@ -11,6 +11,7 @@ from UM.Util import parseBool from cura.PrinterOutput.PrinterOutputDevice import ConnectionType from cura.Settings.CuraContainerRegistry import CuraContainerRegistry from cura.Settings.GlobalStack import GlobalStack +from cura.UltimakerCloud.UltimakerCloudConstants import META_CAPABILITIES # To filter on the printer's capabilities. class GlobalStacksModel(ListModel): @@ -42,6 +43,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. # Listen to changes CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerChanged) @@ -76,6 +78,19 @@ class GlobalStacksModel(ListModel): """ return self._filter_online_only + filterCapabilitiesChanged = pyqtSignal() + def setFilterCapabilities(self, new_filter: List[str]) -> None: + self._filter_capabilities = new_filter + + @pyqtProperty("QStringList", fset = setFilterCapabilities, notify = filterCapabilitiesChanged) + def filterCapabilities(self) -> List[str]: + """ + Capabilities to require on the list of printers. + + Only printers that have all of these capabilities will be shown in this model. + """ + return self._filter_capabilities + def _onContainerChanged(self, container) -> None: """Handler for container added/removed events from registry""" @@ -108,6 +123,10 @@ class GlobalStacksModel(ListModel): if self._filter_online_only and not is_online: continue + capabilities = set(container_stack.getMetaDataEntry(META_CAPABILITIES, set())) + if set(self._filter_capabilities) - capabilities: # Not all required capabilities are met. + continue + device_name = container_stack.getMetaDataEntry("group_name", container_stack.getName()) section_name = "Connected printers" if has_remote_connection else "Preset printers" section_name = self._catalog.i18nc("@info:title", section_name) |