Changing the profile name to something unique.

Imported profiles will be now called "Custom profile (<G-code
filename>)"
This commit is contained in:
Thomas Karl Pietrowski 2016-06-17 12:41:24 +02:00
parent 9511692638
commit 4ca247cf37

View file

@ -7,6 +7,8 @@ import re #Regular expressions for parsing escape characters in the settings.
from UM.Application import Application #To get the machine manager to create the new profile in. from UM.Application import Application #To get the machine manager to create the new profile in.
from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.InstanceContainer import InstanceContainer
from UM.Logger import Logger from UM.Logger import Logger
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
from cura.ProfileReader import ProfileReader from cura.ProfileReader import ProfileReader
@ -71,7 +73,7 @@ class GCodeProfileReader(ProfileReader):
serialized = pattern.sub(lambda m: GCodeProfileReader.escape_characters[re.escape(m.group(0))], serialized) serialized = pattern.sub(lambda m: GCodeProfileReader.escape_characters[re.escape(m.group(0))], serialized)
Logger.log("i", "Serialized the following from %s: %s" %(file_name, repr(serialized))) Logger.log("i", "Serialized the following from %s: %s" %(file_name, repr(serialized)))
# Create an empty profile with the name of the G-code file # Create an empty profile - the id will be changed later
profile = InstanceContainer("G-code-imported-profile") profile = InstanceContainer("G-code-imported-profile")
profile.addMetaDataEntry("type", "quality") profile.addMetaDataEntry("type", "quality")
try: try:
@ -80,4 +82,9 @@ class GCodeProfileReader(ProfileReader):
Logger.log("e", "Unable to serialise the profile: %s", str(e)) Logger.log("e", "Unable to serialise the profile: %s", str(e))
return None return None
#Creating a unique name using the filename of the GCode
new_name = catalog.i18nc("@label", "Custom profile (%s)") %(os.path.splitext(os.path.basename(file_name))[0])
profile.setName(new_name)
profile._id = new_name
return profile return profile