Coverage for openhcs/textual_tui/widgets/shared/clickable_help_label.py: 0.0%

46 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-01 18:33 +0000

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

2 

3from typing import Union, Callable 

4from textual.widgets import Static 

5from textual.events import Click 

6 

7 

8class ClickableHelpLabel(Static): 

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

10 

11 def __init__(self, text: str, help_target: Union[Callable, type] = None, 

12 param_name: str = None, param_description: str = None, 

13 param_type: type = None, **kwargs): 

14 """Initialize clickable help label. 

15  

16 Args: 

17 text: Display text for the label 

18 help_target: Function or class to show help for (for function help) 

19 param_name: Parameter name (for parameter help) 

20 param_description: Parameter description (for parameter help) 

21 param_type: Parameter type (for parameter help) 

22 """ 

23 # Add help indicator to text 

24 display_text = f"{text} [dim](?)[/dim]" 

25 super().__init__(display_text, **kwargs) 

26 

27 self.help_target = help_target 

28 self.param_name = param_name 

29 self.param_description = param_description 

30 self.param_type = param_type 

31 

32 # Add CSS classes for styling 

33 self.add_class("clickable-help") 

34 

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

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

37 event.stop() # Prevent event bubbling 

38 

39 from openhcs.textual_tui.windows.help_windows import HelpWindowManager 

40 

41 if self.help_target: 

42 # Show function/class help using unified manager 

43 await HelpWindowManager.show_docstring_help(self.app, self.help_target) 

44 elif self.param_name: 

45 # Show parameter help using the passed description directly 

46 await HelpWindowManager.show_parameter_help( 

47 self.app, self.param_name, self.param_description or "No description available", self.param_type 

48 ) 

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: 

113 # Show parameter help using the passed description directly 

114 await HelpWindowManager.show_parameter_help( 

115 self.app, self.param_name, self.param_description or "No description available", self.param_type 

116 ) 

117