Coverage for openhcs/textual_tui/widgets/shared/clickable_help_label.py: 0.0%
47 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"""Unified clickable help components using consolidated help system."""
3from typing import Union, Callable, Optional
4from textual.widgets import Static
5from textual.events import Click
6from textual.message import Message
9class ClickableHelpLabel(Static):
10 """A clickable label that shows help information when clicked."""
12 def __init__(self, text: str, help_target: Union[Callable, type] = None,
13 param_name: str = None, param_description: str = None,
14 param_type: type = None, **kwargs):
15 """Initialize clickable help label.
17 Args:
18 text: Display text for the label
19 help_target: Function or class to show help for (for function help)
20 param_name: Parameter name (for parameter help)
21 param_description: Parameter description (for parameter help)
22 param_type: Parameter type (for parameter help)
23 """
24 # Add help indicator to text
25 display_text = f"{text} [dim](?)[/dim]"
26 super().__init__(display_text, **kwargs)
28 self.help_target = help_target
29 self.param_name = param_name
30 self.param_description = param_description
31 self.param_type = param_type
33 # Add CSS classes for styling
34 self.add_class("clickable-help")
36 async def on_click(self, event: Click) -> None:
37 """Handle click events to show help window using unified manager."""
38 event.stop() # Prevent event bubbling
40 from openhcs.textual_tui.windows.help_windows import HelpWindowManager
42 if self.help_target:
43 # Show function/class help using unified manager
44 await HelpWindowManager.show_docstring_help(self.app, self.help_target)
45 elif self.param_name and self.param_description:
46 # Show parameter help using unified manager
47 await HelpWindowManager.show_parameter_help(
48 self.app, self.param_name, self.param_description, self.param_type
49 )
52class ClickableFunctionTitle(ClickableHelpLabel):
53 """Clickable function title that shows function documentation."""
55 def __init__(self, func: Callable, index: int = None, **kwargs):
56 func_name = getattr(func, '__name__', 'Unknown Function')
57 module_name = getattr(func, '__module__', '').split('.')[-1] if func else ''
59 # Build title text
60 title = f"{index + 1}: {func_name}" if index is not None else func_name
61 if module_name:
62 title += f" ({module_name})"
64 super().__init__(
65 text=f"[bold]{title}[/bold]",
66 help_target=func,
67 **kwargs
68 )
71class ClickableParameterLabel(ClickableHelpLabel):
72 """Clickable parameter label that shows parameter documentation."""
74 def __init__(self, param_name: str, param_description: str = None,
75 param_type: type = None, **kwargs):
76 # Format parameter name nicely
77 display_name = param_name.replace('_', ' ').title()
79 super().__init__(
80 text=display_name,
81 param_name=param_name,
82 param_description=param_description or "No description available",
83 param_type=param_type,
84 **kwargs
85 )
88class HelpIndicator(Static):
89 """Simple help indicator that can be added next to any widget."""
91 def __init__(self, help_target: Union[Callable, type] = None,
92 param_name: str = None, param_description: str = None,
93 param_type: type = None, **kwargs):
94 super().__init__("[dim](?)[/dim]", **kwargs)
96 self.help_target = help_target
97 self.param_name = param_name
98 self.param_description = param_description
99 self.param_type = param_type
101 self.add_class("help-indicator")
103 async def on_click(self, event: Click) -> None:
104 """Handle click events to show help window using unified manager."""
105 event.stop()
107 from openhcs.textual_tui.windows.help_windows import HelpWindowManager
109 if self.help_target:
110 # Show function/class help using unified manager
111 await HelpWindowManager.show_docstring_help(self.app, self.help_target)
112 elif self.param_name and self.param_description:
113 # Show parameter help using unified manager
114 await HelpWindowManager.show_parameter_help(
115 self.app, self.param_name, self.param_description, self.param_type
116 )