Add specific message when connecting to slave, prevent duplicate messages

This commit is contained in:
ChrisTerBeke 2019-08-07 01:02:46 +02:00
parent 8a2e394abc
commit 2ed033da7c
No known key found for this signature in database
GPG Key ID: A49F1AB9D7E0C263
3 changed files with 60 additions and 14 deletions

View File

@ -7,14 +7,27 @@ from UM.Message import Message
I18N_CATALOG = i18nCatalog("cura") I18N_CATALOG = i18nCatalog("cura")
## Message shown when uploading a print job to a cluster is blocked because another upload is already in progress. ## Message shown when trying to connect to a legacy printer device.
class LegacyDeviceNoLongerSupportedMessage(Message): class LegacyDeviceNoLongerSupportedMessage(Message):
# Singleton used to prevent duplicate messages of this type at the same time.
__is_visible = False
def __init__(self) -> None: def __init__(self) -> None:
super().__init__( super().__init__(
text = I18N_CATALOG.i18nc("@info:status", "You are attempting to connect to a printer that is not " text = I18N_CATALOG.i18nc("@info:status", "You are attempting to connect to a printer that is not "
"running Ultimaker Connect. Please update the printer to the " "running Ultimaker Connect. Please update the printer to the "
"latest firmware."), "latest firmware."),
title = I18N_CATALOG.i18nc("@info:title", "Update your printer"), title = I18N_CATALOG.i18nc("@info:title", "Update your printer"),
lifetime = 10 lifetime = 10
) )
def show(self) -> None:
if LegacyDeviceNoLongerSupportedMessage.__is_visible:
return
super().show()
LegacyDeviceNoLongerSupportedMessage.__is_visible = True
def hide(self, send_signal = True) -> None:
super().hide(send_signal)
LegacyDeviceNoLongerSupportedMessage.__is_visible = False

View File

@ -0,0 +1,33 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from UM import i18nCatalog
from UM.Message import Message
I18N_CATALOG = i18nCatalog("cura")
## Message shown when trying to connect to a printer that is not a host.
class NotClusterHostMessage(Message):
# Singleton used to prevent duplicate messages of this type at the same time.
__is_visible = False
def __init__(self) -> None:
super().__init__(
text = I18N_CATALOG.i18nc("@info:status", "You are attempting to connect to a printer that is not "
"the host of an Ultimaker Connect group. Please connect to "
"the host instead."),
title = I18N_CATALOG.i18nc("@info:title", "Not a cluster host"),
lifetime = 10
)
def show(self) -> None:
if NotClusterHostMessage.__is_visible:
return
super().show()
NotClusterHostMessage.__is_visible = True
def hide(self, send_signal = True) -> None:
super().hide(send_signal)
NotClusterHostMessage.__is_visible = False

View File

@ -16,6 +16,7 @@ from .LocalClusterOutputDevice import LocalClusterOutputDevice
from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice
from ..CloudFlowMessage import CloudFlowMessage from ..CloudFlowMessage import CloudFlowMessage
from ..Messages.LegacyDeviceNoLongerSupportedMessage import LegacyDeviceNoLongerSupportedMessage from ..Messages.LegacyDeviceNoLongerSupportedMessage import LegacyDeviceNoLongerSupportedMessage
from ..Messages.NotClusterHostMessage import NotClusterHostMessage
from ..Models.Http.PrinterSystemStatus import PrinterSystemStatus from ..Models.Http.PrinterSystemStatus import PrinterSystemStatus
@ -128,8 +129,6 @@ class LocalClusterOutputDeviceManager:
## Add a new device. ## Add a new device.
def _onDeviceDiscovered(self, key: str, address: str, properties: Dict[bytes, bytes]) -> None: def _onDeviceDiscovered(self, key: str, address: str, properties: Dict[bytes, bytes]) -> None:
cluster_size = int(properties.get(b"cluster_size", -1))
firmware_version = Version(properties.get(b"firmware", "1.0.0"))
machine_identifier = properties.get(b"machine", b"").decode("utf-8") machine_identifier = properties.get(b"machine", b"").decode("utf-8")
printer_type_identifiers = self._getPrinterTypeIdentifiers() printer_type_identifiers = self._getPrinterTypeIdentifiers()
@ -140,10 +139,6 @@ class LocalClusterOutputDeviceManager:
properties[b"printer_type"] = bytes(p_type, encoding="utf8") properties[b"printer_type"] = bytes(p_type, encoding="utf8")
break break
# We no longer support legacy devices, prevent them from showing up in the discovered devices list.
if cluster_size == -1 or firmware_version < self.MIN_SUPPORTED_CLUSTER_VERSION:
return
device = LocalClusterOutputDevice(key, address, properties) device = LocalClusterOutputDevice(key, address, properties)
CuraApplication.getInstance().getDiscoveredPrintersModel().addDiscoveredPrinter( CuraApplication.getInstance().getDiscoveredPrintersModel().addDiscoveredPrinter(
ip_address=address, ip_address=address,
@ -210,11 +205,16 @@ class LocalClusterOutputDeviceManager:
## Add a device to the current active machine. ## Add a device to the current active machine.
def _connectToOutputDevice(self, device: UltimakerNetworkedPrinterOutputDevice, machine: GlobalStack) -> None: def _connectToOutputDevice(self, device: UltimakerNetworkedPrinterOutputDevice, machine: GlobalStack) -> None:
# Make sure users know that we no longer support legacy devices. # Make sure users know that we no longer support legacy devices.
if device.clusterSize < 1 or Version(device.firmwareVersion) < self.MIN_SUPPORTED_CLUSTER_VERSION: if Version(device.firmwareVersion) < self.MIN_SUPPORTED_CLUSTER_VERSION:
LegacyDeviceNoLongerSupportedMessage().show() LegacyDeviceNoLongerSupportedMessage().show()
return return
# Tell the user that they cannot connect to a non-host printer.
if device.clusterSize < 1:
NotClusterHostMessage().show()
return
device.connect() device.connect()
machine.addConfiguredConnectionType(device.connectionType.value) machine.addConfiguredConnectionType(device.connectionType.value)