mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Don't add to profile if setting is legacy default
If a setting is equal to the legacy setting's default value, then it doesn't get added to the profile either. Contributes to issue CURA-37.
This commit is contained in:
parent
c0b5832a59
commit
e7b2586d36
1 changed files with 20 additions and 8 deletions
|
@ -23,6 +23,19 @@ class LegacyProfileReader(ProfileReader):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
## Prepares the default values of all legacy settings.
|
||||||
|
#
|
||||||
|
# These are loaded from the Dictionary of Doom.
|
||||||
|
#
|
||||||
|
# \param json The JSON file to load the default setting values from. This
|
||||||
|
# should not be a URL but a pre-loaded JSON handle.
|
||||||
|
# \return A dictionary of the default values of the legacy Cura version.
|
||||||
|
def prepareDefaults(self, json):
|
||||||
|
defaults = {}
|
||||||
|
for key in json["defaults"]: #We have to copy over all defaults from the JSON handle to a normal dict.
|
||||||
|
defaults[key] = json["defaults"][key]
|
||||||
|
return defaults
|
||||||
|
|
||||||
## Prepares the local variables that can be used in evaluation of computing
|
## Prepares the local variables that can be used in evaluation of computing
|
||||||
# new setting values from the old ones.
|
# new setting values from the old ones.
|
||||||
#
|
#
|
||||||
|
@ -34,14 +47,11 @@ class LegacyProfileReader(ProfileReader):
|
||||||
# legacy profile.
|
# legacy profile.
|
||||||
# \param config_section The section in the profile where the settings
|
# \param config_section The section in the profile where the settings
|
||||||
# should be found.
|
# should be found.
|
||||||
# \param json The JSON file to load the default setting values from. This
|
# \param defaults The default values for all settings in the legacy Cura.
|
||||||
# should not be an URL but a pre-loaded JSON handle.
|
|
||||||
# \return A set of local variables, one for each setting in the legacy
|
# \return A set of local variables, one for each setting in the legacy
|
||||||
# profile.
|
# profile.
|
||||||
def prepareLocals(self, config_parser, config_section, json):
|
def prepareLocals(self, config_parser, config_section, defaults):
|
||||||
locals = {}
|
locals = defaults.copy() #Don't edit the original!
|
||||||
for key in json["defaults"]: #We have to copy over all defaults from the JSON handle to a normal dict.
|
|
||||||
locals[key] = json["defaults"][key]
|
|
||||||
for option in config_parser.options(config_section):
|
for option in config_parser.options(config_section):
|
||||||
locals[option] = config_parser.get(config_section, option)
|
locals[option] = config_parser.get(config_section, option)
|
||||||
return locals
|
return locals
|
||||||
|
@ -84,7 +94,8 @@ class LegacyProfileReader(ProfileReader):
|
||||||
Logger.log("e", "Could not parse DictionaryOfDoom.json: %s", str(e))
|
Logger.log("e", "Could not parse DictionaryOfDoom.json: %s", str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
legacy_settings = self.prepareLocals(parser, section, dict_of_doom) #Gets the settings from the legacy profile.
|
defaults = self.prepareDefaults(dict_of_doom)
|
||||||
|
legacy_settings = self.prepareLocals(parser, section, defaults) #Gets the settings from the legacy profile.
|
||||||
|
|
||||||
#Check the target version in the Dictionary of Doom with this application version.
|
#Check the target version in the Dictionary of Doom with this application version.
|
||||||
if "target_version" not in dict_of_doom:
|
if "target_version" not in dict_of_doom:
|
||||||
|
@ -102,10 +113,11 @@ class LegacyProfileReader(ProfileReader):
|
||||||
compiled = compile(old_setting_expression, new_setting, "eval")
|
compiled = compile(old_setting_expression, new_setting, "eval")
|
||||||
try:
|
try:
|
||||||
new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation.
|
new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation.
|
||||||
|
value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default.
|
||||||
except Exception as e: #Probably some setting name that was missing or something else that went wrong in the ini file.
|
except Exception as e: #Probably some setting name that was missing or something else that went wrong in the ini file.
|
||||||
Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.")
|
Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.")
|
||||||
continue
|
continue
|
||||||
if profile.getSettingValue(new_setting) != new_value: #Not equal to the default.
|
if new_value != value_using_defaults and profile.getSettingValue(new_setting) != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura.
|
||||||
profile.setSettingValue(new_setting, new_value) #Store the setting in the profile!
|
profile.setSettingValue(new_setting, new_value) #Store the setting in the profile!
|
||||||
|
|
||||||
return profile
|
return profile
|
Loading…
Add table
Add a link
Reference in a new issue