|
9 | 9 | from utils import txt_editor, json_editor |
10 | 10 |
|
11 | 11 |
|
| 12 | +def resource_path(relative_path: str) -> str: |
| 13 | + """Корректный путь к файлу для работы из .py и из .exe""" |
| 14 | + if hasattr(sys, "_MEIPASS"): |
| 15 | + return os.path.join(sys._MEIPASS, relative_path) |
| 16 | + return os.path.join(os.path.abspath("."), relative_path) |
| 17 | + |
| 18 | + |
12 | 19 | class QtLauncher(QMainWindow, Ui_MainWindow): |
13 | 20 | def __init__(self): |
14 | 21 | super().__init__() |
15 | 22 | self.setFixedSize(750, 420) |
16 | | - |
17 | 23 | self.setupUi(self) |
18 | | - self.update_game_list() |
19 | 24 |
|
| 25 | + self.update_game_list() |
20 | 26 | txt_editor.create_txt() |
21 | 27 | self.update_last_game_list() |
22 | | - |
23 | 28 | json_editor.create_json() |
24 | 29 |
|
25 | | - with open(f'style/{json_editor.get_theme()}.qss') as qss: |
| 30 | + theme_file = resource_path(f"style/{json_editor.get_theme()}.qss") |
| 31 | + with open(theme_file, "r", encoding="utf-8") as qss: |
26 | 32 | self.setStyleSheet(qss.read()) |
27 | 33 |
|
| 34 | + # Сигналы |
28 | 35 | self.add_game.clicked.connect(self.open_dialog) |
29 | 36 | self.list_games.itemDoubleClicked.connect(self.open_game) |
30 | 37 | self.delete_game.clicked.connect(self.delete_game_from_list) |
31 | | - |
32 | 38 | self.sort_name_a_z.clicked.connect(lambda: self.sort_games("")) |
33 | 39 | self.sort_name_z_a.clicked.connect(lambda: self.sort_games("r")) |
34 | | - |
35 | 40 | self.action_2.triggered.connect(lambda: self.set_theme("light")) |
36 | 41 | self.action_3.triggered.connect(lambda: self.set_theme("dark")) |
37 | 42 |
|
38 | 43 | def set_theme(self, theme): |
39 | | - with open(f'style/{theme}.qss') as qss: |
| 44 | + theme_file = resource_path(f"style/{theme}.qss") |
| 45 | + with open(theme_file, "r", encoding="utf-8") as qss: |
40 | 46 | self.setStyleSheet(qss.read()) |
41 | 47 | json_editor.update_setting("theme", theme) |
42 | 48 |
|
|
0 commit comments