4
4
# Copyright (c) Isabel Paredes.
5
5
# Distributed under the terms of the Modified BSD License.
6
6
7
- """
7
+ '''
8
8
TODO: Add module docstring
9
- """
9
+ '''
10
10
11
11
from ipywidgets import DOMWidget , Output
12
12
from traitlets import Unicode , Integer
@@ -26,12 +26,12 @@ def __init__(self, widget, service_name, output=Output()):
26
26
27
27
def _create_msg (self , method_name , * args , ** kwargs ):
28
28
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 )
32
32
# 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
35
35
return data
36
36
37
37
def call_service (self , method_name , * args , ** kwargs ):
@@ -44,32 +44,30 @@ async def async_call_service(self, method_name, *args, **kwargs):
44
44
45
45
try :
46
46
self .output .clear_output ()
47
- self .output .append_stdout (" Calling service... \n " )
47
+ self .output .append_stdout (' Calling service... \n ' )
48
48
await self .widget .wait_for_change ('counter' , self .output )
49
49
except Exception as e :
50
50
return e
51
- return self .widget .response [" data" ]
51
+ return self .widget .response [' data' ]
52
52
53
53
54
54
def __getattr__ (self , method_name ):
55
- if (method_name [:6 ] == " async_" ):
55
+ if (method_name [:6 ] == ' async_' ):
56
56
return lambda * x , ** y : self .async_call_service (method_name [6 :], * x , ** y )
57
57
else :
58
58
return lambda * x , ** y : self .call_service (method_name , * x , ** y )
59
59
60
60
61
61
class NaoRobotWidget (DOMWidget ):
62
- """TODO: Add docstring here
63
- """
64
62
_model_name = Unicode ('NaoRobotModel' ).tag (sync = True )
65
63
_model_module = Unicode (module_name ).tag (sync = True )
66
64
_model_module_version = Unicode (module_version ).tag (sync = True )
67
65
_view_name = Unicode ('NaoRobotView' ).tag (sync = True )
68
66
_view_module = Unicode (module_name ).tag (sync = True )
69
67
_view_module_version = Unicode (module_version ).tag (sync = True )
70
68
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 )
73
71
counter = Integer (0 ).tag (sync = True )
74
72
response = None
75
73
@@ -80,7 +78,7 @@ def __init__(self, **kwargs):
80
78
81
79
82
80
def _handle_frontend_msg (self , model , msg , buffer ):
83
- print (" Received frontend msg: " , msg )
81
+ print (' Received frontend msg: ' , msg )
84
82
self .response = msg
85
83
86
84
@@ -91,36 +89,36 @@ def wait_for_change(widget, value_name, output=Output()):
91
89
def get_value_change (change ):
92
90
widget .unobserve (get_value_change , names = value_name )
93
91
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' ])
97
95
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' ])
100
98
else :
101
99
future .set_result (change )
102
100
103
101
widget .observe (get_value_change , names = value_name )
104
102
return future
105
103
106
104
107
- def connect (self , ip_address = " nao.local" , port = "80" ):
105
+ def connect (self , ip_address = ' nao.local' , port = '80' ):
108
106
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 )
112
110
self .send (data )
113
111
114
112
115
113
def disconnect (self ):
116
114
data = {}
117
- data [" command" ] = str (" disconnect" )
115
+ data [' command' ] = str (' disconnect' )
118
116
self .send (data )
119
117
120
118
121
119
def service (self , service_name , output = Output ()):
122
120
data = {}
123
- data [" command" ] = str (" createService" )
124
- data [" service" ] = str (service_name )
121
+ data [' command' ] = str (' createService' )
122
+ data [' service' ] = str (service_name )
125
123
self .send (data )
126
124
return NaoRobotService (self , service_name , output )
0 commit comments