mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-22 06:03:57 -06:00
WIP: Make material import work
This commit is contained in:
parent
0b859bb308
commit
581699cd8d
2 changed files with 36 additions and 8 deletions
|
@ -459,7 +459,7 @@ class ContainerManager(QObject):
|
||||||
@pyqtSlot(QUrl, result = "QVariantMap")
|
@pyqtSlot(QUrl, result = "QVariantMap")
|
||||||
def importMaterialContainer(self, file_url_or_string: Union[QUrl, str]) -> Dict[str, str]:
|
def importMaterialContainer(self, file_url_or_string: Union[QUrl, str]) -> Dict[str, str]:
|
||||||
if not file_url_or_string:
|
if not file_url_or_string:
|
||||||
return { "status": "error", "message": "Invalid path"}
|
return {"status": "error", "message": "Invalid path"}
|
||||||
|
|
||||||
if isinstance(file_url_or_string, QUrl):
|
if isinstance(file_url_or_string, QUrl):
|
||||||
file_url = file_url_or_string.toLocalFile()
|
file_url = file_url_or_string.toLocalFile()
|
||||||
|
@ -467,16 +467,16 @@ class ContainerManager(QObject):
|
||||||
file_url = file_url_or_string
|
file_url = file_url_or_string
|
||||||
|
|
||||||
if not file_url or not os.path.exists(file_url):
|
if not file_url or not os.path.exists(file_url):
|
||||||
return { "status": "error", "message": "Invalid path" }
|
return {"status": "error", "message": "Invalid path"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mime_type = MimeTypeDatabase.getMimeTypeForFile(file_url)
|
mime_type = MimeTypeDatabase.getMimeTypeForFile(file_url)
|
||||||
except MimeTypeNotFoundError:
|
except MimeTypeNotFoundError:
|
||||||
return { "status": "error", "message": "Could not determine mime type of file" }
|
return {"status": "error", "message": "Could not determine mime type of file"}
|
||||||
|
|
||||||
container_type = self._container_registry.getContainerForMimeType(mime_type)
|
container_type = self._container_registry.getContainerForMimeType(mime_type)
|
||||||
if not container_type:
|
if not container_type:
|
||||||
return { "status": "error", "message": "Could not find a container to handle the specified file."}
|
return {"status": "error", "message": "Could not find a container to handle the specified file."}
|
||||||
|
|
||||||
container_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_url)))
|
container_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_url)))
|
||||||
container_id = self._container_registry.uniqueName(container_id)
|
container_id = self._container_registry.uniqueName(container_id)
|
||||||
|
@ -487,7 +487,7 @@ class ContainerManager(QObject):
|
||||||
with open(file_url, "rt", encoding = "utf-8") as f:
|
with open(file_url, "rt", encoding = "utf-8") as f:
|
||||||
container.deserialize(f.read())
|
container.deserialize(f.read())
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
return { "status": "error", "message": "Permission denied when trying to read the file"}
|
return {"status": "error", "message": "Permission denied when trying to read the file"}
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
return {"status": "error", "message": str(ex)}
|
return {"status": "error", "message": str(ex)}
|
||||||
|
|
||||||
|
@ -495,7 +495,7 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
self._container_registry.addContainer(container)
|
self._container_registry.addContainer(container)
|
||||||
|
|
||||||
return { "status": "success", "message": "Successfully imported container {0}".format(container.getName()) }
|
return {"status": "success", "message": "Successfully imported container {0}".format(container.getName())}
|
||||||
|
|
||||||
## Update the current active quality changes container with the settings from the user container.
|
## Update the current active quality changes container with the settings from the user container.
|
||||||
#
|
#
|
||||||
|
|
|
@ -108,8 +108,8 @@ Item
|
||||||
text: catalog.i18nc("@action:button", "Import")
|
text: catalog.i18nc("@action:button", "Import")
|
||||||
iconName: "document-import"
|
iconName: "document-import"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
forceActiveFocus()
|
forceActiveFocus();
|
||||||
// TODO
|
importMaterialDialog.open();
|
||||||
}
|
}
|
||||||
visible: true
|
visible: true
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,34 @@ Item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDialog
|
||||||
|
{
|
||||||
|
id: importMaterialDialog
|
||||||
|
title: catalog.i18nc("@title:window", "Import Material")
|
||||||
|
selectExisting: true
|
||||||
|
nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
|
||||||
|
folder: CuraApplication.getDefaultPath("dialog_material_path")
|
||||||
|
onAccepted:
|
||||||
|
{
|
||||||
|
var result = Cura.ContainerManager.importMaterialContainer(fileUrl);
|
||||||
|
|
||||||
|
messageDialog.title = catalog.i18nc("@title:window", "Import Material");
|
||||||
|
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message);
|
||||||
|
if (result.status == "success") {
|
||||||
|
messageDialog.icon = StandardIcon.Information;
|
||||||
|
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully imported material <filename>%1</filename>").arg(fileUrl);
|
||||||
|
}
|
||||||
|
else if (result.status == "duplicate") {
|
||||||
|
messageDialog.icon = StandardIcon.Warning;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
messageDialog.icon = StandardIcon.Critical;
|
||||||
|
}
|
||||||
|
messageDialog.open();
|
||||||
|
CuraApplication.setDefaultPath("dialog_material_path", folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FileDialog
|
FileDialog
|
||||||
{
|
{
|
||||||
id: exportMaterialDialog
|
id: exportMaterialDialog
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue