mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 10:17:52 -06:00
Digital Library plugin needs to be backwards compatible.
Message-types are a new parameter to Messages, so they can't be used in SDK/API versions smaller than 7.7.0. CURA-8473
This commit is contained in:
parent
8b2904ee3b
commit
5d7804deae
3 changed files with 41 additions and 24 deletions
15
plugins/DigitalLibrary/src/BackwardsCompatibleMessage.py
Normal file
15
plugins/DigitalLibrary/src/BackwardsCompatibleMessage.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2021 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from UM.Application import Application
|
||||
from UM.Message import Message
|
||||
from UM.Version import Version
|
||||
|
||||
def getBackwardsCompatibleMessage(text: str, title: str, lifetime: int, message_type_str: str) -> Message:
|
||||
if Application.getInstance().getAPIVersion() < Version("7.7.0"):
|
||||
return Message(text=text, title=title, lifetime=lifetime)
|
||||
else:
|
||||
message_type = Message.MessageType.NEUTRAL
|
||||
if message_type in Message.MessageType:
|
||||
message_type = Message.MessageType[message_type_str]
|
||||
return Message(text=text, title=title, lifetime=lifetime, message_type=message_type)
|
|
@ -14,6 +14,7 @@ from UM.Logger import Logger
|
|||
from UM.Message import Message
|
||||
from UM.Scene.SceneNode import SceneNode
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from .BackwardsCompatibleMessage import getBackwardsCompatibleMessage
|
||||
from .DFLibraryFileUploadRequest import DFLibraryFileUploadRequest
|
||||
from .DFLibraryFileUploadResponse import DFLibraryFileUploadResponse
|
||||
from .DFPrintJobUploadRequest import DFPrintJobUploadRequest
|
||||
|
@ -69,11 +70,11 @@ class DFFileExportAndUploadManager:
|
|||
use_inactivity_timer = False
|
||||
)
|
||||
|
||||
self._generic_success_message = Message(
|
||||
self._generic_success_message = getBackwardsCompatibleMessage(
|
||||
text = "Your {} uploaded to '{}'.".format("file was" if len(self._file_upload_job_metadata) <= 1 else "files were", self._library_project_name),
|
||||
title = "Upload successful",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.POSITIVE
|
||||
message_type_str = "POSITIVE"
|
||||
)
|
||||
self._generic_success_message.addAction(
|
||||
"open_df_project",
|
||||
|
@ -217,11 +218,11 @@ class DFFileExportAndUploadManager:
|
|||
# Set the progress to 100% when the upload job fails, to avoid having the progress message stuck
|
||||
self._file_upload_job_metadata[filename]["upload_status"] = "failed"
|
||||
self._file_upload_job_metadata[filename]["upload_progress"] = 100
|
||||
self._file_upload_job_metadata[filename]["file_upload_failed_message"] = Message(
|
||||
self._file_upload_job_metadata[filename]["file_upload_failed_message"] = getBackwardsCompatibleMessage(
|
||||
text = "Failed to export the file '{}'. The upload process is aborted.".format(filename),
|
||||
title = "Export error",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.ERROR
|
||||
message_type_str = "ERROR"
|
||||
)
|
||||
self._on_upload_error()
|
||||
self._onFileUploadFinished(filename)
|
||||
|
@ -240,11 +241,11 @@ class DFFileExportAndUploadManager:
|
|||
self._file_upload_job_metadata[filename_3mf]["upload_progress"] = 100
|
||||
|
||||
human_readable_error = self.extractErrorTitle(reply_string)
|
||||
self._file_upload_job_metadata[filename_3mf]["file_upload_failed_message"] = Message(
|
||||
self._file_upload_job_metadata[filename_3mf]["file_upload_failed_message"] = getBackwardsCompatibleMessage(
|
||||
text = "Failed to upload the file '{}' to '{}'. {}".format(filename_3mf, self._library_project_name, human_readable_error),
|
||||
title = "File upload error",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.ERROR
|
||||
message_type_str = "ERROR"
|
||||
)
|
||||
self._on_upload_error()
|
||||
self._onFileUploadFinished(filename_3mf)
|
||||
|
@ -263,11 +264,11 @@ class DFFileExportAndUploadManager:
|
|||
self._file_upload_job_metadata[filename_ufp]["upload_progress"] = 100
|
||||
|
||||
human_readable_error = self.extractErrorTitle(reply_string)
|
||||
self._file_upload_job_metadata[filename_ufp]["file_upload_failed_message"] = Message(
|
||||
self._file_upload_job_metadata[filename_ufp]["file_upload_failed_message"] = getBackwardsCompatibleMessage(
|
||||
title = "File upload error",
|
||||
text = "Failed to upload the file '{}' to '{}'. {}".format(filename_ufp, self._library_project_name, human_readable_error),
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.ERROR
|
||||
message_type_str = "ERROR"
|
||||
)
|
||||
self._on_upload_error()
|
||||
self._onFileUploadFinished(filename_ufp)
|
||||
|
@ -300,11 +301,11 @@ class DFFileExportAndUploadManager:
|
|||
self._file_upload_job_metadata[filename]["upload_status"] = "failed"
|
||||
self._file_upload_job_metadata[filename]["upload_progress"] = 100
|
||||
human_readable_error = self.extractErrorTitle(reply_string)
|
||||
self._file_upload_job_metadata[filename]["file_upload_failed_message"] = Message(
|
||||
self._file_upload_job_metadata[filename]["file_upload_failed_message"] = getBackwardsCompatibleMessage(
|
||||
title = "File upload error",
|
||||
text = "Failed to upload the file '{}' to '{}'. {}".format(self._file_name, self._library_project_name, human_readable_error),
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.ERROR
|
||||
message_type_str = "ERROR"
|
||||
)
|
||||
|
||||
self._on_upload_error()
|
||||
|
@ -337,17 +338,17 @@ class DFFileExportAndUploadManager:
|
|||
"upload_progress" : -1,
|
||||
"upload_status" : "",
|
||||
"file_upload_response": None,
|
||||
"file_upload_success_message": Message(
|
||||
"file_upload_success_message": getBackwardsCompatibleMessage(
|
||||
text = "'{}' was uploaded to '{}'.".format(filename_3mf, self._library_project_name),
|
||||
title = "Upload successful",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.POSITIVE
|
||||
message_type_str = "POSITIVE"
|
||||
),
|
||||
"file_upload_failed_message": Message(
|
||||
"file_upload_failed_message": getBackwardsCompatibleMessage(
|
||||
text = "Failed to upload the file '{}' to '{}'.".format(filename_3mf, self._library_project_name),
|
||||
title = "File upload error",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.ERROR
|
||||
message_type_str = "ERROR"
|
||||
)
|
||||
}
|
||||
job_3mf = ExportFileJob(self._file_handlers["3mf"], self._nodes, self._file_name, "3mf")
|
||||
|
@ -361,17 +362,17 @@ class DFFileExportAndUploadManager:
|
|||
"upload_progress" : -1,
|
||||
"upload_status" : "",
|
||||
"file_upload_response": None,
|
||||
"file_upload_success_message": Message(
|
||||
"file_upload_success_message": getBackwardsCompatibleMessage(
|
||||
text = "'{}' was uploaded to '{}'.".format(filename_ufp, self._library_project_name),
|
||||
title = "Upload successful",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.POSITIVE
|
||||
message_type_str = "POSITIVE"
|
||||
),
|
||||
"file_upload_failed_message": Message(
|
||||
"file_upload_failed_message": getBackwardsCompatibleMessage(
|
||||
text = "Failed to upload the file '{}' to '{}'.".format(filename_ufp, self._library_project_name),
|
||||
title = "File upload error",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.ERROR
|
||||
message_type_str = "ERROR"
|
||||
)
|
||||
}
|
||||
job_ufp = ExportFileJob(self._file_handlers["ufp"], self._nodes, self._file_name, "ufp")
|
||||
|
|
|
@ -23,6 +23,7 @@ from UM.TaskManagement.HttpRequestManager import HttpRequestManager
|
|||
from cura.API import Account
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope
|
||||
from .BackwardsCompatibleMessage import getBackwardsCompatibleMessage
|
||||
from .DFFileExportAndUploadManager import DFFileExportAndUploadManager
|
||||
from .DigitalFactoryApiClient import DigitalFactoryApiClient
|
||||
from .DigitalFactoryFileModel import DigitalFactoryFileModel
|
||||
|
@ -527,11 +528,11 @@ class DigitalFactoryController(QObject):
|
|||
except IOError as ex:
|
||||
Logger.logException("e", "Can't write Digital Library file {0}/{1} download to temp-directory {2}.",
|
||||
ex, project_name, file_name, temp_dir)
|
||||
Message(
|
||||
getBackwardsCompatibleMessage(
|
||||
text = "Failed to write to temporary file for '{}'.".format(file_name),
|
||||
title = "File-system error",
|
||||
lifetime = 10,
|
||||
message_type=Message.MessageType.ERROR
|
||||
message_type_str="ERROR"
|
||||
).show()
|
||||
return
|
||||
|
||||
|
@ -542,11 +543,11 @@ class DigitalFactoryController(QObject):
|
|||
f = file_name) -> None:
|
||||
progress_message.hide()
|
||||
Logger.error("An error {0} {1} occurred while downloading {2}/{3}".format(str(error), str(reply), p, f))
|
||||
Message(
|
||||
getBackwardsCompatibleMessage(
|
||||
text = "Failed Digital Library download for '{}'.".format(f),
|
||||
title = "Network error {}".format(error),
|
||||
lifetime = 10,
|
||||
message_type=Message.MessageType.ERROR
|
||||
message_type_str="ERROR"
|
||||
).show()
|
||||
|
||||
download_manager = HttpRequestManager.getInstance()
|
||||
|
@ -591,10 +592,10 @@ class DigitalFactoryController(QObject):
|
|||
|
||||
if filename == "":
|
||||
Logger.log("w", "The file name cannot be empty.")
|
||||
Message(text = "Cannot upload file with an empty name to the Digital Library",
|
||||
getBackwardsCompatibleMessage(text = "Cannot upload file with an empty name to the Digital Library",
|
||||
title = "Empty file name provided",
|
||||
lifetime = 0,
|
||||
message_type = Message.MessageType.ERROR).show()
|
||||
message_type_str = "ERROR").show()
|
||||
return
|
||||
|
||||
self._saveFileToSelectedProjectHelper(filename, formats)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue