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

21 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-04 02:09 +0000

1"""Base window class for OpenHCS TUI windows.""" 

2 

3from textual_window import Window 

4 

5 

6class BaseOpenHCSWindow(Window): 

7 """ 

8 Base class for all OpenHCS windows with common functionality. 

9 

10 Features: 

11 - Instant window open/close (no fade animations) 

12 - Automatic window position/size caching 

13 """ 

14 

15 def __init__(self, window_id: str, title: str, mode: str = "temporary", **kwargs): 

16 """ 

17 Initialize base OpenHCS window. 

18 

19 Args: 

20 window_id: Unique window identifier 

21 title: Window title 

22 mode: "temporary" or "permanent" 

23 

24 Features: 

25 - Instant window operations (no animations) 

26 - Automatic position/size caching 

27 """ 

28 super().__init__( 

29 id=window_id, 

30 name=title, 

31 mode=mode, 

32 allow_resize=True, 

33 animated=False, # Disable fade effects for instant window open/close 

34 **kwargs 

35 ) 

36 

37 def close_window(self): 

38 """Close this window (handles both temporary and permanent modes).""" 

39 # Save window position and size to cache before closing 

40 import logging 

41 logger = logging.getLogger(__name__) 

42 

43 try: 

44 # Get window identifier 

45 window_id = getattr(self, 'id', None) or self.__class__.__name__ 

46 

47 # Get window position and size 

48 if hasattr(self, 'offset') and hasattr(self, 'size'): 

49 position = self.offset 

50 size = self.size 

51 

52 # Save to cache 

53 from openhcs.textual_tui.services.window_cache import get_window_cache 

54 cache = get_window_cache() 

55 cache.save_window_state(window_id, position, size) 

56 

57 logger.info(f"💾 WINDOW CLOSING: {window_id} - Position: ({position.x},{position.y}), Size: {size.width}x{size.height}") 

58 else: 

59 logger.info(f"💾 WINDOW CLOSING: {window_id} - Position/size unavailable") 

60 except Exception as e: 

61 window_id = getattr(self, 'id', None) or self.__class__.__name__ 

62 logger.warning(f"💾 WINDOW CLOSING: {window_id} - Cache save failed: {e}") 

63 

64 # Use the correct textual-window API method 

65 super().close_window() # Call the textual-window Window.close_window() method 

66 

67 # Position caching removed - it was interfering with window button creation 

68 # Only keeping animated=False for instant window open/close