-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
236 lines (197 loc) · 9.06 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import sys, os
from PySide6.QtGui import QAction, QCursor, QPainter, QColor, QMovie, QIcon
from PySide6.QtWidgets import QApplication, QMainWindow, QCheckBox, QVBoxLayout, QWidget, QLabel, QHBoxLayout, \
QGridLayout
from PySide6.QtCore import Qt, QPropertyAnimation, QPoint
from widgets.video_widget import VideoWidget
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
class IndicatorLabel(QLabel):
def __init__(self, color, parent=None):
super().__init__(parent)
self.color = color
self.setFixedSize(18, 18) # 원의 크기 조절
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setBrush(QColor(self.color))
painter.setPen(QColor(self.color))
painter.drawEllipse(0, 0, self.width(), self.height())
class Switch(QCheckBox):
def __init__(self, parent=None):
super(Switch, self).__init__(parent)
self.setFixedSize(60, 30)
self.setCursor(QCursor(Qt.PointingHandCursor))
self.setStyleSheet('''
QCheckBox {
background-color: #ccc;
border-radius: 15px;
border: 2px solid #ccc;
width: 60px;
height: 30px;
padding: 0;
margin: 0;
}
QCheckBox::indicator {
width: 26px;
height: 26px;
border-radius: 13px;
background-color: white;
position: absolute;
left: 1px;
top: 1px;
}
QCheckBox::indicator:checked {
left: 32px;
}
QCheckBox:checked {
background-color: #66bb6a;
border: 2px solid #66bb6a;
}
''')
self.animation = QPropertyAnimation(self, b"pos")
self.animation.setDuration(300)
self.stateChanged.connect(self.start_animation)
def start_animation(self, state):
if state == Qt.Checked:
self.animation.setEndValue(self.mapToParent(self.rect().topLeft() + QPoint(32, 0)))
else:
self.animation.setEndValue(self.mapToParent(self.rect().topLeft() + QPoint(1, 0)))
self.animation.start()
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setFixedSize(690, 800)
self.setWindowTitle("Hipermodal")
self.setWindowIcon(QIcon(resource_path('icon.ico')))
# Status Bar
self.statusBar().showMessage('프로그램 실행 완료', 3000)
self.video_widget = VideoWidget()
self.voice_recognition = self.video_widget.voice_recognition
self.voice_recognition.listening_signal.connect(self.on_listening)
self.menuBar().setNativeMenuBar(False) # macOS 에서만
filemenu = self.menuBar().addMenu("&File")
exitAction = QAction('Exit', self)
exitAction.setShortcut('Ctrl+W')
exitAction.setStatusTip('프로그램 종료')
exitAction.triggered.connect(QApplication.quit)
filemenu.addAction(exitAction)
# 레이아웃을 위한 위젯 생성
layout_widget = QWidget()
layout = QHBoxLayout(layout_widget)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(5)
# 카메라, 마이크 인디케이터 설정
self.camera_indicator = IndicatorLabel('green')
self.camera_indicator.setToolTip('카메라로 제스처를 감지중입니다.')
self.mic_indicator = IndicatorLabel('orange')
self.mic_indicator.setToolTip('마이크로 음성을 감지중입니다.')
# 로딩 애니메이션 설정
self.loading_label = QLabel(self)
self.loading_movie = QMovie(resource_path('loading.gif'))
self.loading_label.setMovie(self.loading_movie)
self.loading_label.setFixedSize(22, 22)
# 레이아웃에 인디케이터 추가
layout.addWidget(self.camera_indicator)
layout.addWidget(self.mic_indicator)
layout.addWidget(self.loading_label)
# 상태 표시줄에 레이아웃 위젯 추가
self.statusBar().addPermanentWidget(layout_widget)
# 기본적으로 인디케이터 숨김
self.camera_indicator.hide()
self.mic_indicator.hide()
self.loading_label.hide()
# QLabel 스타일 설정
label_style = """
QLabel {
font-size: 18px; /* 글씨 크기 설정 */
color: #333; /* 글씨 색상 설정 */
}
"""
# 제스처 모드 스위치와 라벨
self.toggle_layout = QGridLayout()
self.gesture_label = QLabel(" 제스처 모드")
self.gesture_label.setStyleSheet(label_style)
self.gesture_toggle_switch = Switch()
self.gesture_toggle_switch.stateChanged.connect(self.toggle_gesture_mode)
self.toggle_layout.addWidget(self.gesture_label, 4, 1)
self.toggle_layout.addWidget(self.gesture_toggle_switch, 4, 2)
self.speech_label = QLabel(" 음성 인식")
self.speech_label.setStyleSheet(label_style)
self.speech_toggle_switch = Switch()
self.speech_toggle_switch.setEnabled(False)
self.speech_toggle_switch.stateChanged.connect(self.toggle_speech_mode)
self.toggle_layout.addWidget(self.speech_label, 4, 4)
self.toggle_layout.addWidget(self.speech_toggle_switch, 4, 5)
self.layout = QVBoxLayout()
self.layout.addWidget(self.video_widget)
self.layout.addLayout(self.toggle_layout)
self.container = QWidget()
self.container.setLayout(self.layout)
self.setCentralWidget(self.container)
# 배경 색상 설정
self.setStyleSheet("background-color: #ffffff;") # 여기에 원하는 색상을 입력하세요.
# 제스처 모드 단축키
self.gesture_shortcut = QAction('Toggle Gesture Mode', self)
self.gesture_shortcut.setShortcut('Ctrl+C')
self.gesture_shortcut.setStatusTip('Toggle Gesture Mode')
self.gesture_shortcut.triggered.connect(self.toggle_gesture_mode_shortcut)
self.addAction(self.gesture_shortcut)
filemenu.addAction(self.gesture_shortcut)
# 음성 인식 단축키
self.speech_shortcut = QAction('Toggle Speech Mode', self)
self.speech_shortcut.setShortcut('Ctrl+V')
self.speech_shortcut.setStatusTip('Toggle Speech Mode')
self.speech_shortcut.triggered.connect(self.toggle_speech_mode_shortcut)
self.addAction(self.speech_shortcut)
filemenu.addAction(self.speech_shortcut)
def toggle_gesture_mode(self, state):
if self.gesture_toggle_switch.isChecked():
self.video_widget.gesture_thread.start_gesture_recognition()
self.speech_toggle_switch.setEnabled(True)
self.statusBar().showMessage('제스처 모드가 활성화되었습니다.', 3000)
self.camera_indicator.setVisible(True)
else:
self.video_widget.gesture_thread.stop_gesture_recognition()
self.video_widget.voice_recognition_stop()
self.speech_toggle_switch.setEnabled(False)
self.speech_toggle_switch.setChecked(False)
self.statusBar().showMessage('제스처 모드가 비활성화되었습니다.', 3000)
self.camera_indicator.setVisible(False)
self.mic_indicator.setVisible(False)
def toggle_speech_mode(self, state):
if self.speech_toggle_switch.isChecked():
self.video_widget.voice_recognition_start()
self.loading_label.show()
self.loading_movie.start()
self.statusBar().showMessage('음성 인식이 완전히 활성화될 때까지 잠시만 기다려주세요.', 3000)
else:
self.video_widget.voice_recognition_stop()
self.loading_movie.stop()
self.loading_label.hide()
self.mic_indicator.setVisible(False)
self.statusBar().showMessage('음성 인식이 비활성화되었습니다.', 3000)
def toggle_gesture_mode_shortcut(self):
self.gesture_toggle_switch.setChecked(not self.gesture_toggle_switch.isChecked())
def toggle_speech_mode_shortcut(self):
if self.speech_toggle_switch.isEnabled():
self.speech_toggle_switch.setChecked(not self.speech_toggle_switch.isChecked())
def on_listening(self):
# Listening 신호를 수신했을 때 수행할 작업
self.statusBar().showMessage('음성 인식이 활성화되었습니다.', 3000)
self.loading_movie.stop()
self.loading_label.hide()
self.mic_indicator.setVisible(True)
def closeEvent(self, event):
self.statusBar().showMessage('프로그램 종료 중... 잠시만 기다려주세요.')
self.video_widget.closeEvent(event)
event.accept()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())