diff --git a/ipywidgets/_version.py b/ipywidgets/_version.py index 761d079d7f2..3f06ee21f23 100644 --- a/ipywidgets/_version.py +++ b/ipywidgets/_version.py @@ -8,7 +8,7 @@ __version__ = '%s.%s.%s%s'%(version_info[0], version_info[1], version_info[2], '' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4])) -__protocol_version__ = '2.0.0' +__protocol_version__ = '2.1.0' # 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. __jupyter_widgets_base_version__ = '1.2.0' diff --git a/ipywidgets/widgets/widget.py b/ipywidgets/widgets/widget.py index 94e466dd12a..ee3198cdaaa 100644 --- a/ipywidgets/widgets/widget.py +++ b/ipywidgets/widgets/widget.py @@ -319,6 +319,10 @@ def _call_widget_constructed(widget): @classmethod def handle_comm_opened_control(cls, comm, msg): + version = msg.get('metadata', {}).get('version', '') + if version.split('.')[0] != PROTOCOL_VERSION_MAJOR: + raise ValueError("Incompatible widget protocol versions: received version %r, expected version %r"%(version, __protocol_version__)) + cls.get_manager_state() widgets = Widget.widgets.values() # build a single dict with the full widget state @@ -332,10 +336,7 @@ def handle_comm_opened_control(cls, comm, msg): 'state': widget.get_state(drop_defaults=drop_defaults), } full_state, buffer_paths, buffers = _remove_buffers(full_state) - # the message is also send as buffer, so it does not get handled by jupyter_server - msg = jsondumps([full_state, buffer_paths]).encode('utf8') - buffers.insert(0, msg) - comm.send(buffers=buffers) + comm.send([full_state, buffer_paths], buffers=buffers) @staticmethod def handle_comm_opened(comm, msg): diff --git a/packages/base/src/version.ts b/packages/base/src/version.ts index 475502b53b1..8fbd0e7e5b9 100644 --- a/packages/base/src/version.ts +++ b/packages/base/src/version.ts @@ -5,5 +5,4 @@ export const JUPYTER_WIDGETS_VERSION = '1.2.0'; export -const PROTOCOL_VERSION = '2.0.0'; - +const PROTOCOL_VERSION = '2.1.0'; diff --git a/packages/schema/messages.md b/packages/schema/messages.md index c2576e38bc3..96afb475489 100644 --- a/packages/schema/messages.md +++ b/packages/schema/messages.md @@ -338,3 +338,16 @@ To display a widget, the kernel sends a Jupyter [iopub `display_data` message](h } } ``` + + + + +# Widget messaging protocol, version 2.1 + +This is implemented in ipywidgets 7.7. + +## Changes from version 2 + +### The `jupyter.widget.control` comm target + +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.