Skip to content

Commit 16d0f57

Browse files
committed
Docs + remove buffer hack
I removed the buffer hack. This shouldn't be required anymore since the removal of json_clean in ipykernel. We should also see if we can improve performances in jupyter-server.
1 parent b6f6dbc commit 16d0f57

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

ipywidgets/_version.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4]))
1010

1111
__protocol_version__ = '2.0.0'
12+
__control_protocol_version__ = '1.0.0'
1213

1314
# These are *protocol* versions for each package, *not* npm versions. To check, look at each package's src/version.ts file for the protocol version the package implements.
1415
__jupyter_widgets_base_version__ = '1.2.0'

ipywidgets/widgets/widget.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525

2626
from base64 import standard_b64encode
2727

28-
from .._version import __protocol_version__, __jupyter_widgets_base_version__
28+
from .._version import __protocol_version__, __control_protocol_version__, __jupyter_widgets_base_version__
2929
PROTOCOL_VERSION_MAJOR = __protocol_version__.split('.')[0]
30+
CONTROL_PROTOCOL_VERSION_MAJOR = __control_protocol_version__.split('.')[0]
3031

3132
def _widget_to_json(x, obj):
3233
if isinstance(x, dict):
@@ -319,6 +320,10 @@ def _call_widget_constructed(widget):
319320

320321
@classmethod
321322
def handle_comm_opened_control(cls, comm, msg):
323+
version = msg.get('metadata', {}).get('version', '')
324+
if version.split('.')[0] != CONTROL_PROTOCOL_VERSION_MAJOR:
325+
raise ValueError("Incompatible widget control protocol versions: received version %r, expected version %r"%(version, __control_protocol_version__))
326+
322327
cls.get_manager_state()
323328
widgets = Widget.widgets.values()
324329
# build a single dict with the full widget state
@@ -332,10 +337,7 @@ def handle_comm_opened_control(cls, comm, msg):
332337
'state': widget.get_state(drop_defaults=drop_defaults),
333338
}
334339
full_state, buffer_paths, buffers = _remove_buffers(full_state)
335-
# the message is also send as buffer, so it does not get handled by jupyter_server
336-
msg = jsondumps([full_state, buffer_paths]).encode('utf8')
337-
buffers.insert(0, msg)
338-
comm.send(buffers=buffers)
340+
comm.send([full_state, buffer_paths], buffers=buffers)
339341

340342
@staticmethod
341343
def handle_comm_opened(comm, msg):

packages/base/src/version.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ const JUPYTER_WIDGETS_VERSION = '1.2.0';
66

77
export
88
const PROTOCOL_VERSION = '2.0.0';
9-

packages/schema/messages.md

+11
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,14 @@ To display a widget, the kernel sends a Jupyter [iopub `display_data` message](h
338338
}
339339
}
340340
```
341+
342+
343+
344+
345+
# Control Widget messaging protocol, version 1.0
346+
347+
This is implemented in ipywidgets 7.7.
348+
349+
### The `jupyter.widget.control` comm target
350+
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). The kernel-side widgets library must answer to the "comm-open" message with a comm message containing the full state of all widget instances.

0 commit comments

Comments
 (0)