Revision 70c54617 client/python/hlrc_client/hlrc_test_gui.py
| client/python/hlrc_client/hlrc_test_gui.py | ||
|---|---|---|
| 39 | 39 |
from PyQt4.QtCore import SIGNAL |
| 40 | 40 |
|
| 41 | 41 |
class HLRCExample(QtGui.QWidget): |
| 42 |
|
|
| 42 |
|
|
| 43 | 43 |
def __init__(self, scope, mw): |
| 44 |
super(HLRCExample, self).__init__() |
|
| 45 |
|
|
| 46 |
self.scope = scope |
|
| 47 |
self.mw = mw |
|
| 48 |
self.initUI() |
|
| 49 |
self.robot_controller = RobotController(self.mw, self.scope, logging.DEBUG) |
|
| 50 |
|
|
| 51 |
def initUtteranceUI(self): |
|
| 52 |
groupBox = QtGui.QGroupBox("utterances")
|
|
| 53 |
|
|
| 54 |
hello = QtGui.QPushButton("hello...")
|
|
| 55 |
hello.clicked.connect(self.utterance_button_clicked) |
|
| 56 |
|
|
| 57 |
count = QtGui.QPushButton("12345...")
|
|
| 58 |
count.clicked.connect(self.utterance_button_clicked) |
|
| 59 |
|
|
| 60 |
|
|
| 61 |
vbox = QtGui.QVBoxLayout() |
|
| 62 |
vbox.addWidget(hello) |
|
| 63 |
vbox.addWidget(count) |
|
| 64 |
vbox.addStretch(1) |
|
| 65 |
groupBox.setLayout(vbox) |
|
| 66 |
|
|
| 67 |
return groupBox |
|
| 68 |
|
|
| 69 |
def initSpinbox(self, _min, _max, _init, double): |
|
| 70 |
if (double): |
|
| 71 |
s = QtGui.QDoubleSpinBox() |
|
| 72 |
else: |
|
| 73 |
s = QtGui.QSpinBox() |
|
| 74 |
|
|
| 75 |
s.setMinimum(_min) |
|
| 76 |
s.setMaximum(_max) |
|
| 77 |
s.setValue(_init) |
|
| 78 |
return s |
|
| 79 |
|
|
| 80 |
def initPushButton(self, base_layout, text, action): |
|
| 81 |
button = QtGui.QPushButton(text) |
|
| 82 |
button.clicked.connect(action) |
|
| 83 |
base_layout.addWidget(button) |
|
| 84 |
|
|
| 85 |
def initEmotionUI(self): |
|
| 86 |
vbox = QtGui.QVBoxLayout() |
|
| 87 |
self.duration_spinbox = self.initSpinbox(100, 10000, 1000, 0) |
|
| 88 |
vbox.addWidget(self.duration_spinbox) |
|
| 89 |
|
|
| 90 |
#self.duration_spinbox = self.initSpinbox(50, 10000, 1000, 0) |
|
| 91 |
self.initPushButton(vbox, "neutral", self.emotion_button_clicked) |
|
| 92 |
self.initPushButton(vbox, "surprise", self.emotion_button_clicked) |
|
| 93 |
self.initPushButton(vbox, "angry", self.emotion_button_clicked) |
|
| 94 |
self.initPushButton(vbox, "happy", self.emotion_button_clicked) |
|
| 95 |
self.initPushButton(vbox, "sad", self.emotion_button_clicked) |
|
| 96 |
self.initPushButton(vbox, "fear", self.emotion_button_clicked) |
|
| 97 |
vbox.addStretch(1) |
|
| 98 |
|
|
| 99 |
groupBox = QtGui.QGroupBox("emotion")
|
|
| 100 |
groupBox.setLayout(vbox) |
|
| 101 |
return groupBox |
|
| 102 |
|
|
| 103 |
def initAnimationButton(self, base_layout, name): |
|
| 104 |
b = QtGui.QPushButton(name) |
|
| 105 |
b.clicked.connect(self.animation_button_clicked) |
|
| 106 |
base_layout.addWidget(b) |
|
| 107 |
|
|
| 108 |
def initAnimUI(self): |
|
| 109 |
groupBox = QtGui.QGroupBox("animations")
|
|
| 110 |
|
|
| 111 |
#options |
|
| 112 |
options = QtGui.QHBoxLayout() |
|
| 113 |
vbox_r = QtGui.QVBoxLayout() |
|
| 114 |
vbox_r.addWidget(QtGui.QLabel("repetitions"))
|
|
| 115 |
self.repetitions_spinbox = self.initSpinbox(1,10,1,0) |
|
| 116 |
vbox_r.addWidget(self.repetitions_spinbox) |
|
| 117 |
|
|
| 118 |
vbox_d = QtGui.QVBoxLayout() |
|
| 119 |
vbox_d.addWidget(QtGui.QLabel("duration/ms (each)"))
|
|
| 120 |
self.duration_each_spinbox = self.initSpinbox(50,10000,1000,0) |
|
| 121 |
vbox_d.addWidget(self.duration_each_spinbox) |
|
| 122 |
|
|
| 123 |
vbox_s = QtGui.QVBoxLayout() |
|
| 124 |
vbox_s.addWidget(QtGui.QLabel("scale"))
|
|
| 125 |
self.scale_spinbox = self.initSpinbox(0.1, 5.0, 1.0, 1) |
|
| 126 |
vbox_s.addWidget(self.scale_spinbox) |
|
| 127 |
|
|
| 128 |
|
|
| 129 |
options.addLayout(vbox_r) |
|
| 130 |
options.addLayout(vbox_d) |
|
| 131 |
options.addLayout(vbox_s) |
|
| 132 |
|
|
| 133 |
#buttons |
|
| 134 |
vbox = QtGui.QVBoxLayout() |
|
| 135 |
vbox.addLayout(options) |
|
| 136 |
self.initAnimationButton(vbox, "head shake") |
|
| 137 |
self.initAnimationButton(vbox, "head nod") |
|
| 138 |
self.initAnimationButton(vbox, "eyeblink left") |
|
| 139 |
self.initAnimationButton(vbox, "eyeblink right") |
|
| 140 |
self.initAnimationButton(vbox, "eyeblink both") |
|
| 141 |
self.initAnimationButton(vbox, "eyebrows raise") |
|
| 142 |
self.initAnimationButton(vbox, "eyebrows lower") |
|
| 143 |
vbox.addStretch(1) |
|
| 144 |
groupBox.setLayout(vbox) |
|
| 145 |
|
|
| 146 |
return groupBox |
|
| 147 |
|
|
| 148 |
def initUI(self): |
|
| 149 |
vbox = QtGui.QVBoxLayout() |
|
| 150 |
|
|
| 151 |
hboxl = QtGui.QHBoxLayout() |
|
| 152 |
hboxl.addWidget(QtGui.QLabel("base scope: "))
|
|
| 153 |
hboxl.addWidget(QtGui.QLabel(self.scope)) |
|
| 154 |
vbox.addLayout(hboxl) |
|
| 155 |
|
|
| 156 |
hbox = QtGui.QHBoxLayout() |
|
| 157 |
vbox.addLayout(hbox) |
|
| 158 |
|
|
| 159 |
#emotion |
|
| 160 |
hbox.addWidget(self.initEmotionUI()) |
|
| 161 |
|
|
| 162 |
#utterance: |
|
| 163 |
hbox.addWidget(self.initUtteranceUI()) |
|
| 164 |
|
|
| 165 |
#animations: |
|
| 166 |
hbox.addWidget(self.initAnimUI()) |
|
| 167 |
|
|
| 168 |
self.setLayout(vbox) |
|
| 169 |
#sld.valueChanged.connect(lcd.display) |
|
| 170 |
|
|
| 171 |
self.setGeometry(400, 100, 250, 150) |
|
| 172 |
self.setWindowTitle("HLRC Server test GUI - %s" % self.scope)
|
|
| 173 |
self.show() |
|
| 174 |
|
|
| 175 |
def utterance_button_clicked(self): |
|
| 176 |
button = self.sender().text() |
|
| 177 |
|
|
| 178 |
|
|
| 179 |
if (button == "12345..."): |
|
| 180 |
self.robot_controller.set_speak("1 2 3 4 5 6 7 8 9 10", False)
|
|
| 181 |
elif (button == "hello..."): |
|
| 182 |
self.robot_controller.set_speak("Hello my name is flobi. How can i help you?", False)
|
|
| 183 |
else: |
|
| 184 |
self.robot_controller.set_speak("invalid button name", False)
|
|
| 185 |
print "invalid button '%s'" % (button) |
|
| 186 |
|
|
| 187 |
def emotion_button_clicked(self): |
|
| 188 |
button = self.sender().text() |
|
| 189 |
|
|
| 190 |
re = RobotEmotion() |
|
| 191 |
re.time_ms = self.duration_spinbox.value() |
|
| 192 |
|
|
| 193 |
if (button == "angry"): |
|
| 194 |
re.value = RobotEmotion.ANGRY |
|
| 195 |
elif (button == "neutral"): |
|
| 196 |
re.value = RobotEmotion.NEUTRAL |
|
| 197 |
elif (button == "happy"): |
|
| 198 |
re.value = RobotEmotion.HAPPY |
|
| 199 |
elif (button == "sad"): |
|
| 200 |
re.value = RobotEmotion.SAD |
|
| 201 |
elif (button == "surprise"): |
|
| 202 |
re.value = RobotEmotion.SURPRISED |
|
| 203 |
elif (button == "fear"): |
|
| 204 |
re.value = RobotEmotion.FEAR |
|
| 205 |
else: |
|
| 206 |
print "invalid emotion id '%s'" % (button) |
|
| 207 |
return |
|
| 208 |
|
|
| 209 |
self.robot_controller.set_current_emotion(re, False) |
|
| 210 |
|
|
| 211 |
def animation_button_clicked(self): |
|
| 212 |
button = self.sender().text() |
|
| 213 |
|
|
| 214 |
ra = RobotAnimation() |
|
| 215 |
ra.time_ms = self.duration_each_spinbox.value() |
|
| 216 |
ra.repetitions = self.repetitions_spinbox.value() |
|
| 217 |
ra.scale = self.scale_spinbox.value() |
|
| 218 |
|
|
| 219 |
if (button == "head nod"): |
|
| 220 |
ra.value = RobotAnimation.HEAD_NOD |
|
| 221 |
elif (button == "head shake"): |
|
| 222 |
ra.value = RobotAnimation.HEAD_SHAKE |
|
| 223 |
elif (button == "eyeblink left"): |
|
| 224 |
ra.value = RobotAnimation.EYEBLINK_L |
|
| 225 |
elif (button == "eyeblink right"): |
|
| 226 |
ra.value = RobotAnimation.EYEBLINK_R |
|
| 227 |
elif (button == "eyeblink both"): |
|
| 228 |
ra.value = RobotAnimation.EYEBLINK_BOTH |
|
| 229 |
elif (button == "eyebrows raise"): |
|
| 230 |
ra.value = RobotAnimation.EYEBROWS_RAISE |
|
| 231 |
elif (button == "eyebrows lower"): |
|
| 232 |
ra.value = RobotAnimation.EYEBROWS_LOWER |
|
| 233 |
else: |
|
| 234 |
print "invalid button '%s'" % (button) |
|
| 235 |
return |
|
| 236 |
|
|
| 237 |
self.robot_controller.set_head_animation(ra, False) |
|
| 238 |
|
|
| 239 |
def main(): |
|
| 240 |
if (len(sys.argv) != 3): |
|
| 241 |
print("usage: hlrc_test_gui.py <middleware> <scope>\n\n")
|
|
| 242 |
print("example: hlrc_test_gui.py ROS /flobi\n\n")
|
|
| 243 |
sys.exit(errno.EINVAL) |
|
| 244 |
|
|
| 245 |
scope = sys.argv[1] |
|
| 246 |
mw = sys.argv[2] |
|
| 247 |
|
|
| 248 |
app = QtGui.QApplication(sys.argv) |
|
| 249 |
ex = HLRCExample(mw, scope) |
|
| 250 |
sys.exit(app.exec_()) |
|
| 251 |
|
|
| 252 |
|
|
| 253 |
if __name__ == '__main__': |
|
| 254 |
main() |
|
| 44 |
super(HLRCExample, self).__init__() |
|
| 45 |
|
|
| 46 |
self.scope = scope |
|
| 47 |
self.mw = mw |
|
| 48 |
self.initUI() |
|
| 49 |
self.robot_controller = RobotController(self.mw, self.scope, logging.DEBUG) |
|
| 50 |
|
|
| 51 |
def initUtteranceUI(self): |
|
| 52 |
groupBox = QtGui.QGroupBox("utterances")
|
|
| 53 |
|
|
| 54 |
hello = QtGui.QPushButton("hello...")
|
|
| 55 |
hello.clicked.connect(self.utterance_button_clicked) |
|
| 56 |
|
|
| 57 |
count = QtGui.QPushButton("12345...")
|
|
| 58 |
count.clicked.connect(self.utterance_button_clicked) |
|
| 59 |
|
|
| 60 |
|
|
| 61 |
vbox = QtGui.QVBoxLayout() |
|
| 62 |
vbox.addWidget(hello) |
|
| 63 |
vbox.addWidget(count) |
|
| 64 |
vbox.addStretch(1) |
|
| 65 |
groupBox.setLayout(vbox) |
|
| 66 |
|
|
| 67 |
return groupBox |
|
| 68 |
|
|
| 69 |
def initSpinbox(self, _min, _max, _init, double): |
|
| 70 |
if (double): |
|
| 71 |
s = QtGui.QDoubleSpinBox() |
|
| 72 |
else: |
|
| 73 |
s = QtGui.QSpinBox() |
|
| 74 |
|
|
| 75 |
s.setMinimum(_min) |
|
| 76 |
s.setMaximum(_max) |
|
| 77 |
s.setValue(_init) |
|
| 78 |
return s |
|
| 79 |
|
|
| 80 |
def initPushButton(self, base_layout, text, action): |
|
| 81 |
button = QtGui.QPushButton(text) |
|
| 82 |
button.clicked.connect(action) |
|
| 83 |
base_layout.addWidget(button) |
|
| 84 |
|
|
| 85 |
def initEmotionUI(self): |
|
| 86 |
vbox = QtGui.QVBoxLayout() |
|
| 87 |
self.duration_spinbox = self.initSpinbox(100, 10000, 1000, 0) |
|
| 88 |
vbox.addWidget(self.duration_spinbox) |
|
| 89 |
|
|
| 90 |
#self.duration_spinbox = self.initSpinbox(50, 10000, 1000, 0) |
|
| 91 |
self.initPushButton(vbox, "neutral", self.emotion_button_clicked) |
|
| 92 |
self.initPushButton(vbox, "surprise", self.emotion_button_clicked) |
|
| 93 |
self.initPushButton(vbox, "angry", self.emotion_button_clicked) |
|
| 94 |
self.initPushButton(vbox, "happy", self.emotion_button_clicked) |
|
| 95 |
self.initPushButton(vbox, "sad", self.emotion_button_clicked) |
|
| 96 |
self.initPushButton(vbox, "fear", self.emotion_button_clicked) |
|
| 97 |
vbox.addStretch(1) |
|
| 98 |
|
|
| 99 |
groupBox = QtGui.QGroupBox("emotion")
|
|
| 100 |
groupBox.setLayout(vbox) |
|
| 101 |
return groupBox |
|
| 102 |
|
|
| 103 |
def initAnimationButton(self, base_layout, name): |
|
| 104 |
b = QtGui.QPushButton(name) |
|
| 105 |
b.clicked.connect(self.animation_button_clicked) |
|
| 106 |
base_layout.addWidget(b) |
|
| 107 |
|
|
| 108 |
def initAnimUI(self): |
|
| 109 |
groupBox = QtGui.QGroupBox("animations")
|
|
| 110 |
|
|
| 111 |
#options |
|
| 112 |
options = QtGui.QHBoxLayout() |
|
| 113 |
vbox_r = QtGui.QVBoxLayout() |
|
| 114 |
vbox_r.addWidget(QtGui.QLabel("repetitions"))
|
|
| 115 |
self.repetitions_spinbox = self.initSpinbox(1,10,1,0) |
|
| 116 |
vbox_r.addWidget(self.repetitions_spinbox) |
|
| 117 |
|
|
| 118 |
vbox_d = QtGui.QVBoxLayout() |
|
| 119 |
vbox_d.addWidget(QtGui.QLabel("duration/ms (each)"))
|
|
| 120 |
self.duration_each_spinbox = self.initSpinbox(50,10000,1000,0) |
|
| 121 |
vbox_d.addWidget(self.duration_each_spinbox) |
|
| 122 |
|
|
| 123 |
vbox_s = QtGui.QVBoxLayout() |
|
| 124 |
vbox_s.addWidget(QtGui.QLabel("scale"))
|
|
| 125 |
self.scale_spinbox = self.initSpinbox(0.1, 5.0, 1.0, 1) |
|
| 126 |
vbox_s.addWidget(self.scale_spinbox) |
|
| 127 |
|
|
| 128 |
|
|
| 129 |
options.addLayout(vbox_r) |
|
| 130 |
options.addLayout(vbox_d) |
|
| 131 |
options.addLayout(vbox_s) |
|
| 132 |
|
|
| 133 |
#buttons |
|
| 134 |
vbox = QtGui.QVBoxLayout() |
|
| 135 |
vbox.addLayout(options) |
|
| 136 |
self.initAnimationButton(vbox, "head shake") |
|
| 137 |
self.initAnimationButton(vbox, "head nod") |
|
| 138 |
self.initAnimationButton(vbox, "eyeblink left") |
|
| 139 |
self.initAnimationButton(vbox, "eyeblink right") |
|
| 140 |
self.initAnimationButton(vbox, "eyeblink both") |
|
| 141 |
self.initAnimationButton(vbox, "eyebrows raise") |
|
| 142 |
self.initAnimationButton(vbox, "eyebrows lower") |
|
| 143 |
vbox.addStretch(1) |
|
| 144 |
groupBox.setLayout(vbox) |
|
| 145 |
|
|
| 146 |
return groupBox |
|
| 147 |
|
|
| 148 |
def initUI(self): |
|
| 149 |
vbox = QtGui.QVBoxLayout() |
|
| 150 |
|
|
| 151 |
hboxl = QtGui.QHBoxLayout() |
|
| 152 |
hboxl.addWidget(QtGui.QLabel("base scope: "))
|
|
| 153 |
hboxl.addWidget(QtGui.QLabel(self.scope)) |
|
| 154 |
vbox.addLayout(hboxl) |
|
| 155 |
|
|
| 156 |
hbox = QtGui.QHBoxLayout() |
|
| 157 |
vbox.addLayout(hbox) |
|
| 158 |
|
|
| 159 |
#emotion |
|
| 160 |
hbox.addWidget(self.initEmotionUI()) |
|
| 161 |
|
|
| 162 |
#utterance: |
|
| 163 |
hbox.addWidget(self.initUtteranceUI()) |
|
| 164 |
|
|
| 165 |
#animations: |
|
| 166 |
hbox.addWidget(self.initAnimUI()) |
|
| 167 |
|
|
| 168 |
self.setLayout(vbox) |
|
| 169 |
#sld.valueChanged.connect(lcd.display) |
|
| 170 |
|
|
| 171 |
self.setGeometry(400, 100, 250, 150) |
|
| 172 |
self.setWindowTitle("HLRC Server test GUI - %s" % self.scope)
|
|
| 173 |
self.show() |
|
| 174 |
|
|
| 175 |
def utterance_button_clicked(self): |
|
| 176 |
button = self.sender().text() |
|
| 177 |
|
|
| 178 |
|
|
| 179 |
if (button == "12345..."): |
|
| 180 |
self.robot_controller.set_speak("1 2 3 4 5 6 7 8 9 10", False)
|
|
| 181 |
elif (button == "hello..."): |
|
| 182 |
self.robot_controller.set_speak("Hello my name is flobi. How can i help you?", False)
|
|
| 183 |
else: |
|
| 184 |
self.robot_controller.set_speak("invalid button name", False)
|
|
| 185 |
print "invalid button '%s'" % (button) |
|
| 186 |
|
|
| 187 |
def emotion_button_clicked(self): |
|
| 188 |
button = self.sender().text() |
|
| 189 |
|
|
| 190 |
re = RobotEmotion() |
|
| 191 |
re.time_ms = self.duration_spinbox.value() |
|
| 192 |
|
|
| 193 |
if (button == "angry"): |
|
| 194 |
re.value = RobotEmotion.ANGRY |
|
| 195 |
elif (button == "neutral"): |
|
| 196 |
re.value = RobotEmotion.NEUTRAL |
|
| 197 |
elif (button == "happy"): |
|
| 198 |
re.value = RobotEmotion.HAPPY |
|
| 199 |
elif (button == "sad"): |
|
| 200 |
re.value = RobotEmotion.SAD |
|
| 201 |
elif (button == "surprise"): |
|
| 202 |
re.value = RobotEmotion.SURPRISED |
|
| 203 |
elif (button == "fear"): |
|
| 204 |
re.value = RobotEmotion.FEAR |
|
| 205 |
else: |
|
| 206 |
print "invalid emotion id '%s'" % (button) |
|
| 207 |
return |
|
| 208 |
|
|
| 209 |
self.robot_controller.set_current_emotion(re, False) |
|
| 210 |
|
|
| 211 |
def animation_button_clicked(self): |
|
| 212 |
button = self.sender().text() |
|
| 213 |
|
|
| 214 |
ra = RobotAnimation() |
|
| 215 |
ra.time_ms = self.duration_each_spinbox.value() |
|
| 216 |
ra.repetitions = self.repetitions_spinbox.value() |
|
| 217 |
ra.scale = self.scale_spinbox.value() |
|
| 218 |
|
|
| 219 |
if (button == "head nod"): |
|
| 220 |
ra.value = RobotAnimation.HEAD_NOD |
|
| 221 |
elif (button == "head shake"): |
|
| 222 |
ra.value = RobotAnimation.HEAD_SHAKE |
|
| 223 |
elif (button == "eyeblink left"): |
|
| 224 |
ra.value = RobotAnimation.EYEBLINK_L |
|
| 225 |
elif (button == "eyeblink right"): |
|
| 226 |
ra.value = RobotAnimation.EYEBLINK_R |
|
| 227 |
elif (button == "eyeblink both"): |
|
| 228 |
ra.value = RobotAnimation.EYEBLINK_BOTH |
|
| 229 |
elif (button == "eyebrows raise"): |
|
| 230 |
ra.value = RobotAnimation.EYEBROWS_RAISE |
|
| 231 |
elif (button == "eyebrows lower"): |
|
| 232 |
ra.value = RobotAnimation.EYEBROWS_LOWER |
|
| 233 |
else: |
|
| 234 |
print "invalid button '%s'" % (button) |
|
| 235 |
return |
|
| 236 |
|
|
| 237 |
self.robot_controller.set_head_animation(ra, False) |
|
| 238 |
|
|
| 239 |
def main(): |
|
| 240 |
if (len(sys.argv) != 3): |
|
| 241 |
print("usage: hlrc_test_gui.py <middleware> <scope>\n\n")
|
|
| 242 |
print("example: hlrc_test_gui.py ROS /flobi\n\n")
|
|
| 243 |
sys.exit(errno.EINVAL) |
|
| 244 |
|
|
| 245 |
scope = sys.argv[1] |
|
| 246 |
mw = sys.argv[2] |
|
| 247 |
|
|
| 248 |
app = QtGui.QApplication(sys.argv) |
|
| 249 |
ex = HLRCExample(mw, scope) |
|
| 250 |
sys.exit(app.exec_()) |
|
| 251 |
|
|
| 252 |
|
|
| 253 |
if __name__ == '__main__': |
|
| 254 |
main() |
|
Also available in: Unified diff