-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
122 lines (94 loc) · 3.84 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import cgitb
import sys
from optparse import OptionParser
import gi
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication
from ui.MainWindow import MainWindow, restart
from ui.SplashScreen import SplashScreen
from utils.CommonHelper import CommonHelper
from utils.DetectTensorRT import GstServer
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import GObject, Gst
if __name__ == "__main__":
"""program restart section"""
parser = OptionParser(usage="usage:%prog [optinos] filepath")
parser.add_option("-t", "--twice", type="int",
dest="twice", default=1, help="运行次数")
options, _ = parser.parse_args()
cgitb.enable(1, None, 5, '')
"""GStreamer remote video push"""
GObject.threads_init()
Gst.init(None)
server = GstServer()
"""PyQt Application"""
app = QApplication(sys.argv)
splashScreenStyle = CommonHelper.readQss("./qss/splashScreen.qss")
mainWindowStyle = CommonHelper.readQss("./qss/mainWindow.qss")
splashScreen = SplashScreen()
splashScreen.setStyleSheet(splashScreenStyle)
splashScreen.show()
def load_config():
"""
Load application configuration.
This is just a simulation.
This part will be implemented in the future.
:return: None
"""
pass
QTimer.singleShot(100, lambda: (splashScreen.progressBar.setValue(10),
splashScreen.progressBarStatusLabel.setText("(2/5)正在读取配置 ...")))
def load_model():
"""
Load TensorRT model.
This is just a simulation.
This part will be implemented in the future.
:return: None
"""
pass
QTimer.singleShot(200, lambda: (splashScreen.progressBar.setValue(30),
splashScreen.progressBarStatusLabel.setText("(3/5)正在加载模型 ...")))
def load_camera():
"""
Load camera.
This is just a simulation.
This part will be implemented in the future.
:return: None
"""
pass
QTimer.singleShot(300, lambda: (splashScreen.progressBar.setValue(80),
splashScreen.progressBarStatusLabel.setText("(4/5)正在打开相机 ...")))
def create_window():
"""
Create PyQt MainWindow.
This is just a simulation.
This part will be implemented in the future.
:return: None
"""
app.w = MainWindow("appconfig/appconfig.xml")
QTimer.singleShot(400, lambda: (splashScreen.progressBar.setValue(100),
splashScreen.progressBarStatusLabel.setText("(5/5)加载完毕"),
splashScreen.finish(app.w),
app.setStyleSheet(mainWindowStyle),
app.w.show()))
splashScreen.progressBarStatusLabel.setText("(1/5)正在创建界面 ...")
load_config()
load_model()
load_camera()
create_window()
"""
Finally, enter the main loop of the program.
Event processing starts from this line code,
and the main loop receives the event message and distributes it to each control of the program.
If exit() is called or the main control is destroyed, the main loop ends.
Use sys.exit () method exit ensures that the program ends completely,
In this case, the system environment variable records how the program exited.
"""
app.exec_()
"""whether the program can be restarted"""
from ui.MainWindow import canRestart
if canRestart:
restart(str(options.twice + 1))