Coverage for src / ezqt_app / services / ui / panel_service.py: 93.10%

50 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-06 13:12 +0000

1""" 

2UI panel animation service implementation. 

3""" 

4 

5from __future__ import annotations 

6 

7# /////////////////////////////////////////////////////////////// 

8# IMPORTS 

9# /////////////////////////////////////////////////////////////// 

10# Standard library imports 

11from typing import cast 

12 

13# Third-party imports 

14from PySide6.QtCore import QEasingCurve, QObject, QPropertyAnimation 

15 

16# Local imports 

17from ...domain.ports.main_window import MainWindowProtocol 

18from ...utils.diagnostics import warn_tech 

19from ..settings import get_settings_service 

20 

21 

22# /////////////////////////////////////////////////////////////// 

23# CLASSES 

24# /////////////////////////////////////////////////////////////// 

25class PanelService: 

26 """Service responsible for menu and settings panel animations.""" 

27 

28 @staticmethod 

29 def toggle_menu_panel(window: MainWindowProtocol, enable: bool) -> None: 

30 """Animate the left menu panel between shrink and extended widths.""" 

31 if not enable: 

32 return 

33 

34 settings_service = get_settings_service() 

35 width = window.ui.menu_container.width() 

36 max_extend = window.ui.menu_container.get_extended_width() 

37 standard = window.ui.menu_container.get_shrink_width() 

38 width_extended = max_extend if width == standard else standard 

39 

40 window.menu_animation = QPropertyAnimation( 

41 cast(QObject, window.ui.menu_container), 

42 b"minimumWidth", 

43 ) 

44 window.menu_animation.setDuration(settings_service.gui.TIME_ANIMATION) 

45 window.menu_animation.setStartValue(width) 

46 window.menu_animation.setEndValue(width_extended) 

47 window.menu_animation.setEasingCurve(QEasingCurve.Type.InOutQuart) 

48 window.menu_animation.start() 

49 

50 @staticmethod 

51 def toggle_settings_panel(window: MainWindowProtocol, enable: bool) -> None: 

52 """Animate the right settings panel and synchronize theme toggle.""" 

53 if not enable: 

54 return 

55 

56 settings_service = get_settings_service() 

57 width = window.ui.settings_panel.width() 

58 max_extend = settings_service.gui.SETTINGS_PANEL_WIDTH 

59 standard = 0 

60 is_opening = width == 0 

61 width_extended = max_extend if is_opening else standard 

62 

63 window.ui.header_container.set_settings_panel_open(is_opening) 

64 

65 window.settings_animation = QPropertyAnimation( 

66 cast(QObject, window.ui.settings_panel), 

67 b"minimumWidth", 

68 ) 

69 window.settings_animation.setDuration(settings_service.gui.TIME_ANIMATION) 

70 window.settings_animation.setStartValue(width) 

71 window.settings_animation.setEndValue(width_extended) 

72 window.settings_animation.setEasingCurve(QEasingCurve.Type.InOutQuart) 

73 window.settings_animation.start() 

74 

75 theme_toggle = window.ui.settings_panel.get_theme_selector() 

76 if theme_toggle and hasattr(theme_toggle, "set_value"): 76 ↛ exitline 76 didn't return from function 'toggle_settings_panel' because the condition on line 76 was always true

77 try: 

78 gui = settings_service.gui 

79 internal = f"{gui.THEME_PRESET}:{gui.THEME}" 

80 value_to_display = getattr( 

81 window.ui.settings_panel, "_theme_value_to_display", {} 

82 ) 

83 display = value_to_display.get(internal, "") 

84 if display: 84 ↛ exitline 84 didn't return from function 'toggle_settings_panel' because the condition on line 84 was always true

85 theme_toggle.set_value(display) 

86 except Exception as error: 

87 warn_tech( 

88 code="ui.panel.theme_selector_sync_failed", 

89 message="Theme selector sync failed on panel open", 

90 error=error, 

91 )