Skip to content

Commit

Permalink
Merge pull request #957 from Ultimaker/CURA-12009_add_setting_depends_on
Browse files Browse the repository at this point in the history
CURA-12009 add setting depends on
  • Loading branch information
wawanbreton authored Jul 16, 2024
2 parents 2c5e1ba + 53239ca commit 21391d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions UM/Settings/DefinitionContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,17 @@ def _processFunction(self, definition: SettingDefinition, property_name: str) ->
except AttributeError:
return

if not isinstance(function, SettingFunction):
return
settings_dependencies = set()

if isinstance(function, SettingFunction):
settings_dependencies.update(function.getUsedSettingKeys())

try:
settings_dependencies.update(definition.depends_on_settings)
except AttributeError:
pass

for setting in function.getUsedSettingKeys():
for setting in settings_dependencies:
# Prevent circular relations between the same setting and the same property
# Note that the only property used by SettingFunction is the "value" property, which
# is why this is hard coded here.
Expand Down
2 changes: 2 additions & 0 deletions UM/Settings/SettingDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ def _updateDescendants(self, definition: "SettingDefinition" = None) -> Dict[str
"warning_value": {"type": DefinitionPropertyType.Function, "required": False, "read_only": True, "default": None, "depends_on": None},
# For bool type: if the value is the same as the error value, the setting will be in the error state.
"error_value": {"type": DefinitionPropertyType.Function, "required": False, "read_only": True, "default": None, "depends_on": None},
# Optional list of settings that a setting explicitely depends on, which is useful when this can not be fully calculated from the formula.
"depends_on_settings": {"type": DefinitionPropertyType.Any, "required": False, "read_only": True, "default": [], "depends_on": None},
} # type: Dict[str, Dict[str, Any]]

__type_definitions = {
Expand Down

0 comments on commit 21391d8

Please sign in to comment.