Coverage for openhcs/textual_tui/windows/help_window.py: 0.0%

35 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-14 05:57 +0000

1"""Help window for OpenHCS Textual TUI.""" 

2 

3from textual.app import ComposeResult 

4from textual.widgets import Static, Button 

5from textual.containers import ScrollableContainer, Horizontal 

6 

7from openhcs.textual_tui.windows.base_window import BaseOpenHCSWindow 

8 

9 

10class HelpWindow(BaseOpenHCSWindow): 

11 """Help window using textual-window system.""" 

12 

13 DEFAULT_CSS = """ 

14 HelpWindow ScrollableContainer { 

15 text-align: left; 

16 align: left top; 

17 } 

18 

19 HelpWindow Static { 

20 text-align: left; 

21 } 

22 """ 

23 

24 def __init__(self, content: str = "Help content goes here.", **kwargs): 

25 self.content = content 

26 

27 super().__init__( 

28 window_id="help", 

29 title="OpenHCS Help", 

30 mode="temporary", 

31 **kwargs 

32 ) 

33 

34 # Calculate dynamic minimum size based on content 

35 self._calculate_dynamic_size() 

36 

37 HELP_TEXT = """OpenHCS - Open High-Content Screening 

38 

39🔬 Visual Programming for Cell Biology Research 

40 

41Key Features: 

42• GPU-accelerated image processing 

43• Visual pipeline building 

44• Multi-backend storage support 

45• Real-time parameter editing 

46 

47Workflow: 

481. Add Plate → Select microscopy data 

492. Edit Step → Visual function selection 

503. Compile → Create execution plan 

514. Run → Process images 

52 

53For detailed documentation, see Nature Methods 

54publication.""" 

55 

56 def compose(self) -> ComposeResult: 

57 """Compose the help window content with scrollable area.""" 

58 # Scrollable content area 

59 with ScrollableContainer(): 

60 yield Static(self.HELP_TEXT) 

61 

62 # Close button at bottom - wrapped in Horizontal for automatic centering 

63 with Horizontal(): 

64 yield Button("Close", id="close", compact=True) 

65 

66 def on_button_pressed(self, event: Button.Pressed) -> None: 

67 """Handle button presses.""" 

68 if event.button.id == "close": 

69 self.close_window() 

70 

71 def _calculate_dynamic_size(self) -> None: 

72 """Calculate and set dynamic minimum window size based on content.""" 

73 try: 

74 # Calculate width based on content lines 

75 max_width = 50 # Base minimum width 

76 

77 content_lines = self.HELP_TEXT.split('\n') 

78 for line in content_lines: 

79 max_width = max(max_width, len(line) + 10) 

80 

81 # Calculate height based on number of lines 

82 min_height = 15 # Base minimum height 

83 content_line_count = len(content_lines) 

84 min_height = max(min_height, content_line_count + 5) # Content + margins + button 

85 

86 # Cap maximum size to reasonable limits 

87 max_width = min(max_width, 120) 

88 min_height = min(min_height, 40) 

89 

90 # Set dynamic minimum size 

91 self.styles.min_width = max_width 

92 self.styles.min_height = min_height 

93 

94 except Exception: 

95 # Fallback to default sizes if calculation fails 

96 self.styles.min_width = 50 

97 self.styles.min_height = 15 

98