mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-01-19 02:50:44 +00:00
Reset commands to defaults
This commit is contained in:
parent
bc7e8994c9
commit
2788a3ac91
|
@ -169,3 +169,7 @@ class HonCommand:
|
|||
else:
|
||||
result[name] = parameter
|
||||
return result
|
||||
|
||||
def reset(self):
|
||||
for parameter in self._parameters.values():
|
||||
parameter.reset()
|
||||
|
|
|
@ -7,14 +7,21 @@ if TYPE_CHECKING:
|
|||
class HonParameter:
|
||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||
self._key = key
|
||||
self._category: str = attributes.get("category", "")
|
||||
self._typology: str = attributes.get("typology", "")
|
||||
self._mandatory: int = attributes.get("mandatory", 0)
|
||||
self._attributes = attributes
|
||||
self._category: str = ""
|
||||
self._typology: str = ""
|
||||
self._mandatory: int = 0
|
||||
self._value: str | float = ""
|
||||
self._group: str = group
|
||||
self._triggers: Dict[
|
||||
str, List[Tuple[Callable[["HonRule"], None], "HonRule"]]
|
||||
] = {}
|
||||
self._set_attributes()
|
||||
|
||||
def _set_attributes(self):
|
||||
self._category = self._attributes.get("category", "")
|
||||
self._typology = self._attributes.get("typology", "")
|
||||
self._mandatory = self._attributes.get("mandatory", 0)
|
||||
|
||||
@property
|
||||
def key(self) -> str:
|
||||
|
@ -54,7 +61,7 @@ class HonParameter:
|
|||
return self._group
|
||||
|
||||
def add_trigger(
|
||||
self, value: str, func: Callable[["HonRule"], None], data: "HonRule"
|
||||
self, value: str, func: Callable[["HonRule"], None], data: "HonRule"
|
||||
) -> None:
|
||||
if self._value == value:
|
||||
func(data)
|
||||
|
@ -85,3 +92,6 @@ class HonParameter:
|
|||
param[rule.param_key] = rule.param_data.get("defaultValue", "")
|
||||
|
||||
return result
|
||||
|
||||
def reset(self):
|
||||
self._set_attributes()
|
||||
|
|
|
@ -10,12 +10,19 @@ def clean_value(value: str | float) -> str:
|
|||
class HonParameterEnum(HonParameter):
|
||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||
super().__init__(key, attributes, group)
|
||||
self._default = attributes.get("defaultValue")
|
||||
self._value = self._default or "0"
|
||||
self._values: List[str] = attributes.get("enumValues", [])
|
||||
self._default = ""
|
||||
self._value = ""
|
||||
self._values: List[str] = []
|
||||
self._set_attributes()
|
||||
if self._default and clean_value(self._default.strip("[]")) not in self.values:
|
||||
self._values.append(self._default)
|
||||
|
||||
def _set_attributes(self):
|
||||
super()._set_attributes()
|
||||
self._default = self._attributes.get("defaultValue")
|
||||
self._value = self._default or "0"
|
||||
self._values: List[str] = self._attributes.get("enumValues", [])
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.__class__} (<{self.key}> {self.values})"
|
||||
|
||||
|
|
|
@ -6,7 +6,12 @@ from pyhon.parameter.base import HonParameter
|
|||
class HonParameterFixed(HonParameter):
|
||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||
super().__init__(key, attributes, group)
|
||||
self._value = attributes.get("fixedValue", None)
|
||||
self._value = None
|
||||
self._set_attributes()
|
||||
|
||||
def _set_attributes(self):
|
||||
super()._set_attributes()
|
||||
self._value = self._attributes.get("fixedValue", None)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.__class__} (<{self.key}> fixed)"
|
||||
|
|
|
@ -7,10 +7,19 @@ from pyhon.parameter.base import HonParameter
|
|||
class HonParameterRange(HonParameter):
|
||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||
super().__init__(key, attributes, group)
|
||||
self._min: float = str_to_float(attributes["minimumValue"])
|
||||
self._max: float = str_to_float(attributes["maximumValue"])
|
||||
self._step: float = str_to_float(attributes["incrementValue"])
|
||||
self._default: float = str_to_float(attributes.get("defaultValue", self.min))
|
||||
self._min: float = 0
|
||||
self._max: float = 0
|
||||
self._step: float = 0
|
||||
self._default: float = 0
|
||||
self._value: float = 0
|
||||
self._set_attributes()
|
||||
|
||||
def _set_attributes(self):
|
||||
super()._set_attributes()
|
||||
self._min: float = str_to_float(self._attributes["minimumValue"])
|
||||
self._max: float = str_to_float(self._attributes["maximumValue"])
|
||||
self._step: float = str_to_float(self._attributes["incrementValue"])
|
||||
self._default: float = str_to_float(self._attributes.get("defaultValue", self.min))
|
||||
self._value: float = self._default
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
|
Loading…
Reference in a new issue