Coverage for src / ezqt_app / services / ui / component_factory.py: 100.00%

15 statements  

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

1# /////////////////////////////////////////////////////////////// 

2# SERVICES.UI.COMPONENT_FACTORY - UI component factory service 

3# Project: ezqt_app 

4# /////////////////////////////////////////////////////////////// 

5 

6"""Service implementation for reusable UI components.""" 

7 

8from __future__ import annotations 

9 

10# /////////////////////////////////////////////////////////////// 

11# IMPORTS 

12# /////////////////////////////////////////////////////////////// 

13# Local imports 

14from ...domain.models.ui import FONT_SPECS, SIZE_POLICY_SPECS, FontSpec, SizePolicySpec 

15from ...domain.ports.ui_component_factory import UiComponentFactoryProtocol 

16 

17 

18# /////////////////////////////////////////////////////////////// 

19# CLASSES 

20# /////////////////////////////////////////////////////////////// 

21class UiComponentFactory(UiComponentFactoryProtocol): 

22 """Factory that exposes predefined UI component specifications.""" 

23 

24 def __init__(self) -> None: 

25 """Initialize the factory.""" 

26 self._initialized = False 

27 

28 def initialize(self) -> None: 

29 """Mark the factory as initialized (specs are statically defined).""" 

30 self._initialized = True 

31 

32 def get_font(self, name: str) -> FontSpec | None: 

33 """Return a predefined font specification by name.""" 

34 return FONT_SPECS.get(name) 

35 

36 def get_size_policy(self, name: str) -> SizePolicySpec | None: 

37 """Return a predefined size policy specification by name.""" 

38 return SIZE_POLICY_SPECS.get(name) 

39 

40 

41# /////////////////////////////////////////////////////////////// 

42# SINGLETONS 

43# /////////////////////////////////////////////////////////////// 

44_ui_component_factory = UiComponentFactory() 

45 

46 

47# /////////////////////////////////////////////////////////////// 

48# FUNCTIONS 

49# /////////////////////////////////////////////////////////////// 

50def get_ui_component_factory() -> UiComponentFactory: 

51 """Return the singleton UI component factory.""" 

52 return _ui_component_factory