mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-01 16:24:41 +08:00
Move new printers detected message to it's own class
CURA-8463
This commit is contained in:
parent
8e9056df71
commit
a429a93e94
@ -23,6 +23,7 @@ from cura.UltimakerCloud.UltimakerCloudConstants import META_CAPABILITIES, META_
|
|||||||
from .CloudApiClient import CloudApiClient
|
from .CloudApiClient import CloudApiClient
|
||||||
from .CloudOutputDevice import CloudOutputDevice
|
from .CloudOutputDevice import CloudOutputDevice
|
||||||
from ..Models.Http.CloudClusterResponse import CloudClusterResponse
|
from ..Models.Http.CloudClusterResponse import CloudClusterResponse
|
||||||
|
from ..Messages.NewPrinterDetectedMessage import NewPrinterDetectedMessage
|
||||||
|
|
||||||
|
|
||||||
class CloudOutputDeviceManager:
|
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}
|
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()))
|
new_output_devices.sort(key = lambda x: ("a{}" if x.name.lower() in online_cluster_names else "b{}").format(x.name.lower()))
|
||||||
|
|
||||||
message = Message(
|
message = NewPrinterDetectedMessage(num_printers_found = len(new_output_devices))
|
||||||
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.show()
|
message.show()
|
||||||
|
|
||||||
new_devices_added = []
|
new_devices_added = []
|
||||||
|
|
||||||
for idx, output_device in enumerate(new_output_devices):
|
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.updateDisplayText(output_device)
|
||||||
message.setText(message_text)
|
|
||||||
if len(new_output_devices) > 1:
|
|
||||||
message.setProgress((idx / len(new_output_devices)) * 100)
|
|
||||||
CuraApplication.getInstance().processEvents()
|
|
||||||
self._remote_clusters[output_device.getId()] = output_device
|
self._remote_clusters[output_device.getId()] = output_device
|
||||||
|
|
||||||
# If there is no active machine, activate the first available cloud printer
|
# If there is no active machine, activate the first available cloud printer
|
||||||
|
@ -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()
|
Loading…
x
Reference in New Issue
Block a user