Coverage for src/pytribeam/GUI/common/resources.py: 0%
36 statements
« prev ^ index » next coverage.py v7.6.1, created at 2026-06-16 18:30 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2026-06-16 18:30 +0000
1"""Resource path management for GUI application.
3This module provides centralized management of application resources like
4images, icons, and documentation files.
5"""
7from pathlib import Path
8from typing import Optional, Dict, List
11class AppResources:
12 """Manages paths to application resources.
14 This class provides a single point of access for all resource files,
15 making it easy to update paths and avoid hard-coded path strings throughout
16 the codebase.
18 Attributes:
19 base_path: Root directory of the pytribeam package
20 """
22 def __init__(self, base_path: Path):
23 """Initialize resource manager.
25 Args:
26 base_path: Root directory containing docs, src, etc.
27 """
28 self.base_path = Path(base_path)
30 @classmethod
31 def from_module_file(cls, module_file: str) -> "AppResources":
32 """Create AppResources from a module's __file__ path.
34 This is the preferred way to initialize AppResources from within
35 the GUI module, as it automatically determines the correct base path.
37 Args:
38 module_file: The __file__ attribute from a module
40 Returns:
41 AppResources instance with correct base path
43 Example:
44 resources = AppResources.from_module_file(__file__)
45 """
46 # From GUI/module.py, go up to pytribeam root
47 module_path = Path(module_file)
48 # module.py -> GUI -> pytribeam -> src -> pytribeam_root
49 if module_path.parent.name == "GUI":
50 base = module_path.parent.parent.parent.parent
51 elif (
52 module_path.parent.name == "common"
53 or module_path.parent.name == "config_ui"
54 ):
55 base = module_path.parent.parent.parent.parent.parent
56 return cls(base_path=base)
58 @property
59 def icon_path(self) -> Path:
60 """Path to application icon (.ico file)."""
61 return self.base_path / "docs/userguide/src/logos/logo_color_alt.ico"
63 @property
64 def logo_dark_path(self) -> Path:
65 """Path to dark theme logo image."""
66 return self.base_path / "docs/userguide/src/logos/logo_color_dark.png"
68 @property
69 def logo_light_path(self) -> Path:
70 """Path to light theme logo image."""
71 return self.base_path / "docs/userguide/src/logos/logo_color.png"
73 @property
74 def user_guide_path(self) -> Path:
75 """Path to user guide HTML index."""
76 # return self.base_path / "docs" / "userguide" / "book" / "index.html"
77 return "https://github.com/sandialabs/pytribeam/blob/main/docs/userguide/src/SUMMARY.md"
79 def get_logo_path(self, theme: str = "dark") -> Path:
80 """Get logo path for specified theme.
82 Args:
83 theme: Theme name ('dark' or 'light')
85 Returns:
86 Path to appropriate logo file
88 Raises:
89 ValueError: If theme is not 'dark' or 'light'
90 """
91 if theme.lower() == "dark":
92 return self.logo_dark_path
93 elif theme.lower() == "light":
94 return self.logo_light_path
95 else:
96 raise ValueError(f"Unknown theme: {theme}. Must be 'dark' or 'light'")
98 def verify_resources(self) -> Dict[str, bool]:
99 """Check which resources exist on filesystem.
101 Returns:
102 Dictionary mapping resource names to existence status
103 """
104 return {
105 "icon": self.icon_path.exists(),
106 "logo_dark": self.logo_dark_path.exists(),
107 "logo_light": self.logo_light_path.exists(),
108 "user_guide": self.user_guide_path.exists(),
109 }
111 def get_missing_resources(self) -> List[str]:
112 """Get list of missing resource files.
114 Returns:
115 List of resource names that don't exist on filesystem
116 """
117 status = self.verify_resources()
118 return [name for name, exists in status.items() if not exists]