Add button to hide/show connected printers

CURA-9514
This commit is contained in:
c.lamboo 2022-08-30 23:15:54 +02:00
parent 401170d8dd
commit ac732e9604
2 changed files with 51 additions and 8 deletions

View file

@ -5,7 +5,7 @@
# online cloud connected printers are represented within this ListModel. Additional information such as the number of
# connected printers for each printer type is gathered.
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtCore import Qt, QTimer, pyqtSlot, pyqtProperty, pyqtSignal
from UM.Qt.ListModel import ListModel
from UM.Settings.ContainerStack import ContainerStack
@ -29,6 +29,8 @@ class MachineListModel(ListModel):
def __init__(self, parent=None) -> None:
super().__init__(parent)
self._show_cloud_printers = True
self._catalog = i18nCatalog("cura")
self.addRoleName(self.NameRole, "name")
@ -50,6 +52,18 @@ class MachineListModel(ListModel):
CuraContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged)
self._updateDelayed()
showCloutPrintersChanged = pyqtSignal(bool)
@pyqtProperty(bool, notify=showCloutPrintersChanged)
def showCloudPrinters(self) -> bool:
return self._show_cloud_printers
@pyqtSlot(bool, name="setShowCloudPrinters")
def set_show_cloud_printers(self, show_cloud_printers: bool) -> None:
self._show_cloud_printers = show_cloud_printers
self._updateDelayed()
self.showCloutPrintersChanged.emit(show_cloud_printers)
def _onContainerChanged(self, container) -> None:
"""Handler for container added/removed events from registry"""
@ -80,6 +94,7 @@ class MachineListModel(ListModel):
# Create list of machines that are children of the abstract machine
for stack in online_machine_stacks:
if self._show_cloud_printers:
self.addItem(stack)
# Remove this machine from the other stack list
other_machine_stacks.remove(stack)

View file

@ -19,16 +19,44 @@ ListView
id: scrollBar
}
section.delegate: UM.Label
section.delegate: Item
{
text: section == "true" ? catalog.i18nc("@label", "Connected printers") : catalog.i18nc("@label", "Other printers")
width: parent.width - scrollBar.width
height: childrenRect.height
UM.Label
{
visible: section == "true"
text: catalog.i18nc("@label", "Connected printers")
height: UM.Theme.getSize("action_button").height
leftPadding: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("medium")
color: UM.Theme.getColor("text_medium")
}
Column
{
visible: section != "true"
height: childrenRect.height
Cura.TertiaryButton
{
text: listView.model.showCloudPrinters ? catalog.i18nc("@label", "Hide all connected printers") : catalog.i18nc("@label", "Show all connected printers")
onClicked: listView.model.setShowCloudPrinters(!listView.model.showCloudPrinters)
iconSource: listView.model.showCloudPrinters ? UM.Theme.getIcon("ChevronSingleUp") : UM.Theme.getIcon("ChevronSingleDown")
}
UM.Label
{
text: catalog.i18nc("@label", "Other printers")
height: UM.Theme.getSize("action_button").height
leftPadding: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("medium")
color: UM.Theme.getColor("text_medium")
}
}
}
delegate: MachineListButton
{
text: model.name ? model.name : ""