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