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

49 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-26 07:07 +0000

1""" 

2UI panel animation service implementation. 

3""" 

4 

5from __future__ import annotations 

6 

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

8# IMPORTS 

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

10# Third-party imports 

11from PySide6.QtCore import QEasingCurve, QPropertyAnimation 

12 

13# Local imports 

14from ...domain.ports.main_window import MainWindowProtocol 

15from ...utils.diagnostics import warn_tech 

16from ..settings import get_settings_service 

17 

18 

19# /////////////////////////////////////////////////////////////// 

20# CLASSES 

21# /////////////////////////////////////////////////////////////// 

22class PanelService: 

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

24 

25 @staticmethod 

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

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

28 if not enable: 

29 return 

30 

31 settings_service = get_settings_service() 

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

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

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

35 width_extended = max_extend if width == standard else standard 

36 

37 window.menu_animation = QPropertyAnimation( 

38 window.ui.menu_container, # type: ignore[arg-type] 

39 b"minimumWidth", 

40 ) 

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

42 window.menu_animation.setStartValue(width) 

43 window.menu_animation.setEndValue(width_extended) 

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

45 window.menu_animation.start() 

46 

47 @staticmethod 

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

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

50 if not enable: 

51 return 

52 

53 settings_service = get_settings_service() 

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

55 max_extend = settings_service.gui.SETTINGS_PANEL_WIDTH 

56 standard = 0 

57 is_opening = width == 0 

58 width_extended = max_extend if is_opening else standard 

59 

60 window.ui.header_container.set_settings_panel_open(is_opening) 

61 

62 window.settings_animation = QPropertyAnimation( 

63 window.ui.settings_panel, # type: ignore[arg-type] 

64 b"minimumWidth", 

65 ) 

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

67 window.settings_animation.setStartValue(width) 

68 window.settings_animation.setEndValue(width_extended) 

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

70 window.settings_animation.start() 

71 

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

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

74 try: 

75 gui = settings_service.gui 

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

77 value_to_display = getattr( 

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

79 ) 

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

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

82 theme_toggle.set_value(display) 

83 except Exception as error: 

84 warn_tech( 

85 code="ui.panel.theme_selector_sync_failed", 

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

87 error=error, 

88 )