Coverage for openhcs/textual_tui/windows/base_window.py: 0.0%
24 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 05:57 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 05:57 +0000
1"""Base window class for OpenHCS TUI windows."""
3from textual_window import Window
4from textual.app import ComposeResult
5from textual.widgets import Button
6from textual.containers import Container
9class BaseOpenHCSWindow(Window):
10 """
11 Base class for all OpenHCS windows with common functionality.
13 Features:
14 - Instant window open/close (no fade animations)
15 - Automatic window position/size caching
16 """
18 def __init__(self, window_id: str, title: str, mode: str = "temporary", **kwargs):
19 """
20 Initialize base OpenHCS window.
22 Args:
23 window_id: Unique window identifier
24 title: Window title
25 mode: "temporary" or "permanent"
27 Features:
28 - Instant window operations (no animations)
29 - Automatic position/size caching
30 """
31 super().__init__(
32 id=window_id,
33 name=title,
34 mode=mode,
35 allow_resize=True,
36 animated=False, # Disable fade effects for instant window open/close
37 **kwargs
38 )
40 def close_window(self):
41 """Close this window (handles both temporary and permanent modes)."""
42 # Save window position and size to cache before closing
43 import logging
44 logger = logging.getLogger(__name__)
46 try:
47 # Get window identifier
48 window_id = getattr(self, 'id', None) or self.__class__.__name__
50 # Get window position and size
51 if hasattr(self, 'offset') and hasattr(self, 'size'):
52 position = self.offset
53 size = self.size
55 # Save to cache
56 from openhcs.textual_tui.services.window_cache import get_window_cache
57 cache = get_window_cache()
58 cache.save_window_state(window_id, position, size)
60 logger.info(f"💾 WINDOW CLOSING: {window_id} - Position: ({position.x},{position.y}), Size: {size.width}x{size.height}")
61 else:
62 logger.info(f"💾 WINDOW CLOSING: {window_id} - Position/size unavailable")
63 except Exception as e:
64 window_id = getattr(self, 'id', None) or self.__class__.__name__
65 logger.warning(f"💾 WINDOW CLOSING: {window_id} - Cache save failed: {e}")
67 # Use the correct textual-window API method
68 super().close_window() # Call the textual-window Window.close_window() method
70 # Position caching removed - it was interfering with window button creation
71 # Only keeping animated=False for instant window open/close