Coverage for openhcs/textual_tui/widgets/shared/enum_radio_set.py: 0.0%
18 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 05:57 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 05:57 +0000
1# File: openhcs/textual_tui/widgets/shared/enum_radio_set.py
3from enum import Enum
4from typing import Optional
5from textual.widgets import RadioSet, RadioButton
6from textual.app import ComposeResult
8class EnumRadioSet(RadioSet):
9 """RadioSet for enum parameters. Simple enum → radio buttons mapping."""
11 def __init__(self, enum_class: type, current_value: Optional[str] = None, **kwargs):
12 """Create RadioSet from enum class.
14 Args:
15 enum_class: The enum class (e.g., VariableComponents)
16 current_value: Current string value (e.g., "site")
17 **kwargs: Additional RadioSet arguments
18 """
19 # Force compact mode and pass to parent
20 kwargs['compact'] = True
21 super().__init__(**kwargs)
22 self.enum_class = enum_class
23 self.current_value = current_value
25 # Set height to exactly fit the number of enum options
26 num_options = len(list(enum_class))
27 self.styles.height = num_options
28 self.styles.max_height = num_options
30 def compose(self) -> ComposeResult:
31 """Create radio buttons for each enum option."""
32 for enum_member in self.enum_class:
33 # Create button with enum value as ID
34 button_id = f"enum_{enum_member.value}"
35 is_pressed = (self.current_value == enum_member.value)
37 yield RadioButton(
38 label=enum_member.value.upper(),
39 value=is_pressed,
40 id=button_id
41 )