27
27
28
28
import tribler .gui
29
29
from tribler .core .components .knowledge .db .knowledge_db import ResourceType
30
+ from tribler .core .utilities .install_dir import get_base_path
31
+ from tribler .core .utilities .utilities import is_frozen
30
32
from tribler .gui .defs import CORRUPTED_DB_WAS_FIXED_MESSAGE , HEALTH_DEAD , HEALTH_GOOD , HEALTH_MOOT , HEALTH_UNCHECKED
31
33
32
34
# fmt: off
@@ -194,17 +196,14 @@ def duration_to_string(seconds):
194
196
return tr ("%(seconds)is" ) % data
195
197
196
198
197
- def get_base_path ():
198
- """ Get absolute path to resource, works for dev and for PyInstaller """
199
- try :
200
- # PyInstaller creates a temp folder and stores path in _MEIPASS
201
- base_path = sys ._MEIPASS
202
- except Exception :
203
- base_path = os .path .dirname (tribler .gui .__file__ )
204
- return base_path
199
+ def get_gui_path ():
200
+ """ Get absolute path to resource, works for dev and for PyInstaller/cx_freeze"""
201
+ if is_frozen ():
202
+ return get_base_path () / 'tribler_source/tribler/gui'
203
+ return get_base_path () / 'gui'
205
204
206
205
207
- TRANSLATIONS_DIR = os .path .join (get_base_path (), "i18n" )
206
+ TRANSLATIONS_DIR = os .path .join (get_gui_path (), "i18n" )
208
207
209
208
210
209
def get_available_translations ():
@@ -224,7 +223,7 @@ def get_available_translations():
224
223
225
224
226
225
def get_ui_file_path (filename ):
227
- return os .path .join (get_base_path (), 'qt_resources' , filename )
226
+ return os .path .join (get_gui_path (), 'qt_resources' , filename )
228
227
229
228
230
229
def get_image_path (filename : str , convert_slashes_to_forward : bool = False ) -> str :
@@ -235,7 +234,7 @@ def get_image_path(filename: str, convert_slashes_to_forward: bool = False) -> s
235
234
This can be used to ensure that images on Windows can be correctly loaded.
236
235
Also see https://stackoverflow.com/questions/26121737/qt-stylesheet-background-image-from-filepath.
237
236
"""
238
- path = os .path .join (get_base_path (), 'images' , filename )
237
+ path = os .path .join (get_gui_path (), 'images' , filename )
239
238
if convert_slashes_to_forward :
240
239
path = path .replace ("\\ " , "/" )
241
240
return path
@@ -245,7 +244,7 @@ def get_font_path(filename: str) -> str:
245
244
"""
246
245
Return a path to a particular font in the fonts directory.
247
246
"""
248
- return os .path .join (get_base_path (), 'fonts' , filename )
247
+ return os .path .join (get_gui_path (), 'fonts' , filename )
249
248
250
249
251
250
def get_gui_setting (gui_settings , value , default , is_bool = False ):
0 commit comments