Coverage for src / ezqt_app / services / ui / menu_service.py: 100.00%
20 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-06 13:12 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-06 13:12 +0000
1"""
2UI menu service implementation.
3"""
5from __future__ import annotations
7# ///////////////////////////////////////////////////////////////
8# IMPORTS
9# ///////////////////////////////////////////////////////////////
10# Third-party imports
11from PySide6.QtWidgets import QToolButton, QWidget
13# Local imports
14from ...domain.ports.main_window import MainWindowProtocol
16# ///////////////////////////////////////////////////////////////
17# CLASSES
18# ///////////////////////////////////////////////////////////////
21class MenuService:
22 """Service responsible for menu item selection state and style refresh."""
24 @staticmethod
25 def select_menu(window: MainWindowProtocol, widget: str) -> None:
26 """Set active class on a menu button identified by its object name."""
27 for menu_widget in window.ui.menu_container.top_menu.findChildren(QToolButton):
28 if menu_widget.objectName() == widget and isinstance(
29 menu_widget, QToolButton
30 ):
31 menu_widget.setProperty("class", "active")
32 MenuService.refresh_style(menu_widget)
34 @staticmethod
35 def deselect_menu(window: MainWindowProtocol, widget: str) -> None:
36 """Set inactive class on all menu buttons except the selected one."""
37 for menu_widget in window.ui.menu_container.top_menu.findChildren(QToolButton):
38 if menu_widget.objectName() != widget and isinstance(
39 menu_widget, QToolButton
40 ):
41 menu_widget.setProperty("class", "inactive")
42 MenuService.refresh_style(menu_widget)
44 @staticmethod
45 def refresh_style(widget: QWidget) -> None:
46 """Re-apply widget style after dynamic property changes."""
47 widget.style().unpolish(widget)
48 widget.style().polish(widget)