Uranium
Application Framework
Loading...
Searching...
No Matches
UM.Settings.SettingFunction.SettingFunction Class Reference
Inheritance diagram for UM.Settings.SettingFunction.SettingFunction:
UM.Settings.Validator.Validator

Public Member Functions

None __init__ (self, str expression)
Any __call__ (self, ContainerInterface value_provider, Optional[PropertyEvaluationContext] context=None, *, Optional[Dict[str, Any]] additional_variables=None)
bool __eq__ (self, object other)
int __hash__ (self)
bool isValid (self)
FrozenSet[str] getUsedSettingKeys (self)
str __str__ (self)
str __repr__ (self)
Dict[str, Any] __getstate__ (self)
None __setstate__ (self, Dict[str, Any] state)
None registerOperator (cls, str name, Callable operator)

Protected Member Functions

 _safeCompile (self)

Protected Attributes

 _code = expression
FrozenSet[str] _used_keys = frozenset()
FrozenSet[str] _used_values = frozenset()
Optional[CodeType] _compiled = None
bool _valid = False

Detailed Description

Evaluates Python formulas for a setting's property.

If a setting's property is a static type, e.g. a string, an int, a float, etc., its value will just be interpreted
as it is, but when it's a Python code (formula), the value needs to be evaluated via this class.

Constructor & Destructor Documentation

◆ __init__()

None UM.Settings.SettingFunction.SettingFunction.__init__ ( self,
str expression )
Constructor.

:param expression: The Python code this function should evaluate.

Member Function Documentation

◆ __call__()

Any UM.Settings.SettingFunction.SettingFunction.__call__ ( self,
ContainerInterface value_provider,
Optional[PropertyEvaluationContext] context = None,
* ,
Optional[Dict[str, Any]] additional_variables = None )
Call the actual function to calculate the value.

:param value_provider: The container from which to get setting values in the formula.
:param context: The context in which the call needs to be executed

◆ __getstate__()

Dict[str, Any] UM.Settings.SettingFunction.SettingFunction.__getstate__ ( self)
To support Pickle

Pickle does not support the compiled code, so instead remove it from the state.
We can re-compile it later on anyway.

◆ getUsedSettingKeys()

FrozenSet[str] UM.Settings.SettingFunction.SettingFunction.getUsedSettingKeys ( self)
Retrieve a set of the keys (strings) of all the settings used in this function.

:return: A set of the keys (strings) of all the settings used in this functions.

◆ isValid()

bool UM.Settings.SettingFunction.SettingFunction.isValid ( self)
Returns whether the function is ready to be executed.

:return: True if the function is valid, or False if it's not.

◆ registerOperator()

None UM.Settings.SettingFunction.SettingFunction.registerOperator ( cls,
str name,
Callable operator )
Expose a custom function to the code executed by SettingFunction

:param name: What identifier to use in the executed code.
:param operator: A callable that implements the actual logic to execute.

The documentation for this class was generated from the following file:
  • UM/Settings/SettingFunction.py