|
9 | 9 | from PySide6.QtCore import Qt, QSettings |
10 | 10 | from PySide6.QtGui import QIcon, QFontDatabase, QFont |
11 | 11 |
|
| 12 | +# Helper for bundled resources (PyInstaller) |
| 13 | +def resource_path(relative_path): |
| 14 | + """ Get absolute path to resource, works for dev and for PyInstaller """ |
| 15 | + if hasattr(sys, '_MEIPASS'): |
| 16 | + return os.path.join(sys._MEIPASS, relative_path) |
| 17 | + return os.path.join(os.path.abspath(os.path.dirname(__file__)), relative_path) |
| 18 | + |
12 | 19 | UPDATE_VERSION_URL = "https://gist.githubusercontent.com/Chill-Astro/738d8c4978d0a71a028235c375a30d1f/raw/2e23a1b0ccb7bdbaa63c0dd128ddbfdb27ef814e/PyC_GUI_V.txt" # Gist URL |
13 | 20 |
|
14 | 21 | class Calculator(QWidget): |
15 | 22 | def __init__(self): |
16 | 23 | super().__init__() |
17 | | - self.CURRENT_VERSION = "1.1" # Massive Rewrite |
| 24 | + self.CURRENT_VERSION = "1.2" # Self-Contained Update |
18 | 25 | self.setWindowTitle("PyCalc - GUI") |
19 | 26 | self.setMinimumSize(400, 500) |
20 | | - icon_path = os.path.join(".", "Pycalc-GUI.ico") |
| 27 | + # Set window icon using resource_path (bundled with exe) |
| 28 | + icon_path = resource_path("PyCalc-GUI.ico") |
21 | 29 | if os.path.exists(icon_path): |
22 | 30 | self.setWindowIcon(QIcon(icon_path)) |
23 | | - # Load custom font Inter.ttf |
24 | | - font_id = QFontDatabase.addApplicationFont("Inter.ttf") |
| 31 | + # Load custom font Inter.ttf (bundled) |
| 32 | + font_id = QFontDatabase.addApplicationFont(resource_path("Inter.ttf")) |
25 | 33 | font_families = QFontDatabase.applicationFontFamilies(font_id) |
26 | 34 | if font_families: |
27 | 35 | custom_font = QFont(font_families[0], 14) |
@@ -172,8 +180,8 @@ def initSidebarUI(self): |
172 | 180 | sidebar_layout.setContentsMargins(2, 8, 2, 8) |
173 | 181 | # Sidebar buttons (icon only) |
174 | 182 | self.sidebar_buttons = [] |
175 | | - # Try to load icomoon.ttf |
176 | | - icomoon_font_id = QFontDatabase.addApplicationFont("icomoon.ttf") |
| 183 | + # Try to load icomoon.ttf (bundled) |
| 184 | + icomoon_font_id = QFontDatabase.addApplicationFont(resource_path("icomoon.ttf")) |
177 | 185 | icomoon_families = QFontDatabase.applicationFontFamilies(icomoon_font_id) |
178 | 186 | use_icomoon = bool(icomoon_families) |
179 | 187 | if use_icomoon: |
|
0 commit comments