WIP: Disable unknown printer type buttons

This commit is contained in:
Lipu Fei 2019-03-14 11:16:31 +01:00
parent 2b0e9ea439
commit b3621bae84
4 changed files with 30 additions and 4 deletions

View file

@ -62,6 +62,10 @@ class DiscoveredPrinter(QObject):
readable_type = catalog.i18nc("@label", "Unknown") readable_type = catalog.i18nc("@label", "Unknown")
return readable_type return readable_type
@pyqtProperty(bool, notify = machineTypeChanged)
def is_unknown_machine_type(self) -> bool:
return self.readable_machine_type.lower() == "unknown"
@pyqtProperty(QObject, constant = True) @pyqtProperty(QObject, constant = True)
def device(self): def device(self):
return self._device return self._device

View file

@ -118,7 +118,7 @@ class DiscoverUM3Action(MachineAction):
if self._network_plugin: if self._network_plugin:
# Ensure that the connection states are refreshed. # Ensure that the connection states are refreshed.
self._network_plugin.reCheckConnections() self._network_plugin.refreshConnections()
# Associates the currently active machine with the given printer device. The network connection information will be # Associates the currently active machine with the given printer device. The network connection information will be
# stored into the metadata of the currently active machine. # stored into the metadata of the currently active machine.
@ -160,7 +160,7 @@ class DiscoverUM3Action(MachineAction):
if self._network_plugin: if self._network_plugin:
# Ensure that the connection states are refreshed. # Ensure that the connection states are refreshed.
self._network_plugin.reCheckConnections() self._network_plugin.refreshConnections()
@pyqtSlot(result = str) @pyqtSlot(result = str)
def getStoredKey(self) -> str: def getStoredKey(self) -> str:

View file

@ -84,7 +84,14 @@ Button
background: Rectangle background: Rectangle
{ {
id: backgroundRect id: backgroundRect
color: machineSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent" color:
{
if (!machineSelectorButton.enabled)
{
return UM.Theme.getColor("action_button_disabled")
}
return machineSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
}
radius: UM.Theme.getSize("action_button_radius").width radius: UM.Theme.getSize("action_button_radius").width
border.width: UM.Theme.getSize("default_lining").width border.width: UM.Theme.getSize("default_lining").width
border.color: machineSelectorButton.selected ? UM.Theme.getColor("primary") : "transparent" border.color: machineSelectorButton.selected ? UM.Theme.getColor("primary") : "transparent"

View file

@ -70,7 +70,20 @@ Item
id: networkPrinterListView id: networkPrinterListView
anchors.fill: parent anchors.fill: parent
model: CuraApplication.getDiscoveredPrintersModel().discovered_printers model: CuraApplication.getDiscoveredPrintersModel().discovered_printers
//visible: base.visible && model.length > 0
Component.onCompleted:
{
// select the first one that's not "unknown" by default.
for (var i = 0; i < count; i++)
{
if (!model[i].is_unknown_machine_type)
{
currentIndex = i
break
}
}
}
delegate: MachineSelectorButton delegate: MachineSelectorButton
{ {
@ -81,6 +94,8 @@ Item
anchors.rightMargin: 10 anchors.rightMargin: 10
outputDevice: modelData.device outputDevice: modelData.device
enabled: !modelData.is_unknown_machine_type
printerTypeLabelAutoFit: true printerTypeLabelAutoFit: true
updatePrinterTypesFunction: updateMachineTypes updatePrinterTypesFunction: updateMachineTypes