mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 13:17:51 -06:00
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.
This commit is contained in:
parent
f5604dfb1e
commit
b76df21b4b
3 changed files with 22 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -737,6 +737,7 @@ Window
|
|||
id: cloudPrinterList
|
||||
filterConnectionType: 3 //Only show cloud connections.
|
||||
filterOnlineOnly: true //Only show printers that are online.
|
||||
filterCapabilities: ["import_materials"] //Only show printers that can receive the material profiles.
|
||||
}
|
||||
Cura.GlobalStacksModel
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue