forked from qg0/EliteQuant_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive_engine.py
More file actions
81 lines (68 loc) · 2.49 KB
/
live_engine.py
File metadata and controls
81 lines (68 loc) · 2.49 KB
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
#!/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
try:
from server.EliteQuant import tradingengine_ # windows
except ImportError:
from server.libelitequant import tradingengine_ # linux
# 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, '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, '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, 'language/en/live_text.yaml')
font = QtGui.QFont('Microsoft Sans Serif', 10)
if config_client['language'] == 'cn':
config_file = os.path.join(path, '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_())
def start_server():
print('Running python server.')
server = tradingengine_()
server.run()
def stop_server():
global server_process
kill(server_process.pid, SIGINT)
server_process = None
if __name__ == "__main__":
server_process = Process(target=start_server)
server_process.start()
atexit.register(stop_server)
main()