Coverage for openhcs/textual_tui/widgets/main_content.py: 0.0%

39 statements  

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

1""" 

2MainContent Widget for OpenHCS Textual TUI 

3 

4Main content area with horizontal split between PlateManager and PipelineEditor. 

5Matches the layout from the current prompt-toolkit TUI. 

6""" 

7 

8import logging 

9 

10from textual.app import ComposeResult 

11from textual.containers import Container, Horizontal, Vertical 

12from textual.widgets import Static 

13from textual.widget import Widget 

14from textual.css.query import NoMatches 

15from textual.reactive import reactive 

16 

17from openhcs.core.config import GlobalPipelineConfig 

18from openhcs.io.filemanager import FileManager 

19from .system_monitor import SystemMonitorTextual 

20 

21from .plate_manager import PlateManagerWidget 

22from .pipeline_editor import PipelineEditorWidget 

23 

24logger = logging.getLogger(__name__) 

25 

26 

27class MainContent(Widget): 

28 """ 

29 Main content area widget. 

30  

31 Layout: Horizontal split with PlateManager (left) and PipelineEditor (right) 

32 Uses proper frame containers with titles matching the current TUI. 

33 """ 

34 

35 def __init__(self, filemanager: FileManager, global_config: GlobalPipelineConfig): 

36 """ 

37 Initialize the main content area. 

38 

39 Args: 

40 filemanager: FileManager instance for file operations 

41 global_config: Global configuration (for initial setup only) 

42 """ 

43 super().__init__() 

44 self.filemanager = filemanager 

45 # Note: We don't store global_config as it can become stale 

46 # Child widgets should use self.app.global_config to get current config 

47 logger.debug("MainContent initialized") 

48 

49 def compose(self) -> ComposeResult: 

50 """Compose the main content layout.""" 

51 # Use the system monitor as the main background 

52 yield SystemMonitorTextual() 

53 

54 def on_mount(self) -> None: 

55 """Called when the main content is mounted.""" 

56 # Widgets are now in floating windows, no setup needed here 

57 pass 

58 

59 def open_pipeline_editor(self): 

60 """Open the pipeline editor in shared window.""" 

61 window = self._get_or_create_shared_window() 

62 window.show_pipeline_editor() 

63 window.open_state = True 

64 

65 def open_plate_manager(self): 

66 """Open the plate manager in shared window.""" 

67 window = self._get_or_create_shared_window() 

68 window.show_plate_manager() 

69 window.open_state = True 

70 

71 def _get_or_create_shared_window(self): 

72 """Get existing shared window or create new one.""" 

73 from openhcs.textual_tui.windows import PipelinePlateWindow 

74 

75 # Try to find existing window - if it doesn't exist, query_one will raise NoMatches 

76 try: 

77 window = self.app.query_one(PipelinePlateWindow) 

78 return window 

79 except NoMatches: 

80 # Expected case: window doesn't exist yet, create new one 

81 window = PipelinePlateWindow(self.filemanager, self.app.global_config) 

82 self.app.mount(window) 

83 return window