-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainEntry.py
159 lines (143 loc) · 5.92 KB
/
mainEntry.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import sys
from datetime import datetime
import cv2
import time
from PyQt5 import QtWidgets
from PyQt5.QtGui import QImage, QPixmap
from Demo import Ui_MainWindow, identifier
"""""""""""""""""""""""""""""""""""""""""""""""""""
|identifier:3a879f86-dfde-45b0-90c4-73e14fd77fe8 |
"""""""""""""""""""""""""""""""""""""""""""""""""""
assert(identifier == '3a879f86-dfde-45b0-90c4-73e14fd77fe8')
class mywindow(QtWidgets.QMainWindow, Ui_MainWindow): # 这个地方要注意Ui_MainWindow
def __init__(self):
super(mywindow, self).__init__()
self.setupUi(self)
frame = cv2.imread("testdata/victory.jpeg")
for i in ["main_demo", "sub_demo1", "sub_demo2"]:
self.set_image(frame, i)
del frame
self.feedback_message_box = []
self.alarm_location_message_box = []
self.set_text("feedback", "intializing...")
self.record_state = False # 0:开始 1:停止
self.btn1.setText("开始录制")
self.btn2.setText("备用")
self.btn3.setText("备用")
self.btn4.setText("备用")
# 。。。加自己的函数等
def btn1_on_clicked(self):
"""
video recording
:return: True or False
"""
self.record_state = not self.record_state
if not self.record_state:
self.btn1.setText("开始录制")
save_address = ""
self.set_text("feedback", "录制已保存于{0}".format(save_address))
else:
self.btn1.setText("停止录制")
self.set_text("feedback", "录制已开始于{0}".format(datetime.fromtimestamp(time.time()).strftime('%H:%M:%S')))
def btn2_on_clicked(self):
print("btn2")
def btn3_on_clicked(self):
print("btn3")
def btn4_on_clicked(self):
print("btn4")
def set_image(self, frame, position=""):
"""
:param frame: cv form
:param position:
:return:
"""
assert (position in ["main_demo", "sub_demo1", "sub_demo2"])
if position == "main_demo":
width = self.main_demo.width()
height = self.main_demo.height()
elif position == "sub_demo1":
width = self.sub_demo1.width()
height = self.sub_demo1.height()
elif position == "sub_demo2":
width = self.sub_demo2.width()
height = self.sub_demo2.height()
frame = cv2.resize(frame, (int(width), int(height)))
if frame.ndim == 3:
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
elif frame.ndim == 2:
rgb = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
else:
return False
temp_image = QImage(rgb.flatten(), width, height, QImage.Format_RGB888)
#temp_image = QImage(rgb.flatten(), width*2, height*2, QImage.Format_RGB888)
temp_pixmap = QPixmap.fromImage(temp_image)
if position == "main_demo":
self.main_demo.setPixmap(temp_pixmap)
self.main_demo.setScaledContents(True)
elif position == "sub_demo1":
self.sub_demo1.setPixmap(temp_pixmap)
self.sub_demo1.setScaledContents(True)
elif position == "sub_demo2":
self.sub_demo2.setPixmap(temp_pixmap)
self.sub_demo2.setScaledContents(True)
#self.pictureLabel.setPixmap(temp_pixmap)
return True
def set_text(self, position: str, message=""):
"""
if you want a blank line please use set_text(position[, ""]) explicitly, do not hide it in message in the
form of "\n\n"
:param position: must be one of the followings: "feedback", "message_box", "alarm_location", "small_space"
:param message: Either a single string or a compound string splited by '\n' is accepted.
:return:
True if operation succeeded.
"""
if position == "message_box":
self.message_box.setText(message)
return True
if '\n' not in message:
if len(message) > 50:
print("The message may not be fully displayed.")
if position not in ["feedback", "message_box", "alarm_location", "small_space"]:
return False
if position == "feedback":
if len(self.feedback_message_box) >= 12:
self.feedback_message_box.pop(0)
self.feedback_message_box.append(message)
message = "\n".join(self.feedback_message_box)
self.feedback.setText(message)
elif position == "alarm_location":
if len(self.alarm_location_message_box) >= 25:
self.alarm_location_message_box.pop(0)
self.alarm_location_message_box.append(message)
message = "\n".join(self.alarm_location_message_box)
self.alarm_location.setText(message)
elif position == "small_space":
self.small_space.setText(message)
return True
else:
message = message.split("\n")
if "" in message:
message.remove("")
flag = True
for s in message:
flag = flag and self.set_text(position, s)
return flag
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myshow = mywindow()
myshow.set_text("message_box", "aaa")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "bbb")
myshow.set_text("alarm_location", "ccc\n"*5)
myshow.show() # 显示
sys.exit(app.exec_())