Move new printers detected message to it's own class

CURA-8463
This commit is contained in:
Jaime van Kessel 2022-08-30 11:26:09 +02:00
parent 8e9056df71
commit a429a93e94
No known key found for this signature in database
GPG Key ID: C85F7A3AF1BAA7C4
2 changed files with 35 additions and 16 deletions

View File

@ -23,6 +23,7 @@ from cura.UltimakerCloud.UltimakerCloudConstants import META_CAPABILITIES, META_
from .CloudApiClient import CloudApiClient
from .CloudOutputDevice import CloudOutputDevice
from ..Models.Http.CloudClusterResponse import CloudClusterResponse
from ..Messages.NewPrinterDetectedMessage import NewPrinterDetectedMessage
class CloudOutputDeviceManager:
@ -230,27 +231,14 @@ class CloudOutputDeviceManager:
online_cluster_names = {c.friendly_name.lower() for c in discovered_clusters if c.is_online and not c.friendly_name is None}
new_output_devices.sort(key = lambda x: ("a{}" if x.name.lower() in online_cluster_names else "b{}").format(x.name.lower()))
message = Message(
title = self.i18n_catalog.i18ncp(
"info:status",
"New printer detected from your Ultimaker account",
"New printers detected from your Ultimaker account",
len(new_output_devices)
),
progress = 0,
lifetime = 0,
message_type = Message.MessageType.POSITIVE
)
message = NewPrinterDetectedMessage(num_printers_found = len(new_output_devices))
message.show()
new_devices_added = []
for idx, output_device in enumerate(new_output_devices):
message_text = self.i18n_catalog.i18nc("info:status Filled in with printer name and printer model.", "Adding printer {name} ({model}) from your account").format(name = output_device.name, model = output_device.printerTypeName)
message.setText(message_text)
if len(new_output_devices) > 1:
message.setProgress((idx / len(new_output_devices)) * 100)
CuraApplication.getInstance().processEvents()
message.updateDisplayText(output_device)
self._remote_clusters[output_device.getId()] = output_device
# If there is no active machine, activate the first available cloud printer

View File

@ -0,0 +1,31 @@
# Copyright (c) 2022 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from UM import i18nCatalog
from UM.Message import Message
from cura.CuraApplication import CuraApplication
class NewPrinterDetectedMessage(Message):
i18n_catalog = i18nCatalog("cura")
def __init__(self, num_printers_found: int) -> None:
super().__init__(title = self.i18n_catalog.i18ncp("info:status",
"New printer detected from your Ultimaker account",
"New printers detected from your Ultimaker account",
num_printers_found),
progress = 0,
lifetime = 0,
message_type = Message.MessageType.POSITIVE)
self._printers_added = 0
self._num_printers_found = num_printers_found
def updateDisplayText(self, output_device):
message_text = self.i18n_catalog.i18nc("info:status Filled in with printer name and printer model.",
"Adding printer {name} ({model}) from your account").format(
name=output_device.name, model=output_device.printerTypeName)
self.setText(message_text)
if self._num_printers_found > 1:
self.setProgress((self._printers_added / self._num_printers_found) * 100)
self._printers_added += 1
CuraApplication.getInstance().processEvents()