-
Notifications
You must be signed in to change notification settings - Fork 165
/
gui.py
70 lines (55 loc) · 2.11 KB
/
gui.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import yaml
from PyQt5 import QtCore, QtWidgets, QtGui
from source.gui.ui_main_window import MainWindow
import atexit
from signal import signal, SIGINT, SIG_DFL
from os import kill
from multiprocessing import Process
import itchat
# https://stackoverflow.com/questions/4938723/what-is-the-correct-way-to-make-my-pyqt-application-quit-when-killed-from-the-co
signal(SIGINT, SIG_DFL)
def main():
config_server = None
try:
path = os.path.abspath(os.path.dirname(__file__))
config_file = os.path.join(path, 'etc/config_server.yaml')
with open(os.path.expanduser(config_file), encoding='utf8') as fd:
config_server = yaml.load(fd)
except IOError:
print("config_server.yaml is missing")
config_client = None
try:
path = os.path.abspath(os.path.dirname(__file__))
config_file = os.path.join(path, 'etc/config_client.yaml')
with open(os.path.expanduser(config_file), encoding='utf8') as fd:
config_client = yaml.load(fd)
except IOError:
print("config_client.yaml is missing")
lang_dict = None
font = None
try:
path = os.path.abspath(os.path.dirname(__file__))
config_file = os.path.join(path, 'source/gui/language/en/live_text.yaml')
font = QtGui.QFont('Microsoft Sans Serif', 12)
if config_client['language'] == 'cn':
config_file = os.path.join(path, 'source/gui/language/cn/live_text.yaml')
font = QtGui.QFont(u'微软雅黑', 10)
with open(os.path.expanduser(config_file), encoding='utf8') as fd:
lang_dict = yaml.load(fd)
lang_dict['font'] = font
except IOError:
print("live_text.yaml is missing")
app = QtWidgets.QApplication(sys.argv)
mainWindow = MainWindow(config_server, config_client, lang_dict)
if config_client['theme'] == 'dark':
import qdarkstyle
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
mainWindow.showMaximized()
sys.exit(app.exec_())
server_process = None
if __name__ == "__main__":
main()