hlrc / client / python / hlrc_client / hlrc_test_gui.py @ 801b4c12
History | View | Annotate | Download (7.146 KB)
1 |
#!/usr/bin/python
|
---|---|
2 |
|
3 |
"""
|
4 |
This file is part of hlrc
|
5 |
|
6 |
Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
7 |
http://opensource.cit-ec.de/projects/hlrc
|
8 |
|
9 |
This file may be licensed under the terms of the
|
10 |
GNU General Public License Version 3 (the ``GPL''),
|
11 |
or (at your option) any later version.
|
12 |
|
13 |
Software distributed under the License is distributed
|
14 |
on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
15 |
express or implied. See the GPL for the specific language
|
16 |
governing rights and limitations.
|
17 |
|
18 |
You should have received a copy of the GPL along with this
|
19 |
program. If not, go to http://www.gnu.org/licenses/gpl.html
|
20 |
or write to the Free Software Foundation, Inc.,
|
21 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
22 |
|
23 |
The development of this software was supported by the
|
24 |
Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
25 |
The Excellence Cluster EXC 277 is a grant of the Deutsche
|
26 |
Forschungsgemeinschaft (DFG) in the context of the German
|
27 |
Excellence Initiative.
|
28 |
"""
|
29 |
|
30 |
|
31 |
import logging |
32 |
from hlrc_client import * |
33 |
import time |
34 |
import errno |
35 |
import sys |
36 |
import os.path |
37 |
|
38 |
from PyQt4 import QtGui, QtCore |
39 |
from PyQt4.QtCore import SIGNAL |
40 |
|
41 |
#from hlrc_speak_utterance import hlrc_utterance
|
42 |
#from hlrc_play_animation import hlrc_animation
|
43 |
#from hlrc_set_emotion import hlrc_emotion
|
44 |
|
45 |
class HLRCExample(QtGui.QWidget): |
46 |
|
47 |
def __init__(self, scope, mw): |
48 |
super(HLRCExample, self).__init__() |
49 |
|
50 |
self.scope = scope
|
51 |
self.mw = mw
|
52 |
self.initUI()
|
53 |
self.robot_controller = RobotController(self.mw, self.scope, logging.DEBUG) |
54 |
|
55 |
def initUtteranceUI(self): |
56 |
groupBox = QtGui.QGroupBox("utterances")
|
57 |
|
58 |
hello = QtGui.QPushButton("hello...")
|
59 |
hello.clicked.connect(self.utterance_button_clicked)
|
60 |
|
61 |
count = QtGui.QPushButton("12345...")
|
62 |
count.clicked.connect(self.utterance_button_clicked)
|
63 |
|
64 |
|
65 |
vbox = QtGui.QVBoxLayout() |
66 |
vbox.addWidget(hello) |
67 |
vbox.addWidget(count) |
68 |
vbox.addStretch(1)
|
69 |
groupBox.setLayout(vbox) |
70 |
|
71 |
return groupBox
|
72 |
|
73 |
def initSpinbox(self, _min, _max, _init, double): |
74 |
if (double):
|
75 |
s = QtGui.QDoubleSpinBox() |
76 |
else:
|
77 |
s = QtGui.QSpinBox() |
78 |
|
79 |
s.setMinimum(_min) |
80 |
s.setMaximum(_max) |
81 |
s.setValue(_init) |
82 |
return s
|
83 |
|
84 |
def initPushButton(self, base_layout, text, action): |
85 |
button = QtGui.QPushButton(text) |
86 |
button.clicked.connect(action) |
87 |
base_layout.addWidget(button) |
88 |
|
89 |
def initEmotionUI(self): |
90 |
vbox = QtGui.QVBoxLayout() |
91 |
self.duration_spinbox = self.initSpinbox(100, 10000, 1000, 0) |
92 |
vbox.addWidget(self.duration_spinbox)
|
93 |
|
94 |
self.duration_spinbox = self.initSpinbox(100, 10000, 1000, 0) |
95 |
self.initPushButton(vbox, "neutral", self.emotion_button_clicked) |
96 |
self.initPushButton(vbox, "surprise", self.emotion_button_clicked) |
97 |
self.initPushButton(vbox, "angry", self.emotion_button_clicked) |
98 |
self.initPushButton(vbox, "happy", self.emotion_button_clicked) |
99 |
self.initPushButton(vbox, "sad", self.emotion_button_clicked) |
100 |
self.initPushButton(vbox, "fear", self.emotion_button_clicked) |
101 |
vbox.addStretch(1)
|
102 |
|
103 |
groupBox = QtGui.QGroupBox("emotion")
|
104 |
groupBox.setLayout(vbox) |
105 |
return groupBox
|
106 |
|
107 |
def initAnimationButton(self, base_layout, name): |
108 |
b = QtGui.QPushButton(name) |
109 |
b.clicked.connect(self.animation_button_clicked)
|
110 |
base_layout.addWidget(b) |
111 |
|
112 |
def initAnimUI(self): |
113 |
groupBox = QtGui.QGroupBox("animations")
|
114 |
|
115 |
#options
|
116 |
options = QtGui.QHBoxLayout() |
117 |
vbox_r = QtGui.QVBoxLayout() |
118 |
vbox_r.addWidget(QtGui.QLabel("repetitions"))
|
119 |
self.repetitions_spinbox = self.initSpinbox(1,10,1,0) |
120 |
vbox_r.addWidget(self.repetitions_spinbox)
|
121 |
|
122 |
vbox_d = QtGui.QVBoxLayout() |
123 |
vbox_d.addWidget(QtGui.QLabel("duration/ms (each)"))
|
124 |
self.duration_each_spinbox = self.initSpinbox(100,10000,1000,0) |
125 |
vbox_d.addWidget(self.duration_each_spinbox)
|
126 |
|
127 |
vbox_s = QtGui.QVBoxLayout() |
128 |
vbox_s.addWidget(QtGui.QLabel("scale"))
|
129 |
self.scale_spinbox = self.initSpinbox(0.1, 5.0, 1.0, 1) |
130 |
vbox_s.addWidget(self.scale_spinbox)
|
131 |
|
132 |
|
133 |
options.addLayout(vbox_r) |
134 |
options.addLayout(vbox_d) |
135 |
options.addLayout(vbox_s) |
136 |
|
137 |
#buttons
|
138 |
vbox = QtGui.QVBoxLayout() |
139 |
vbox.addLayout(options) |
140 |
self.initAnimationButton(vbox, "head shake") |
141 |
self.initAnimationButton(vbox, "head nod") |
142 |
self.initAnimationButton(vbox, "eyeblink left") |
143 |
self.initAnimationButton(vbox, "eyeblink right") |
144 |
self.initAnimationButton(vbox, "eyeblink both") |
145 |
self.initAnimationButton(vbox, "eyebrows raise") |
146 |
self.initAnimationButton(vbox, "eyebrows lower") |
147 |
vbox.addStretch(1)
|
148 |
groupBox.setLayout(vbox) |
149 |
|
150 |
return groupBox
|
151 |
|
152 |
def initUI(self): |
153 |
vbox = QtGui.QVBoxLayout() |
154 |
|
155 |
hboxl = QtGui.QHBoxLayout() |
156 |
hboxl.addWidget(QtGui.QLabel("base scope: "))
|
157 |
hboxl.addWidget(QtGui.QLabel(self.scope))
|
158 |
vbox.addLayout(hboxl) |
159 |
|
160 |
hbox = QtGui.QHBoxLayout() |
161 |
vbox.addLayout(hbox) |
162 |
|
163 |
#emotion
|
164 |
hbox.addWidget(self.initEmotionUI())
|
165 |
|
166 |
#utterance:
|
167 |
hbox.addWidget(self.initUtteranceUI())
|
168 |
|
169 |
#animations:
|
170 |
hbox.addWidget(self.initAnimUI())
|
171 |
|
172 |
self.setLayout(vbox)
|
173 |
#sld.valueChanged.connect(lcd.display)
|
174 |
|
175 |
self.setGeometry(400, 100, 250, 150) |
176 |
self.setWindowTitle("HLRC Server test GUI - %s" % self.scope) |
177 |
self.show()
|
178 |
|
179 |
def utterance_button_clicked(self): |
180 |
button = self.sender().text()
|
181 |
|
182 |
|
183 |
if (button == "12345..."): |
184 |
self.robot_controller.set_speak("1 2 3 4 5 6 7 8 9 10", False) |
185 |
elif (button == "hello..."): |
186 |
self.robot_controller.set_speak("Hello my name is flobi. How can i help you?", False) |
187 |
else:
|
188 |
self.robot_controller.set_speak("invalid button name", False) |
189 |
print "invalid button '%s'" % (button) |
190 |
|
191 |
def emotion_button_clicked(self): |
192 |
button = self.sender().text()
|
193 |
|
194 |
re = RobotEmotion() |
195 |
re.time_ms = self.duration_spinbox.value()
|
196 |
|
197 |
if (button == "angry"): |
198 |
re.value = RobotEmotion.ANGRY |
199 |
elif (button == "neutral"): |
200 |
re.value = RobotEmotion.NEUTRAL |
201 |
elif (button == "happy"): |
202 |
re.value = RobotEmotion.HAPPY |
203 |
elif (button == "sad"): |
204 |
re.value = RobotEmotion.SAD |
205 |
elif (button == "surprise"): |
206 |
re.value = RobotEmotion.SURPRISED |
207 |
elif (button == "fear"): |
208 |
re.value = RobotEmotion.FEAR |
209 |
else:
|
210 |
print "invalid emotion id '%s'" % (button) |
211 |
return
|
212 |
|
213 |
self.robot_controller.set_current_emotion(re, False) |
214 |
|
215 |
def animation_button_clicked(self): |
216 |
button = self.sender().text()
|
217 |
|
218 |
ra = RobotAnimation() |
219 |
ra.time_ms = self.duration_each_spinbox.value()
|
220 |
ra.repetitions = self.repetitions_spinbox.value()
|
221 |
ra.scale = self.scale_spinbox.value()
|
222 |
|
223 |
if (button == "head nod"): |
224 |
ra.value = RobotAnimation.HEAD_NOD |
225 |
elif (button == "head shake"): |
226 |
ra.value = RobotAnimation.HEAD_SHAKE |
227 |
elif (button == "eyeblink left"): |
228 |
ra.value = RobotAnimation.EYEBLINK_L |
229 |
elif (button == "eyeblink right"): |
230 |
ra.value = RobotAnimation.EYEBLINK_R |
231 |
elif (button == "eyeblink both"): |
232 |
ra.value = RobotAnimation.EYEBLINK_BOTH |
233 |
elif (button == "eyebrows raise"): |
234 |
ra.value = RobotAnimation.EYEBROWS_RAISE |
235 |
elif (button == "eyebrows lower"): |
236 |
ra.value = RobotAnimation.EYEBROWS_LOWER |
237 |
else:
|
238 |
print "invalid button '%s'" % (button) |
239 |
return
|
240 |
|
241 |
self.robot_controller.set_head_animation(ra, False) |
242 |
|
243 |
def main(): |
244 |
if (len(sys.argv) != 3): |
245 |
print("usage: hlrc_test_gui.py <middleware> <scope>\n\n")
|
246 |
print("example: hlrc_test_gui.py ROS /flobi\n\n")
|
247 |
sys.exit(errno.EINVAL) |
248 |
|
249 |
scope = sys.argv[1]
|
250 |
mw = sys.argv[2]
|
251 |
|
252 |
app = QtGui.QApplication(sys.argv) |
253 |
ex = HLRCExample(mw, scope) |
254 |
sys.exit(app.exec_()) |
255 |
|
256 |
|
257 |
if __name__ == '__main__': |
258 |
main() |