Coverage for src / ezqt_app / services / application / settings_loader.py: 25.00%
34 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# ///////////////////////////////////////////////////////////////
2# SERVICES.APPLICATION.SETTINGS_LOADER - Settings loader service
3# Project: ezqt_app
4# ///////////////////////////////////////////////////////////////
6"""Loads application settings from YAML and applies them to SettingsService."""
8from __future__ import annotations
10# ///////////////////////////////////////////////////////////////
11# IMPORTS
12# ///////////////////////////////////////////////////////////////
13# Standard library imports
14from pathlib import Path
16# Third-party imports
17import yaml
19from ...utils.printer import get_printer, set_global_debug
21# Local imports
22from ..config.config_service import get_config_service
23from ..settings import get_settings_service
26# ///////////////////////////////////////////////////////////////
27# CLASSES
28# ///////////////////////////////////////////////////////////////
29class SettingsLoader:
30 """Loads ``app.config.yaml`` and populates the settings service.
32 Reads the YAML configuration file, extracts application and GUI
33 parameters, and injects them into the singleton ``SettingsService``.
34 """
36 # -----------------------------------------------------------
37 # Static API
38 # -----------------------------------------------------------
40 @staticmethod
41 def load_app_settings(
42 yaml_file: Path | None = None,
43 ) -> dict:
44 """Load application settings from YAML and apply to SettingsService.
46 Parameters
47 ----------
48 yaml_file:
49 Path to the YAML file. Defaults to the package ``app.config.yaml``.
51 Returns
52 -------
53 dict
54 Raw ``app`` section from the YAML file.
55 """
56 if yaml_file is None:
57 data = get_config_service().load_config("app", force_reload=True)
58 app_data = data.get("app", {})
59 else:
60 with open(yaml_file, encoding="utf-8") as file:
61 data = yaml.safe_load(file)
62 app_data = data.get("app", {})
64 settings_service = get_settings_service()
65 debug_enabled = bool(app_data.get("debug", False))
67 # App identity
68 settings_service.set_app_name(app_data["name"])
69 settings_service.set_app_description(app_data["description"])
70 settings_service.set_custom_title_bar_enabled(True)
71 settings_service.set_debug_enabled(debug_enabled)
72 set_global_debug(debug_enabled)
74 # Window dimensions
75 settings_service.set_app_min_size(
76 width=app_data["app_min_width"],
77 height=app_data["app_min_height"],
78 )
79 settings_service.set_app_dimensions(
80 width=app_data["app_width"],
81 height=app_data["app_height"],
82 )
84 # GUI settings
85 try:
86 settings_panel = data.get("settings_panel", {})
87 settings_service.set_theme(
88 settings_panel.get("theme", {}).get("default", app_data["theme"])
89 )
90 except KeyError:
91 settings_service.set_theme(app_data["theme"])
93 settings_service.set_menu_widths(
94 shrinked=app_data["menu_panel_shrinked_width"],
95 extended=app_data["menu_panel_extended_width"],
96 )
97 settings_service.set_settings_panel_width(app_data["settings_panel_width"])
98 settings_service.set_time_animation(app_data["time_animation"])
100 # Display summary through the globally configured printer instance.
101 get_printer().config_display(app_data)
103 return app_data