This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
101 lines (77 loc) · 2.81 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /bin/python3
import sys, os, pathlib, platform, subprocess # noqa: E401
import logging
import ujson as json
logging.basicConfig(level=logging.DEBUG)
__dir__ = os.path.dirname(__file__)
sys.path.append(__dir__ + "/lib")
# Support wayland (github.com/tpaviot/pythonocc-core/issues/1230)
if platform.system() == 'Linux':
if os.popen('echo $XDG_SESSION_TYPE').read() == 'wayland\n':
logging.info("Wayland. Set QT_QPA_PLATFORM=xcb")
# os.system('export QT_QPA_PLATFORM=xcb')
# subprocess.call('export QT_QPA_PLATFORM=xcb', shell=True)
os.environ['QT_QPA_PLATFORM'] = 'xcb'
from PySide6.QtWidgets import QApplication
import gettext
from locale import getlocale
import share_var
import plugin
from window import MainWindow
from lib.multithread_manager import thread_manager
import cProfile
SAFE_MOD = False
# 加载配置文件
if not os.path.exists(share_var.app_path):
os.mkdir(share_var.app_path)
if not os.path.exists(os.path.join(share_var.setting_path)):
# 不存在就创建
with open(share_var.setting_path, 'w') as f:
with open(os.path.join(share_var.root_path, 'default_setting.json')) as default:
f.write(default.read())
with open(share_var.setting_path) as f:
share_var.setting = json.decode(f.read())
# 设置国际化
lang_domain = 'default'
# lang_localedir = os.path.abspath("locale")
if share_var.setting['window']['language'] == 'system':
lang = getlocale()[0]
else:
lang = share_var.setting['window']['language']
lang_localedir = os.path.join(share_var.root_path, 'locale/')
if os.path.exists(os.path.join(lang_localedir, lang)): # 检查语言是否存在
logging.info(f"Found language:{lang}")
translation = gettext.translation(domain=lang_domain, localedir=lang_localedir, languages=[lang])
translation.install()
else:
gettext.install(None)
logging.info(f"Can't find:{lang}. Use english")
class Main():
def __init__(self):
# 创建 MainWindow
self.app = QApplication(sys.argv)
share_var.main_class = self
self.threads = thread_manager()
share_var.threads = self.threads
self.main_window = MainWindow()
share_var.main_window = self.main_window
# 加载插件
if not SAFE_MOD:
self.plugins = plugin.plugins()
self.plugins.load_core()
# self.plugins.load(self)
if __name__ == '__main__':
# Profile = cProfile.Profile()
# Profile.enable()
win = Main()
# debug
# def trace(frame, event, arg):
# print("%s, %s:%d" % (event, frame.f_code.co_filename, frame.f_lineno))
# return trace
# sys.settrace(trace)
win.main_window.show()
win.app.exec()
# Profile.disable()
# # Profile.dump_stats('profile.prof')
# import pstats
# pstats.Stats(Profile).dump_stats('profile.prof')