Show message for unknown machines in project files

CURA-5337

Do not crash on loading project files with unkown machine types. Show a
message instead.
This commit is contained in:
Lipu Fei 2018-06-11 07:52:32 +02:00
parent dc5a48fb7d
commit 83fcc60bee

View file

@ -13,6 +13,7 @@ from UM.Workspace.WorkspaceReader import WorkspaceReader
from UM.Application import Application from UM.Application import Application
from UM.Logger import Logger from UM.Logger import Logger
from UM.Message import Message
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from UM.Signal import postponeSignals, CompressTechnique from UM.Signal import postponeSignals, CompressTechnique
from UM.Settings.ContainerFormatError import ContainerFormatError from UM.Settings.ContainerFormatError import ContainerFormatError
@ -470,6 +471,20 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
Logger.log("w", "File %s is not a valid workspace.", file_name) Logger.log("w", "File %s is not a valid workspace.", file_name)
return WorkspaceReader.PreReadResult.failed return WorkspaceReader.PreReadResult.failed
# Check if the machine definition exists. If not, indicate failure because we do not import definition files.
def_results = self._container_registry.findDefinitionContainersMetadata(id = machine_definition_id)
if not def_results:
message = Message(i18n_catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!",
"Project file <filename>{0}</filename> contains an unknown machine type"
" <message>{1}</message>. Cannot import the machine."
" Models will be imported instead.", file_name, machine_definition_id),
title = i18n_catalog.i18nc("@info:title", "Open Project File"))
message.show()
Logger.log("i", "Could unknown machine definition %s in project file %s, cannot import it.",
self._machine_info.definition_id, file_name)
return WorkspaceReader.PreReadResult.failed
# In case we use preRead() to check if a file is a valid project file, we don't want to show a dialog. # In case we use preRead() to check if a file is a valid project file, we don't want to show a dialog.
if not show_dialog: if not show_dialog:
return WorkspaceReader.PreReadResult.accepted return WorkspaceReader.PreReadResult.accepted