Statistics
| Branch: | Tag: | Revision:

hlrc / client / python / hlrc_client / hlrc_test_gui.py @ 2126781b

History | View | Annotate | Download (7.938 KB)

1 0c286af0 Simon Schulz
#!/usr/bin/python
2 f8fa1217 Simon Schulz
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 0c286af0 Simon Schulz
import sys
36
import os.path
37 f8fa1217 Simon Schulz
38 0c286af0 Simon Schulz
from PyQt4 import QtGui, QtCore
39
from PyQt4.QtCore import SIGNAL
40
41 f8fa1217 Simon Schulz
class HLRCExample(QtGui.QWidget):
42 70c54617 Simon Schulz
43 3877047d Simon Schulz
    def __init__(self, scope, mw):
44 70c54617 Simon Schulz
        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()