WIP: feature/cleanup_programming_interface #40

Draft
Hazel wants to merge 35 commits from feature/cleanup_programming_interface into experimental
Showing only changes of commit c0fbd16929 - Show all commits

View File

@ -451,10 +451,27 @@ class Option:
This could represent a data object, a string or a page.
"""
def __init__(self, value: Any, text: Optional[str] = None, keys: Set[str] = None):
def __init__(self, value: Any, text: Optional[str] = None, keys: Set[str] = None, hidden: bool = False):
self.value = value
self.text = text or str(value)
self.hidden = hidden
self.keys = keys or set()
self.keys.add(self.text)
class SelectOption:
def __init__(self, options: List[Option] = None):
self._key_to_option: Dict[Any, Option] = dict()
self._options: List[Option] = options
self.extend(options or [])
def append(self, option: Option):
self._options.append(option)
for key in option.keys:
self._key_to_option[key] = option
def extend(self, options: List[Option]):
for option in options:
self.append(option)