Coverage for openhcs/textual_tui/widgets/different_values_checkbox.py: 0.0%
37 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"""Simple checkbox widget for handling different values across multiple configurations."""
3from typing import Any
4from textual.widgets import Checkbox
5from textual.events import Click
8class DifferentValuesCheckbox(Checkbox):
9 """Simple checkbox that shows empty state for different values.
11 This widget appears as an empty square (no X, no label) when values differ
12 across configurations. Click sets it to the default value.
13 """
15 def __init__(
16 self,
17 default_value: bool,
18 field_name: str = "",
19 **kwargs
20 ):
21 """Initialize the DifferentValuesCheckbox widget.
23 Args:
24 default_value: The default value to use when clicked
25 field_name: Name of the field (for debugging/logging)
26 **kwargs: Additional arguments passed to Checkbox
27 """
28 # Create empty checkbox with no label
29 kwargs.setdefault("value", False)
30 kwargs.setdefault("label", "") # No label
32 super().__init__(**kwargs)
34 self.default_value = default_value
35 self.field_name = field_name
36 self.is_different_state = True
38 # Add CSS class to appear disabled but still receive clicks
39 self.add_class("different-values-disabled")
41 # Set tooltip to explain the state
42 self.tooltip = f"DIFFERENT VALUES - Click to set to default: {self.default_value}"
44 def on_click(self, event: Click) -> None:
45 """Message handler for Click events - set to default value if in different state."""
46 if self.is_different_state:
47 # Set to default value and remove disabled appearance
48 self.value = bool(self.default_value)
49 self.is_different_state = False
50 self.remove_class("different-values-disabled")
52 # Clear tooltip since we now have a value
53 self.tooltip = ""
55 # Focus the checkbox
56 self.focus()
58 # Prevent the event from bubbling up
59 event.stop()
61 def reset_to_different(self) -> None:
62 """Reset the checkbox back to 'DIFFERENT VALUES' state."""
63 self.value = False # Empty state
64 self.is_different_state = True
66 # Add CSS class to appear disabled
67 self.add_class("different-values-disabled")
69 # Restore tooltip
70 self.tooltip = f"DIFFERENT VALUES - Click to set to default: {self.default_value}"
72 def set_value(self, value: bool) -> None:
73 """Set a specific value (not from click-to-default)."""
74 self.value = bool(value)
75 self.is_different_state = False
76 self.tooltip = ""
78 @property
79 def current_state(self) -> str:
80 """Get the current state of the widget."""
81 if self.is_different_state:
82 return "different"
83 elif self.value == bool(self.default_value):
84 return "default"
85 else:
86 return "modified"