mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Add normal Cura profile reader
This re-introduces the old functionality where you can import .curaprofile files. It's just now in the plug-in format. Contributes to issue CURA-34.
This commit is contained in:
parent
8947873121
commit
f95bfd8ae3
39
plugins/CuraProfileReader/CuraProfileReader.py
Normal file
39
plugins/CuraProfileReader/CuraProfileReader.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright (c) 2015 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from UM.Application import Application #To get the machine manager to create the new profile in.
|
||||
from UM.Settings.Profile import Profile
|
||||
from UM.Settings.ProfileReader import ProfileReader
|
||||
|
||||
## A plugin that reads profile data from Cura profile files.
|
||||
#
|
||||
# It reads a profile from a .curaprofile file, and returns it as a profile
|
||||
# instance.
|
||||
class CuraProfileReader(ProfileReader):
|
||||
## Initialises the cura profile reader.
|
||||
#
|
||||
# This does nothing since the only other function is basically stateless.
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
## Reads a cura profile from a file and returns it.
|
||||
#
|
||||
# \param file_name The file to read the cura profile from.
|
||||
# \return The cura profile that was in the file, if any. If the file could
|
||||
# not be read or didn't contain a valid profile, \code None \endcode is
|
||||
# returned.
|
||||
def read(self, file_name):
|
||||
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile.
|
||||
serialised = ""
|
||||
try:
|
||||
with open(file_name) as f: #Open file for reading.
|
||||
serialised = f.read()
|
||||
except IOError as e:
|
||||
Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
|
||||
return None
|
||||
|
||||
try:
|
||||
profile.unserialise(serialised)
|
||||
except Exception as e: #Parsing error. This is not a (valid) Cura profile then.
|
||||
return None
|
||||
return profile
|
25
plugins/CuraProfileReader/__init__.py
Normal file
25
plugins/CuraProfileReader/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (c) 2015 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from . import CuraProfileReader
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
def getMetaData():
|
||||
return {
|
||||
"plugin": {
|
||||
"name": catalog.i18nc("@label", "Cura Profile Reader"),
|
||||
"author": "Ultimaker",
|
||||
"version": "1.0",
|
||||
"description": catalog.i18nc("@info:whatsthis", "Provides support for importing Cura profiles."),
|
||||
"api": 2
|
||||
},
|
||||
"profile_reader": {
|
||||
"extension": "curaprofile",
|
||||
"description": catalog.i18nc("@item:inlistbox", "Cura Profile")
|
||||
}
|
||||
}
|
||||
|
||||
def register(app):
|
||||
return { "profile_reader": CuraProfileReader.CuraProfileReader() }
|
Loading…
x
Reference in New Issue
Block a user