Source code for devctrl.utility
[docs]
def increase_value(values, getter, setter, name):
"""
From a list of values, get the current value, increase the value to the next possible value and set it using the getter
:param values: list of values
:param getter: Function returning a value in values
:param setter: Function taking a value from values
:param name: Name of the thing, used in a potential error message
:return: The new value
"""
current_val = getter()
new_idx = values.index(current_val) + 1
if new_idx > len(values):
raise RuntimeError(f"Can not increase '{name}', already at maximum ({current_val})")
new_val = values[new_idx]
setter(new_val)
return new_val
[docs]
def decrease_value(values, getter, setter, name):
"""
From a list of values, get the current value, decrease the value to the next possible value and set it using the getter
:param values: list of values
:param getter: Function returning a value in values
:param setter: Function taking a value from values
:param name: Name of the thing, used in a potential error message
:return: The new value
"""
current_val = getter()
new_idx = values.index(current_val) - 1
if new_idx > len(values):
raise RuntimeError(f"Can not decrease '{name}', already at minimum ({current_val})")
new_val = values[new_idx]
setter(new_val)
return new_val