mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Drag profile into Cura; added importProfile(s), exportProfile to ContainerManager. CURA-787
This commit is contained in:
parent
d4f7a0e16c
commit
a23a922eec
3 changed files with 75 additions and 8 deletions
|
@ -4,7 +4,7 @@
|
||||||
import os.path
|
import os.path
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal, QUrl
|
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal, QUrl, QVariant
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
|
|
||||||
import UM.PluginRegistry
|
import UM.PluginRegistry
|
||||||
|
@ -802,3 +802,50 @@ class ContainerManager(QObject):
|
||||||
else:
|
else:
|
||||||
quality_changes.setDefinition(QualityManager.getInstance().getParentMachineDefinition(machine_definition))
|
quality_changes.setDefinition(QualityManager.getInstance().getParentMachineDefinition(machine_definition))
|
||||||
return quality_changes
|
return quality_changes
|
||||||
|
|
||||||
|
|
||||||
|
## Import profiles from a list of file_urls.
|
||||||
|
# Each QUrl item must end with .curaprofile, or it will not be imported.
|
||||||
|
#
|
||||||
|
# \param QVariant<QUrl>, essentially a list with QUrl objects.
|
||||||
|
# \return Dict with keys status, text
|
||||||
|
@pyqtSlot(QVariant, result="QVariantMap")
|
||||||
|
def importProfiles(self, file_urls):
|
||||||
|
status = "ok"
|
||||||
|
results = {"ok": [], "error": []}
|
||||||
|
for file_url in file_urls:
|
||||||
|
if not file_url.isValid():
|
||||||
|
continue
|
||||||
|
path = file_url.toLocalFile()
|
||||||
|
if not path:
|
||||||
|
continue
|
||||||
|
if not path.endswith(".curaprofile"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
single_result = UM.Settings.ContainerRegistry.getInstance().importProfile(path)
|
||||||
|
if single_result["status"] == "error":
|
||||||
|
status = "error"
|
||||||
|
results[single_result["status"]].append(single_result["message"])
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": status,
|
||||||
|
"message": "\n".join(results["ok"] + results["error"])}
|
||||||
|
|
||||||
|
## Import single profile, file_url does not have to end with curaprofile
|
||||||
|
@pyqtSlot(QUrl, result="QVariantMap")
|
||||||
|
def importProfile(self, file_url):
|
||||||
|
if not file_url.isValid():
|
||||||
|
return
|
||||||
|
path = file_url.toLocalFile()
|
||||||
|
if not path:
|
||||||
|
return
|
||||||
|
return UM.Settings.ContainerRegistry.getInstance().importProfile(path)
|
||||||
|
|
||||||
|
@pyqtSlot("QVariantList", QUrl, str)
|
||||||
|
def exportProfile(self, instance_id, file_url, file_type):
|
||||||
|
if not file_url.isValid():
|
||||||
|
return
|
||||||
|
path = file_url.toLocalFile()
|
||||||
|
if not path:
|
||||||
|
return
|
||||||
|
UM.Settings.ContainerRegistry.getInstance().exportProfile(instance_id, path, file_type)
|
||||||
|
|
|
@ -246,15 +246,35 @@ UM.MainWindow
|
||||||
{
|
{
|
||||||
if(drop.urls.length > 0)
|
if(drop.urls.length > 0)
|
||||||
{
|
{
|
||||||
|
// Import models
|
||||||
for(var i in drop.urls)
|
for(var i in drop.urls)
|
||||||
{
|
{
|
||||||
UM.MeshFileHandler.readLocalFile(drop.urls[i]);
|
// There is no endsWith in this version of JS...
|
||||||
if (i == drop.urls.length - 1)
|
if ((drop.urls[i].length <= 12) || (drop.urls[i].substring(drop.urls[i].length-12) !== ".curaprofile")) {
|
||||||
{
|
// Drop an object
|
||||||
var meshName = backgroundItem.getMeshName(drop.urls[i].toString())
|
UM.MeshFileHandler.readLocalFile(drop.urls[i]);
|
||||||
backgroundItem.hasMesh(decodeURIComponent(meshName))
|
if (i == drop.urls.length - 1)
|
||||||
|
{
|
||||||
|
var meshName = backgroundItem.getMeshName(drop.urls[i].toString());
|
||||||
|
backgroundItem.hasMesh(decodeURIComponent(meshName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Import profiles
|
||||||
|
var import_result = Cura.ContainerManager.importProfiles(drop.urls);
|
||||||
|
if (import_result.message !== "") {
|
||||||
|
messageDialog.text = import_result.message
|
||||||
|
if(import_result.status == "ok")
|
||||||
|
{
|
||||||
|
messageDialog.icon = StandardIcon.Information
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messageDialog.icon = StandardIcon.Critical
|
||||||
|
}
|
||||||
|
messageDialog.open()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -310,7 +310,7 @@ UM.ManagementPage
|
||||||
folder: CuraApplication.getDefaultPath("dialog_profile_path")
|
folder: CuraApplication.getDefaultPath("dialog_profile_path")
|
||||||
onAccepted:
|
onAccepted:
|
||||||
{
|
{
|
||||||
var result = base.model.importProfile(fileUrl)
|
var result = Cura.ContainerManager.importProfile(fileUrl);
|
||||||
messageDialog.text = result.message
|
messageDialog.text = result.message
|
||||||
if(result.status == "ok")
|
if(result.status == "ok")
|
||||||
{
|
{
|
||||||
|
@ -339,7 +339,7 @@ UM.ManagementPage
|
||||||
onAccepted:
|
onAccepted:
|
||||||
{
|
{
|
||||||
var containers = Cura.ContainerManager.findInstanceContainers({"type": "quality_changes", "name": base.currentItem.name})
|
var containers = Cura.ContainerManager.findInstanceContainers({"type": "quality_changes", "name": base.currentItem.name})
|
||||||
var result = base.model.exportProfile(containers, fileUrl, selectedNameFilter)
|
var result = Cura.ContainerManager.exportProfile(containers, fileUrl, selectedNameFilter)
|
||||||
|
|
||||||
if(result && result.status == "error")
|
if(result && result.status == "error")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue