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

1"""Unified clickable help components using consolidated help system.""" 

2 

3from typing import Union, Callable, Optional 

4from textual.widgets import Static 

5from textual.events import Click 

6from textual.message import Message 

7 

8 

9class ClickableHelpLabel(Static): 

10 """A clickable label that shows help information when clicked.""" 

11 

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. 

16  

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) 

27 

28 self.help_target = help_target 

29 self.param_name = param_name 

30 self.param_description = param_description 

31 self.param_type = param_type 

32 

33 # Add CSS classes for styling 

34 self.add_class("clickable-help") 

35 

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 

39 

40 from openhcs.textual_tui.windows.help_windows import HelpWindowManager 

41 

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 ) 

50 

51 

52class ClickableFunctionTitle(ClickableHelpLabel): 

53 """Clickable function title that shows function documentation.""" 

54 

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 '' 

58 

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})" 

63 

64 super().__init__( 

65 text=f"[bold]{title}[/bold]", 

66 help_target=func, 

67 **kwargs 

68 ) 

69 

70 

71class ClickableParameterLabel(ClickableHelpLabel): 

72 """Clickable parameter label that shows parameter documentation.""" 

73 

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() 

78 

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 ) 

86 

87 

88class HelpIndicator(Static): 

89 """Simple help indicator that can be added next to any widget.""" 

90 

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) 

95 

96 self.help_target = help_target 

97 self.param_name = param_name 

98 self.param_description = param_description 

99 self.param_type = param_type 

100 

101 self.add_class("help-indicator") 

102 

103 async def on_click(self, event: Click) -> None: 

104 """Handle click events to show help window using unified manager.""" 

105 event.stop() 

106 

107 from openhcs.textual_tui.windows.help_windows import HelpWindowManager 

108 

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 )