Coverage for src / ezqt_app / services / ui / window_service.py: 100.00%
38 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-26 07:07 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-26 07:07 +0000
1"""
2Window state service implementation for UI runtime interactions.
3"""
5from __future__ import annotations
7# ///////////////////////////////////////////////////////////////
8# IMPORTS
9# ///////////////////////////////////////////////////////////////
10# Third-party imports
11from PySide6.QtGui import QIcon
13# Local imports
14from ...domain.ports.main_window import MainWindowProtocol
15from ..runtime import get_runtime_state_service
18# ///////////////////////////////////////////////////////////////
19# CLASSES
20# ///////////////////////////////////////////////////////////////
21class WindowService:
22 """Service responsible for maximize/restore and window state flags."""
24 @staticmethod
25 def maximize_restore(window: MainWindowProtocol) -> None:
26 """Toggle between maximized and restored window state."""
27 runtime_state_service = get_runtime_state_service()
28 is_maximized = runtime_state_service.get_global_state()
30 if not is_maximized:
31 window.showMaximized()
32 runtime_state_service.set_global_state(True)
33 window.ui.app_margins_layout.setContentsMargins(0, 0, 0, 0)
34 window.ui.header_container.maximize_restore_btn.setToolTip("Restore")
35 window.ui.header_container.maximize_restore_btn.setIcon(
36 QIcon(":/icons/icon_restore.png")
37 )
38 window.ui.bottom_bar.size_grip_spacer.hide()
39 window.left_grip.hide()
40 window.right_grip.hide()
41 window.top_grip.hide()
42 window.bottom_grip.hide()
43 return
45 runtime_state_service.set_global_state(False)
46 window.showNormal()
47 window.resize(window.width() + 1, window.height() + 1)
48 window.ui.app_margins_layout.setContentsMargins(10, 10, 10, 10)
49 window.ui.header_container.maximize_restore_btn.setToolTip("Maximize")
50 window.ui.header_container.maximize_restore_btn.setIcon(
51 QIcon(":/icons/icon_maximize.png")
52 )
53 window.ui.bottom_bar.size_grip_spacer.show()
54 window.left_grip.show()
55 window.right_grip.show()
56 window.top_grip.show()
57 window.bottom_grip.show()
59 @staticmethod
60 def get_status() -> bool:
61 """Return the current maximize/restore status."""
62 return get_runtime_state_service().get_global_state()
64 @staticmethod
65 def set_status(status: bool) -> None:
66 """Persist the current maximize/restore status."""
67 get_runtime_state_service().set_global_state(status)