|
4 | 4 | import json
|
5 | 5 | import os
|
6 | 6 | import re
|
| 7 | +import sys |
7 | 8 | import threading
|
8 | 9 | import time
|
9 | 10 | import traceback
|
@@ -44,9 +45,21 @@ def current_ts():
|
44 | 45 | return int(time.time() * 1000)
|
45 | 46 |
|
46 | 47 |
|
| 48 | +def get_assets_path(*paths): |
| 49 | + # pyinstaller -F --add-data ./assets;assets KeymouseGo.py |
| 50 | + try: |
| 51 | + root = sys._MEIPASS |
| 52 | + except: |
| 53 | + root = os.getcwd() |
| 54 | + return os.path.join(root, 'assets', *paths) |
| 55 | + |
| 56 | + |
47 | 57 | class UIFunc(QMainWindow, Ui_UIView):
|
48 | 58 | def __init__(self):
|
49 | 59 | super(UIFunc, self).__init__()
|
| 60 | + |
| 61 | + print('assets root:', get_assets_path()) |
| 62 | + |
50 | 63 | self.setupUi(self)
|
51 | 64 |
|
52 | 65 | self.config = self.loadconfig()
|
@@ -331,12 +344,12 @@ def onconfigchange(self):
|
331 | 344 |
|
332 | 345 | def onchangelang(self):
|
333 | 346 | if self.choice_language.currentText() == '简体中文':
|
334 |
| - self.trans.load('i18n/zh-cn') |
| 347 | + self.trans.load(get_assets_path('i18n', 'zh-cn')) |
335 | 348 | _app = QApplication.instance()
|
336 | 349 | _app.installTranslator(self.trans)
|
337 | 350 | self.retranslateUi(self)
|
338 | 351 | elif self.choice_language.currentText() == 'English':
|
339 |
| - self.trans.load('i18n/en') |
| 352 | + self.trans.load(get_assets_path('i18n', 'en')) |
340 | 353 | _app = QApplication.instance()
|
341 | 354 | _app.installTranslator(self.trans)
|
342 | 355 | self.retranslateUi(self)
|
@@ -646,15 +659,15 @@ def run(self):
|
646 | 659 |
|
647 | 660 | def _play_start_sound(self):
|
648 | 661 | try:
|
649 |
| - path = os.path.join(os.getcwd(), 'sounds', 'start.mp3') |
| 662 | + path = get_assets_path('sounds', 'start.mp3') |
650 | 663 | playsound(path)
|
651 | 664 | except PlaysoundException as e:
|
652 | 665 | print(e)
|
653 | 666 |
|
654 | 667 | @classmethod
|
655 | 668 | def play_end_sound(cls):
|
656 | 669 | try:
|
657 |
| - path = os.path.join(os.getcwd(), 'sounds', 'end.mp3') |
| 670 | + path = get_assets_path('sounds', 'end.mp3') |
658 | 671 | playsound(path)
|
659 | 672 | except PlaysoundException as e:
|
660 | 673 | print(e)
|
0 commit comments