forked from JargeZ/ntscqt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ntscQT.py
executable file
·65 lines (48 loc) · 1.69 KB
/
ntscQT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import sys
from pathlib import Path
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QLibraryInfo
from PyQt5.QtCore import QFile, QTextStream
import darkdetect
from app import NtscApp
from app import logger
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = QLibraryInfo.location(
QLibraryInfo.PluginsPath
)
def crash_handler(type, value, tb):
logger.trace(value)
logger.exception("Uncaught exception: {0}".format(str(value)))
sys.exit(1)
# Install exception handler
sys.excepthook = crash_handler
def main():
translator = QtCore.QTranslator()
locale = QtCore.QLocale.system().name()
print("ntscQT by JargeZ")
# if run by pyinstaller executable, frozen attr will be true
if getattr(sys, 'frozen', False):
# _MEIPASS contain temp pyinstaller dir
base_dir = Path(sys._MEIPASS)
locale_file = str((base_dir / 'translate' / f'{locale}.qm').resolve())
else:
base_dir = Path(__file__).absolute().parent
locale_file = str((base_dir / 'translate' / f'{locale}.qm').resolve())
print(f"Try load {locale} locale: {locale_file}")
if translator.load(locale_file):
print(f'Localization loaded: {locale}') # name, dir
else:
print("Using default translation")
app = QtWidgets.QApplication(sys.argv)
app.installTranslator(translator)
if darkdetect.isDark():
import ui.breeze_resources
darkthm = QFile(":/dark/stylesheet.qss")
darkthm.open(QFile.ReadOnly | QFile.Text)
darkthm_stream = QTextStream(darkthm)
app.setStyleSheet(darkthm_stream.readAll())
window = NtscApp()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()