Skip to content

Commit

Permalink
improve assets
Browse files Browse the repository at this point in the history
  • Loading branch information
taojiayuan committed May 8, 2022
1 parent 423ead4 commit 2383476
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions UIFunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import os
import re
import sys
import threading
import time
import traceback
Expand Down Expand Up @@ -44,9 +45,21 @@ def current_ts():
return int(time.time() * 1000)


def get_assets_path(*paths):
# pyinstaller -F --add-data ./assets;assets KeymouseGo.py
try:
root = sys._MEIPASS
except:
root = os.getcwd()
return os.path.join(root, 'assets', *paths)


class UIFunc(QMainWindow, Ui_UIView):
def __init__(self):
super(UIFunc, self).__init__()

print('assets root:', get_assets_path())

self.setupUi(self)

self.config = self.loadconfig()
Expand Down Expand Up @@ -331,12 +344,12 @@ def onconfigchange(self):

def onchangelang(self):
if self.choice_language.currentText() == '简体中文':
self.trans.load('i18n/zh-cn')
self.trans.load(get_assets_path('i18n', 'zh-cn'))
_app = QApplication.instance()
_app.installTranslator(self.trans)
self.retranslateUi(self)
elif self.choice_language.currentText() == 'English':
self.trans.load('i18n/en')
self.trans.load(get_assets_path('i18n', 'en'))
_app = QApplication.instance()
_app.installTranslator(self.trans)
self.retranslateUi(self)
Expand Down Expand Up @@ -646,15 +659,15 @@ def run(self):

def _play_start_sound(self):
try:
path = os.path.join(os.getcwd(), 'sounds', 'start.mp3')
path = get_assets_path('sounds', 'start.mp3')
playsound(path)
except PlaysoundException as e:
print(e)

@classmethod
def play_end_sound(cls):
try:
path = os.path.join(os.getcwd(), 'sounds', 'end.mp3')
path = get_assets_path('sounds', 'end.mp3')
playsound(path)
except PlaysoundException as e:
print(e)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2383476

Please sign in to comment.