mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Implemented importing multiple profiles from .curaprofile file
CURA-2099
This commit is contained in:
parent
ced6cd7320
commit
fcfbf78f9e
3 changed files with 23 additions and 19 deletions
|
@ -144,6 +144,9 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
return { "status": "ok", "message": catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName()) }
|
return { "status": "ok", "message": catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName()) }
|
||||||
else:
|
else:
|
||||||
for profile in profile_or_list:
|
for profile in profile_or_list:
|
||||||
|
if profile.getId() != "":
|
||||||
|
ContainerRegistry.getInstance().addContainer(profile)
|
||||||
|
else:
|
||||||
self._configureProfile(profile, name_seed)
|
self._configureProfile(profile, name_seed)
|
||||||
|
|
||||||
if len(profile_or_list) == 1:
|
if len(profile_or_list) == 1:
|
||||||
|
@ -158,7 +161,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
def _configureProfile(self, profile, name_seed):
|
def _configureProfile(self, profile, name_seed):
|
||||||
profile.setReadOnly(False)
|
profile.setReadOnly(False)
|
||||||
|
|
||||||
new_name = self.createUniqueName("quality", "", name_seed, catalog.i18nc("@label", "Custom profile"))
|
new_name = self.createUniqueName("quality_changes", "", name_seed, catalog.i18nc("@label", "Custom profile"))
|
||||||
profile.setName(new_name)
|
profile.setName(new_name)
|
||||||
profile._id = new_name
|
profile._id = new_name
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make.
|
from UM.Settings.InstanceContainer import InstanceContainer # The new profile to make.
|
||||||
from cura.ProfileReader import ProfileReader
|
from cura.ProfileReader import ProfileReader
|
||||||
|
|
||||||
|
import zipfile
|
||||||
|
|
||||||
## A plugin that reads profile data from Cura profile files.
|
## A plugin that reads profile data from Cura profile files.
|
||||||
#
|
#
|
||||||
# It reads a profile from a .curaprofile file, and returns it as a profile
|
# It reads a profile from a .curaprofile file, and returns it as a profile
|
||||||
|
@ -24,19 +26,19 @@ class CuraProfileReader(ProfileReader):
|
||||||
# not be read or didn't contain a valid profile, \code None \endcode is
|
# not be read or didn't contain a valid profile, \code None \endcode is
|
||||||
# returned.
|
# returned.
|
||||||
def read(self, file_name):
|
def read(self, file_name):
|
||||||
|
archive = zipfile.ZipFile(file_name, "r")
|
||||||
|
results = []
|
||||||
|
for profile_id in archive.namelist():
|
||||||
# Create an empty profile.
|
# Create an empty profile.
|
||||||
profile = InstanceContainer(os.path.basename(os.path.splitext(file_name)[0]))
|
profile = InstanceContainer(profile_id)
|
||||||
profile.addMetaDataEntry("type", "quality")
|
profile.addMetaDataEntry("type", "quality_changes")
|
||||||
try:
|
serialized = ""
|
||||||
with open(file_name) as f: # Open file for reading.
|
with archive.open(profile_id) as f:
|
||||||
serialized = f.read()
|
serialized = f.read()
|
||||||
except IOError as e:
|
|
||||||
Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
profile.deserialize(serialized)
|
profile.deserialize(serialized.decode("utf-8") )
|
||||||
except Exception as e: # Parsing error. This is not a (valid) Cura profile then.
|
except Exception as e: # Parsing error. This is not a (valid) Cura profile then.
|
||||||
Logger.log("e", "Error while trying to parse profile: %s", str(e))
|
Logger.log("e", "Error while trying to parse profile: %s", str(e))
|
||||||
return None
|
continue
|
||||||
return profile
|
results.append(profile)
|
||||||
|
return results
|
|
@ -108,7 +108,6 @@ UM.ManagementPage
|
||||||
text: catalog.i18nc("@action:button", "Import");
|
text: catalog.i18nc("@action:button", "Import");
|
||||||
iconName: "document-import";
|
iconName: "document-import";
|
||||||
onClicked: importDialog.open();
|
onClicked: importDialog.open();
|
||||||
enabled: false
|
|
||||||
},
|
},
|
||||||
Button
|
Button
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue