Coverage for openhcs/textual_tui/widgets/main_content.py: 0.0%
34 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-04 02:09 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-04 02:09 +0000
1"""
2MainContent Widget for OpenHCS Textual TUI
4Main content area with horizontal split between PlateManager and PipelineEditor.
5Matches the layout from the current prompt-toolkit TUI.
6"""
8import logging
10from textual.app import ComposeResult
11from textual.widget import Widget
12from textual.css.query import NoMatches
14from openhcs.core.config import GlobalPipelineConfig
15from openhcs.io.filemanager import FileManager
16from .system_monitor import SystemMonitorTextual
19logger = logging.getLogger(__name__)
22class MainContent(Widget):
23 """
24 Main content area widget.
26 Layout: Horizontal split with PlateManager (left) and PipelineEditor (right)
27 Uses proper frame containers with titles matching the current TUI.
28 """
30 def __init__(self, filemanager: FileManager, global_config: GlobalPipelineConfig):
31 """
32 Initialize the main content area.
34 Args:
35 filemanager: FileManager instance for file operations
36 global_config: Global configuration (for initial setup only)
37 """
38 super().__init__()
39 self.filemanager = filemanager
40 # Note: We don't store global_config as it can become stale
41 # Child widgets should use self.app.global_config to get current config
42 logger.debug("MainContent initialized")
44 def compose(self) -> ComposeResult:
45 """Compose the main content layout."""
46 # Use the system monitor as the main background
47 yield SystemMonitorTextual()
49 def on_mount(self) -> None:
50 """Called when the main content is mounted."""
51 # Widgets are now in floating windows, no setup needed here
52 pass
54 def open_pipeline_editor(self):
55 """Open the pipeline editor in shared window."""
56 window = self._get_or_create_shared_window()
57 window.show_pipeline_editor()
58 window.open_state = True
60 def open_plate_manager(self):
61 """Open the plate manager in shared window."""
62 window = self._get_or_create_shared_window()
63 window.show_plate_manager()
64 window.open_state = True
66 def _get_or_create_shared_window(self):
67 """Get existing shared window or create new one."""
68 from openhcs.textual_tui.windows import PipelinePlateWindow
70 # Try to find existing window - if it doesn't exist, query_one will raise NoMatches
71 try:
72 window = self.app.query_one(PipelinePlateWindow)
73 return window
74 except NoMatches:
75 # Expected case: window doesn't exist yet, create new one
76 window = PipelinePlateWindow(self.filemanager, self.app.global_config)
77 self.app.mount(window)
78 return window