-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
105 lines (88 loc) · 2.78 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
101
102
103
104
105
# -*- coding: utf-8 -*-
"""
Main
author: modorigoon
since: 0.1.0
"""
import sys
import atexit
from common.logger import log
from common.config import get_config, get_opts
from PyQt5.QtWidgets import *
from lib.window import Window
from application import Application
class MainGui:
def __init__(self):
self._API_CONFIG = get_config('1q_api')
self._window = Window(get_config('node_name'))
self._app = Application(self._window)
def exec(self, start=False):
""" execution
:return: void
"""
try:
self._window.set_real_name(self._API_CONFIG['target']['real_name'])
self._window.set_symbol_name(self._API_CONFIG['target']['symbol'])
self._window.append_log('[run] Initialize main application.')
self._window.set_quit_button_listener(self.quit)
self._window.set_run_button_listener(self.run)
self._window.open_window()
if start is True:
self.run()
except Exception as _e:
self._window.append_log('[exec] ERROR: {}'.format(str(_e)))
def stop(self):
""" stop
:return: void
"""
try:
self._window.append_log('[stop] service stopping..')
self._window.set_run_button_text('STOPPING..')
self._window.delete_run_button_listener()
self._app.disconnect()
self._window.append_log('[stop] service stop complete.')
except Exception as _e:
self._window.append_log('[stop] ERROR: {}'.format(str(_e)))
finally:
self._window.set_run_button_text('START')
self._window.set_run_button_listener(self.run)
def quit(self):
""" quit application
:return: void
"""
self.stop()
self._window.close_window()
sys.exit()
def run(self):
""" start
:return: void
"""
try:
self._window.set_run_button_text('STARTING..')
self._window.delete_run_button_listener()
self._app.connect()
self._window.set_run_button_text('STOP')
self._window.set_run_button_listener(self.stop)
self._app.listen_real()
except Exception as _e:
self._window.append_log('[run] ERROR: {}'.format(str(_e)))
self.stop()
app = QApplication(sys.argv)
opts = get_opts()
auto_start = False
if 's' in opts:
auto_start = True
main_gui = MainGui()
def main():
try:
main_gui.exec(auto_start)
sys.exit(app.exec_())
except Exception as _e:
log.error(str(_e))
def at_exit():
if main_gui is not None:
log.info('[exit] quit application.')
main_gui.quit()
atexit.register(at_exit)
if __name__ == "__main__":
main()