Skip to content

Commit afe6f8b

Browse files
committed
fix: Исправил main.py для pyinstaller
1 parent 173a15d commit afe6f8b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

main.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,40 @@
99
from utils import txt_editor, json_editor
1010

1111

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+
1219
class QtLauncher(QMainWindow, Ui_MainWindow):
1320
def __init__(self):
1421
super().__init__()
1522
self.setFixedSize(750, 420)
16-
1723
self.setupUi(self)
18-
self.update_game_list()
1924

25+
self.update_game_list()
2026
txt_editor.create_txt()
2127
self.update_last_game_list()
22-
2328
json_editor.create_json()
2429

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:
2632
self.setStyleSheet(qss.read())
2733

34+
# Сигналы
2835
self.add_game.clicked.connect(self.open_dialog)
2936
self.list_games.itemDoubleClicked.connect(self.open_game)
3037
self.delete_game.clicked.connect(self.delete_game_from_list)
31-
3238
self.sort_name_a_z.clicked.connect(lambda: self.sort_games(""))
3339
self.sort_name_z_a.clicked.connect(lambda: self.sort_games("r"))
34-
3540
self.action_2.triggered.connect(lambda: self.set_theme("light"))
3641
self.action_3.triggered.connect(lambda: self.set_theme("dark"))
3742

3843
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:
4046
self.setStyleSheet(qss.read())
4147
json_editor.update_setting("theme", theme)
4248

0 commit comments

Comments
 (0)