44from typing import Optional
55from ctypes import wintypes , windll , create_unicode_buffer , pointer
66
7- _DEFAULT_TIMEOUT = 60.0
8- _resource_paths = {}
9-
107class ResourceFiles :
8+ DIRECTORY = "resources"
9+
1110 SSFA_TEMPLATE = "ssfa-template.mnt"
1211
1312 START_MNTS_BTN = "start-mountains.png"
@@ -24,6 +23,15 @@ def append_to_path(end_str, prefix=os.getcwd()):
2423 """Joins the given end string to the end of the file path prefix."""
2524 return os .path .join (os .sep , prefix , end_str )
2625
26+ _DEFAULT_TIMEOUT = 60.0
27+ _resource_paths = {}
28+ # Find base path for resources
29+ try :
30+ # PyInstaller creates a temp folder and stores path in _MEIPASS
31+ _resource_base_path = append_to_path (ResourceFiles .DIRECTORY , sys ._MEIPASS )
32+ except Exception :
33+ _resource_base_path = append_to_path (ResourceFiles .DIRECTORY )
34+
2735def resource_abs_path (relative_path ):
2836 """Get absolute path to resources, works for normal file handling and for PyInstaller.
2937 Based on answer from stackoverflow page:
@@ -34,13 +42,8 @@ def resource_abs_path(relative_path):
3442 if relative_path in _resource_paths :
3543 return _resource_paths [relative_path ]
3644
37- try :
38- # PyInstaller creates a temp folder and stores path in _MEIPASS
39- base_path = sys ._MEIPASS
40- except Exception :
41- base_path = append_to_path ("resources" )
42-
43- path = append_to_path (relative_path , base_path )
45+ global _resource_base_path
46+ path = append_to_path (relative_path , _resource_base_path )
4447 if not os .path .exists (path ):
4548 raise FileNotFoundError ("Could not find resource " + path )
4649 _resource_paths [relative_path ] = path
0 commit comments