Skip to content

Commit 2714d7b

Browse files
committed
Rename messages + add more documentation
1 parent d7e9b99 commit 2714d7b

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

ipywidgets/widgets/widget.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ def handle_control_comm_msg(cls, msg):
333333
if cls._control_comm is None:
334334
raise RuntimeError('Control comm has not been properly opened')
335335

336-
if msg['content']['data']['type'] == 'models-request':
336+
data = msg['content']['data']
337+
method = data['method']
338+
339+
if method == 'request_states':
337340
# Send back the full widgets state
338341
cls.get_manager_state()
339342
widgets = Widget.widgets.values()
@@ -347,9 +350,14 @@ def handle_control_comm_msg(cls, msg):
347350
'state': widget.get_state(drop_defaults=drop_defaults),
348351
}
349352
full_state, buffer_paths, buffers = _remove_buffers(full_state)
350-
cls._control_comm.send([full_state, buffer_paths], buffers=buffers)
353+
cls._control_comm.send(dict(
354+
method='states',
355+
states=full_state,
356+
buffer_paths=buffer_paths
357+
), buffers=buffers)
358+
351359
else:
352-
raise RuntimeError('Control comm msg "{}" not implemented'.format(msg['content']['data']['type']))
360+
self.log.error('Unknown front-end to back-end widget control msg with method "%s"' % method)
353361

354362
@staticmethod
355363
def handle_comm_opened(comm, msg):

packages/schema/messages.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,34 @@ This is implemented in ipywidgets 7.7.
348348

349349
### The `jupyter.widget.control` comm target
350350

351-
A kernel-side Jupyter widgets library registers a `jupyter.widget.control` comm target that is used for fetching all widgets states through a "one shot" comm message (one for all widget instances).
351+
A kernel-side Jupyter widgets library registers a `jupyter.widget.control` comm target that is used for fetching all widgets states through a "one shot" comm message (one for all widget instances). Unlike the `jupyter.widget` comm target, the created comm is global to all widgets,
352352

353-
The kernel-side widgets library must answer to the `{"type": "models-request"}` message with a comm message containing the full state of all widget instances.
353+
#### State requests: `request_states`
354+
355+
When a frontend wants to request the full state of a all widgets, the frontend sends a `request_states` message:
356+
357+
```
358+
{
359+
'comm_id' : 'u-u-i-d',
360+
'data' : {
361+
'method': 'request_states'
362+
}
363+
}
364+
```
365+
366+
The kernel side of the widget should immediately send an `states` message with all widgets states:
367+
368+
```
369+
{
370+
'comm_id' : 'u-u-i-d',
371+
'data' : {
372+
'method': 'states',
373+
'states': {
374+
<widget1 u-u-i-d>: <widget1 state>,
375+
<widget2 u-u-i-d>: <widget2 state>,
376+
[...]
377+
},
378+
'buffer_paths': [ <list with paths corresponding to the binary buffers> ]
379+
}
380+
}
381+
```

0 commit comments

Comments
 (0)