Merge pull request #13168 from Ultimaker/CURA-9514

Add button to hide/show connected printers
This commit is contained in:
Casper Lamboo 2022-08-31 11:17:37 +02:00 committed by GitHub
commit 0ccca3fde5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 174 additions and 79 deletions

View File

@ -5,7 +5,7 @@
# online cloud connected printers are represented within this ListModel. Additional information such as the number of # online cloud connected printers are represented within this ListModel. Additional information such as the number of
# connected printers for each printer type is gathered. # 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.Qt.ListModel import ListModel
from UM.Settings.ContainerStack import ContainerStack from UM.Settings.ContainerStack import ContainerStack
@ -24,11 +24,14 @@ class MachineListModel(ListModel):
MetaDataRole = Qt.ItemDataRole.UserRole + 4 MetaDataRole = Qt.ItemDataRole.UserRole + 4
IsOnlineRole = Qt.ItemDataRole.UserRole + 5 IsOnlineRole = Qt.ItemDataRole.UserRole + 5
MachineCountRole = Qt.ItemDataRole.UserRole + 6 MachineCountRole = Qt.ItemDataRole.UserRole + 6
IsAbstractMachine = Qt.ItemDataRole.UserRole + 7 IsAbstractMachineRole = Qt.ItemDataRole.UserRole + 7
ComponentTypeRole = Qt.ItemDataRole.UserRole + 8
def __init__(self, parent=None) -> None: def __init__(self, parent=None) -> None:
super().__init__(parent) super().__init__(parent)
self._show_cloud_printers = True
self._catalog = i18nCatalog("cura") self._catalog = i18nCatalog("cura")
self.addRoleName(self.NameRole, "name") self.addRoleName(self.NameRole, "name")
@ -37,7 +40,8 @@ class MachineListModel(ListModel):
self.addRoleName(self.MetaDataRole, "metadata") self.addRoleName(self.MetaDataRole, "metadata")
self.addRoleName(self.IsOnlineRole, "isOnline") self.addRoleName(self.IsOnlineRole, "isOnline")
self.addRoleName(self.MachineCountRole, "machineCount") self.addRoleName(self.MachineCountRole, "machineCount")
self.addRoleName(self.IsAbstractMachine, "isAbstractMachine") self.addRoleName(self.IsAbstractMachineRole, "isAbstractMachine")
self.addRoleName(self.ComponentTypeRole, "componentType")
self._change_timer = QTimer() self._change_timer = QTimer()
self._change_timer.setInterval(200) self._change_timer.setInterval(200)
@ -50,6 +54,18 @@ class MachineListModel(ListModel):
CuraContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged) CuraContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged)
self._updateDelayed() self._updateDelayed()
showCloudPrintersChanged = pyqtSignal(bool)
@pyqtProperty(bool, notify=showCloudPrintersChanged)
def showCloudPrinters(self) -> bool:
return self._show_cloud_printers
@pyqtSlot(bool)
def setShowCloudPrinters(self, show_cloud_printers: bool) -> None:
self._show_cloud_printers = show_cloud_printers
self._updateDelayed()
self.showCloudPrintersChanged.emit(show_cloud_printers)
def _onContainerChanged(self, container) -> None: def _onContainerChanged(self, container) -> None:
"""Handler for container added/removed events from registry""" """Handler for container added/removed events from registry"""
@ -61,7 +77,7 @@ class MachineListModel(ListModel):
self._change_timer.start() self._change_timer.start()
def _update(self) -> None: def _update(self) -> None:
self.setItems([]) # Clear items self.clear()
other_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type="machine") other_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type="machine")
@ -80,10 +96,25 @@ class MachineListModel(ListModel):
# Create list of machines that are children of the abstract machine # Create list of machines that are children of the abstract machine
for stack in online_machine_stacks: for stack in online_machine_stacks:
if self._show_cloud_printers:
self.addItem(stack) self.addItem(stack)
# Remove this machine from the other stack list # Remove this machine from the other stack list
other_machine_stacks.remove(stack) other_machine_stacks.remove(stack)
if len(abstract_machine_stacks) > 0:
if self._show_cloud_printers:
self.appendItem({"componentType": "HIDE_BUTTON",
"isOnline": True,
"isAbstractMachine": False,
"machineCount": 0
})
else:
self.appendItem({"componentType": "SHOW_BUTTON",
"isOnline": True,
"isAbstractMachine": False,
"machineCount": 0
})
for stack in other_machine_stacks: for stack in other_machine_stacks:
self.addItem(stack) self.addItem(stack)
@ -98,7 +129,9 @@ class MachineListModel(ListModel):
for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]: for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]:
has_connection |= connection_type in container_stack.configuredConnectionTypes has_connection |= connection_type in container_stack.configuredConnectionTypes
self.appendItem({"name": container_stack.getName(), self.appendItem({
"componentType": "MACHINE",
"name": container_stack.getName(),
"id": container_stack.getId(), "id": container_stack.getId(),
"metadata": container_stack.getMetaData().copy(), "metadata": container_stack.getMetaData().copy(),
"isOnline": parseBool(container_stack.getMetaDataEntry("is_online", False)) and has_connection, "isOnline": parseBool(container_stack.getMetaDataEntry("is_online", False)) and has_connection,

View File

@ -7,11 +7,61 @@ import QtQuick.Controls 2.3
import UM 1.5 as UM import UM 1.5 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
Loader {
id: loader
width: parent.width
sourceComponent: {
switch (model.componentType) {
case "HIDE_BUTTON":
hideButtonComponent
break;
case "SHOW_BUTTON":
showButtonComponent
break;
case "MACHINE":
machineListButtonComponent
break;
default:
}
}
property var onClicked
Button Component
{ {
id: hideButtonComponent
Cura.TertiaryButton
{
text: catalog.i18nc("@label", "Hide all connected printers")
height: UM.Theme.getSize("large_button").height
onClicked: if (loader.onClicked) loader.onClicked()
iconSource: UM.Theme.getIcon("ChevronSingleUp")
width: parent.width
}
}
Component
{
id: showButtonComponent
Cura.TertiaryButton
{
text: catalog.i18nc("@label", "Show all connected printers")
height: UM.Theme.getSize("large_button").height
onClicked: if (loader.onClicked) loader.onClicked()
iconSource: UM.Theme.getIcon("ChevronSingleDown")
width: parent.width
}
}
Component
{
id: machineListButtonComponent
Button
{
id: machineListButton id: machineListButton
onClicked: if (loader.onClicked) loader.onClicked()
width: parent.width width: parent.width
height: UM.Theme.getSize("large_button").height height: UM.Theme.getSize("large_button").height
leftPadding: UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("default_margin").width
@ -50,7 +100,7 @@ Button
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
leftMargin: UM.Theme.getSize("default_margin").width leftMargin: UM.Theme.getSize("default_margin").width
} }
text: machineListButton.text text: model.name ? model.name : ""
font: model.isAbstractMachine ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium") font: model.isAbstractMachine ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")
visible: text != "" visible: text != ""
elide: Text.ElideRight elide: Text.ElideRight
@ -84,4 +134,6 @@ Button
id: backgroundRect id: backgroundRect
color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent" color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
} }
}
}
} }

View File

@ -22,8 +22,8 @@ ListView
section.delegate: UM.Label section.delegate: UM.Label
{ {
text: section == "true" ? catalog.i18nc("@label", "Connected printers") : catalog.i18nc("@label", "Other printers") text: section == "true" ? catalog.i18nc("@label", "Connected printers") : catalog.i18nc("@label", "Other printers")
width: parent.width - scrollBar.width
height: UM.Theme.getSize("action_button").height height: UM.Theme.getSize("action_button").height
width: parent.width - scrollBar.width
leftPadding: UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
color: UM.Theme.getColor("text_medium") color: UM.Theme.getColor("text_medium")
@ -31,13 +31,23 @@ ListView
delegate: MachineListButton delegate: MachineListButton
{ {
text: model.name ? model.name : ""
width: listView.width - scrollBar.width width: listView.width - scrollBar.width
onClicked: onClicked: function()
{ {
switch (model.componentType) {
case "HIDE_BUTTON":
listView.model.setShowCloudPrinters(false);
break;
case "SHOW_BUTTON":
listView.model.setShowCloudPrinters(true);
break;
case "MACHINE":
toggleContent() toggleContent()
Cura.MachineManager.setActiveMachine(model.id) Cura.MachineManager.setActiveMachine(model.id)
break;
default:
}
} }
} }
} }