18 from typing
import Any, List, Optional, Tuple, Dict
22 from ..base_parameter
import BaseParameter
23 from ..utils
import validateEnumStructure
24 from ....project
import ProjectType
27 class EnumParameter(BaseParameter[Dict[str, Any]]):
30 def types(self) -> List[type]:
33 def validate(self) -> Tuple[bool, Optional[str]]:
34 isValid, message = validateEnumStructure(self.name, self.value, self.required)
36 return isValid, message
39 value: Dict[str, Any] = self.value
41 selected = value[
"selected"]
42 options = value[
"options"]
44 if selected
is None and not self.required:
47 if not type(selected)
is int:
48 return False, f
"Enum parameter \"{self.name}.selected\" has invalid type. Expected \"int\", got \"{type(selected).__name__}\""
50 if selected >= len(options)
or selected < 0:
51 return False, f
"Enum parameter \"{self.name}.selected\" has out of range value"
55 def parseValue(self, type_: ProjectType) -> Optional[Any]:
56 if self.value
is None:
59 selected: Optional[int] = self.value.get(
"selected")
63 return self.value[
"options"][selected]
65 def overrideValue(self, value: Optional[Any]) -> Optional[Any]:
66 if value
is None or self.value
is None:
70 parsedValue: Dict[str, Any] = self.value
71 parsedValue[
"selected"] = int(value)
73 except ValueError
as e:
74 logging.getLogger(
"coretexpylib").warning(f
">> [Coretex] Failed to override enum parameter \"{self.name}\". | {e}")