Implement filter for printer list to only show printers with certain configured connections

Because here we only want to show cloud-connected printers.

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-05 17:44:15 +02:00
parent c8931d4c23
commit d16217c674
No known key found for this signature in database
GPG key ID: 68F39EA88EEED5FF
2 changed files with 27 additions and 3 deletions

View file

@ -1,7 +1,7 @@
# Copyright (c) 2018 Ultimaker B.V.
# Copyright (c) 2021 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtCore import Qt, QTimer, pyqtProperty, pyqtSignal
from UM.Qt.ListModel import ListModel
from UM.i18n import i18nCatalog
@ -37,12 +37,29 @@ class GlobalStacksModel(ListModel):
self._change_timer.setSingleShot(True)
self._change_timer.timeout.connect(self._update)
self._filter_connection_type = -1
# Listen to changes
CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerChanged)
CuraContainerRegistry.getInstance().containerMetaDataChanged.connect(self._onContainerChanged)
CuraContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged)
self._updateDelayed()
filterConnectionTypeChanged = pyqtSignal()
def setFilterConnectionType(self, new_filter: int) -> None:
self._filter_connection_type = new_filter
@pyqtProperty(int, fset = setFilterConnectionType, notify = filterConnectionTypeChanged)
def filterConnectionType(self) -> int:
"""
The connection type to filter the list of printers by.
Only printers that match this connection type will be listed in the
model.
"""
return self._filter_connection_type
def _onContainerChanged(self, container) -> None:
"""Handler for container added/removed events from registry"""
@ -58,6 +75,10 @@ class GlobalStacksModel(ListModel):
container_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type = "machine")
for container_stack in container_stacks:
if self._filter_connection_type != -1: # We want to filter on connection types.
if not any((connection_type == self._filter_connection_type for connection_type in container_stack.configuredConnectionTypes)):
continue # No connection type on this printer matches the filter.
has_remote_connection = False
for connection_type in container_stack.configuredConnectionTypes:

View file

@ -203,7 +203,10 @@ Window
width: parent.width
spacing: UM.Theme.getSize("default_margin").height
model: Cura.GlobalStacksModel {}
model: Cura.GlobalStacksModel
{
filterConnectionType: 3 //Only show cloud connections.
}
delegate: Rectangle
{
border.color: UM.Theme.getColor("lining")