-
Notifications
You must be signed in to change notification settings - Fork 2
/
user_window.py
137 lines (107 loc) · 4.04 KB
/
user_window.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
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap
import detector
from PyQt5.QtGui import QIcon
import time
class MyMainGUI(QDialog):
question_cnt = 0
def __init__(self, parent=None):
super().__init__(parent)
self.detect_on=QPixmap('public/detect_on.png')
self.detect_off=QPixmap('public/detect_off.png')
# 이모티콘
self.neutral=QPixmap('public/neutral.png').scaledToWidth(200)
self.question=QPixmap('public/question.png').scaledToWidth(200)
self.doubt = QPixmap('public/doubt.png').scaledToWidth(200)
self.tired=QPixmap('public/sleep.png').scaledToWidth(200)
self.left=QPixmap('public/left.png').scaledToWidth(200)
self.yes=QPixmap('public/yes.png').scaledToWidth(200)
self.no=QPixmap('public/no.png').scaledToWidth(200)
# 얼굴인식 여부
self.detectDot = QLabel()
self.detectDot.resize(10,10)
self.detectDot.setPixmap(self.detect_off)
self.detectText = QLabel('인식안됨', self)
hbox = QHBoxLayout()
hbox.addWidget(self.detectDot)
hbox.addWidget(self.detectText)
# 사용자 이모티콘
self.userEmoticon = QLabel()
self.userEmoticon.setPixmap(self.neutral)
# 질문 버튼
self.questionBtn = QPushButton(self)
self.questionBtn.setIcon(QIcon('public/question.png'))
vbox = QVBoxLayout()
vbox.addLayout(hbox)
vbox.addWidget(self.userEmoticon)
vbox.addWidget(self.questionBtn)
self.setLayout(vbox)
self.setGeometry(100, 50, 200, 300)
class Test:
def __init__(self):
name = ""
class MyMain(MyMainGUI):
add_sec_signal = pyqtSignal()
send_instance_singal = pyqtSignal("PyQt_PyObject")
def __init__(self, parent=None):
super().__init__(parent)
self.questionBtn.clicked.connect(self.btn_clicked)
# video 스레드
self.th = Worker(parent=self)
self.th.detect_changed.connect(self.detect_update) # custom signal from worker thread to main thread
self.th.state_changed.connect(self.state_update) # custom signal from worker thread to main thread
self.th.start()
self.th.working = True
self.show()
# 질문 버튼
def btn_clicked(self):
self.question_cnt = 30
self.userEmoticon.setPixmap(self.question)
@pyqtSlot(str)
def detect_update(self, msg):
# 검출 안됨
if msg == "0":
self.detectDot.setPixmap(self.detect_off)
self.detectText.setText("인식 안됨")
elif msg == "1":
self.detectDot.setPixmap(self.detect_on)
self.detectText.setText("인식 중")
@pyqtSlot(str)
def state_update(self, msg):
self.question_cnt -= 1
if self.question_cnt > 0:
return
if msg == "1":
self.userEmoticon.setPixmap(self.neutral)
elif msg == "2":
self.userEmoticon.setPixmap(self.doubt)
elif msg == "3":
self.userEmoticon.setPixmap(self.tired)
elif msg == "4":
self.userEmoticon.setPixmap(self.left)
elif msg == "5":
self.userEmoticon.setPixmap(self.yes)
elif msg == "6":
self.userEmoticon.setPixmap(self.no)
class Worker(QThread):
detect_changed = pyqtSignal(str)
state_changed = pyqtSignal(str)
def __init__(self, detect = 0,state=0, parent=None):
super().__init__()
self.main = parent
self.working = True
self.detect = detect
self.state = state
# self.main.add_sec_signal.connect(self.add_sec) # 이것도 작동함. # custom signal from main thread to worker thread
def __del__(self):
print(".... end thread.....")
self.wait()
def run(self):
md = detector.MyDetector()
md.video(self.detect, self.detect_changed, self.state, self.state_changed)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
form = MyMain()
app.exec_()