|
37 | 37 | logger = logging.getLogger(__name__) |
38 | 38 |
|
39 | 39 |
|
| 40 | +def resource_path(relative_path): |
| 41 | + """Get absolute path to resource, works for dev and for PyInstaller""" |
| 42 | + try: |
| 43 | + base_path = sys._MEIPASS |
| 44 | + except AttributeError: |
| 45 | + base_path = os.path.abspath(".") |
| 46 | + except Exception: |
| 47 | + base_path = os.path.abspath(".") |
| 48 | + |
| 49 | + path = os.path.join(base_path, relative_path) |
| 50 | + return path |
| 51 | + |
| 52 | + |
40 | 53 | class Worker(QObject): |
41 | 54 | """ |
42 | 55 | Runs a function in a separate thread and emits signals upon completion or error. |
@@ -306,15 +319,17 @@ def __init__(self): |
306 | 319 | def _set_icon(self): |
307 | 320 | """Sets the window icon if the icon file exists.""" |
308 | 321 | try: |
309 | | - app_icon = QIcon(constants.ICON_FILENAME) |
| 322 | + icon_path = resource_path(constants.ICON_FILENAME) |
| 323 | + app_icon = QIcon(icon_path) |
310 | 324 | if not app_icon.isNull(): |
311 | 325 | self.setWindowIcon(app_icon) |
| 326 | + logger.debug(f"Window icon set from {icon_path}") |
312 | 327 | else: |
313 | 328 | logger.warning( |
314 | | - f"{constants.ICON_FILENAME} not found or is invalid. Skipping window icon." |
| 329 | + f"Icon file loaded from {icon_path} but QIcon is null. Check icon validity/path." |
315 | 330 | ) |
316 | 331 | except Exception as e: |
317 | | - logger.error(f"Error setting window icon: {e}") |
| 332 | + logger.error(f"Error setting window icon using resource_path: {e}") |
318 | 333 |
|
319 | 334 | def init_ui(self) -> None: |
320 | 335 | """Creates and arranges the UI widgets.""" |
@@ -1134,14 +1149,17 @@ def closeEvent(self, event) -> None: |
1134 | 1149 | logger.error(f"Error setting AppUserModelID: {e}") |
1135 | 1150 |
|
1136 | 1151 | app = QApplication(sys.argv) |
1137 | | - app_icon = QIcon(constants.ICON_FILENAME) |
1138 | | - if not app_icon.isNull(): |
1139 | | - app.setWindowIcon(app_icon) |
1140 | | - logger.debug(f"Application icon set from {constants.ICON_FILENAME}") |
1141 | | - else: |
1142 | | - logger.warning( |
1143 | | - f"Application icon file '{constants.ICON_FILENAME}' not found or invalid." |
1144 | | - ) |
| 1152 | + |
| 1153 | + try: |
| 1154 | + icon_path = resource_path(constants.ICON_FILENAME) |
| 1155 | + app_icon = QIcon(icon_path) |
| 1156 | + if not app_icon.isNull(): |
| 1157 | + app.setWindowIcon(app_icon) |
| 1158 | + logger.debug(f"Application icon set from {icon_path}") |
| 1159 | + else: |
| 1160 | + logger.warning(f"App icon file loaded from {icon_path} but QIcon is null.") |
| 1161 | + except Exception as e: |
| 1162 | + logger.error(f"Error setting application icon using resource_path: {e}") |
1145 | 1163 |
|
1146 | 1164 | window = BluestacksRootToggle() |
1147 | 1165 | window.show() |
|
0 commit comments