Skip to content

Commit 7764c47

Browse files
committed
Clean up
1 parent 8414599 commit 7764c47

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

ipynao/nao_robot.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# Copyright (c) Isabel Paredes.
55
# Distributed under the terms of the Modified BSD License.
66

7-
"""
7+
'''
88
TODO: Add module docstring
9-
"""
9+
'''
1010

1111
from ipywidgets import DOMWidget, Output
1212
from traitlets import Unicode, Integer
@@ -26,12 +26,12 @@ def __init__(self, widget, service_name, output=Output()):
2626

2727
def _create_msg(self, method_name, *args, **kwargs):
2828
data = {}
29-
data["command"] = "callService"
30-
data["service"] = str(self.name)
31-
data["method"] = str(method_name)
29+
data['command'] = 'callService'
30+
data['service'] = str(self.name)
31+
data['method'] = str(method_name)
3232
# convert tuple to list to avoid empty arg values
33-
data["args"] = list(args)
34-
data["kwargs"] = kwargs
33+
data['args'] = list(args)
34+
data['kwargs'] = kwargs
3535
return data
3636

3737
def call_service(self, method_name, *args, **kwargs):
@@ -44,32 +44,30 @@ async def async_call_service(self, method_name, *args, **kwargs):
4444

4545
try:
4646
self.output.clear_output()
47-
self.output.append_stdout("Calling service... \n")
47+
self.output.append_stdout('Calling service... \n')
4848
await self.widget.wait_for_change('counter', self.output)
4949
except Exception as e:
5050
return e
51-
return self.widget.response["data"]
51+
return self.widget.response['data']
5252

5353

5454
def __getattr__(self, method_name):
55-
if (method_name[:6] == "async_"):
55+
if (method_name[:6] == 'async_'):
5656
return lambda *x, **y: self.async_call_service(method_name[6:], *x, **y)
5757
else:
5858
return lambda *x, **y: self.call_service(method_name, *x, **y)
5959

6060

6161
class NaoRobotWidget(DOMWidget):
62-
"""TODO: Add docstring here
63-
"""
6462
_model_name = Unicode('NaoRobotModel').tag(sync=True)
6563
_model_module = Unicode(module_name).tag(sync=True)
6664
_model_module_version = Unicode(module_version).tag(sync=True)
6765
_view_name = Unicode('NaoRobotView').tag(sync=True)
6866
_view_module = Unicode(module_name).tag(sync=True)
6967
_view_module_version = Unicode(module_version).tag(sync=True)
7068

71-
connected = Unicode("Disconnected").tag(sync=True)
72-
status = Unicode("Not busy").tag(sync=True)
69+
connected = Unicode('Disconnected').tag(sync=True)
70+
status = Unicode('Not busy').tag(sync=True)
7371
counter = Integer(0).tag(sync=True)
7472
response = None
7573

@@ -80,7 +78,7 @@ def __init__(self, **kwargs):
8078

8179

8280
def _handle_frontend_msg(self, model, msg, buffer):
83-
print("Received frontend msg: ", msg)
81+
print('Received frontend msg: ', msg)
8482
self.response = msg
8583

8684

@@ -91,36 +89,36 @@ def wait_for_change(widget, value_name, output=Output()):
9189
def get_value_change(change):
9290
widget.unobserve(get_value_change, names=value_name)
9391
if (widget.response != None):
94-
if (widget.response["isError"]):
95-
future.set_exception(Exception(widget.response["data"]))
96-
output.append_stderr(widget.response["data"])
92+
if (widget.response['isError']):
93+
future.set_exception(Exception(widget.response['data']))
94+
output.append_stderr(widget.response['data'])
9795
else:
98-
future.set_result(widget.response["data"])
99-
output.append_stdout(widget.response["data"])
96+
future.set_result(widget.response['data'])
97+
output.append_stdout(widget.response['data'])
10098
else:
10199
future.set_result(change)
102100

103101
widget.observe(get_value_change, names=value_name)
104102
return future
105103

106104

107-
def connect(self, ip_address="nao.local", port="80"):
105+
def connect(self, ip_address='nao.local', port='80'):
108106
data = {}
109-
data["command"] = str("connect")
110-
data["ipAddress"] = str(ip_address)
111-
data["port"] = str(port)
107+
data['command'] = str('connect')
108+
data['ipAddress'] = str(ip_address)
109+
data['port'] = str(port)
112110
self.send(data)
113111

114112

115113
def disconnect(self):
116114
data = {}
117-
data["command"] = str("disconnect")
115+
data['command'] = str('disconnect')
118116
self.send(data)
119117

120118

121119
def service(self, service_name, output=Output()):
122120
data = {}
123-
data["command"] = str("createService")
124-
data["service"] = str(service_name)
121+
data['command'] = str('createService')
122+
data['service'] = str(service_name)
125123
self.send(data)
126124
return NaoRobotService(self, service_name, output)

src/widget.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class NaoRobotModel extends DOMWidgetModel {
118118

119119
// Skip if service exists already
120120
if (this._services[serviceName] !== undefined) {
121-
console.log("Service " + serviceName + " exists.");
121+
console.log('Service ' + serviceName + ' exists.');
122122
return;
123123
}
124124

@@ -147,7 +147,6 @@ export class NaoRobotModel extends DOMWidgetModel {
147147
args: any,
148148
_kwargs: any
149149
) {
150-
151150
// Reconnect as needed
152151
if (!this.qiSession.isConnected()) {
153152
await this.connect(this._ipAddress, this._port);
@@ -163,7 +162,7 @@ export class NaoRobotModel extends DOMWidgetModel {
163162
break;
164163
}
165164
await sleep(100);
166-
}
165+
}
167166

168167
if (this._services[serviceName][methodName] === undefined) {
169168
this.changeStatus(methodName + ' does not exist for ' + serviceName);
@@ -178,15 +177,14 @@ export class NaoRobotModel extends DOMWidgetModel {
178177
this.changeStatus('Task completed');
179178
this.send({
180179
isError: false,
181-
data: resolution ?? true
180+
data: resolution ?? true,
182181
});
183-
184182
})
185183
.catch((rejection: string) => {
186184
this.changeStatus(rejection);
187185
this.send({
188186
isError: true,
189-
data: rejection
187+
data: rejection,
190188
});
191189
});
192190

0 commit comments

Comments
 (0)