From b6b64348f03285b0ea6eb3fd530e0ebc288067d5 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 3 May 2023 18:11:51 +0200 Subject: [PATCH] Improved support for ipywidgets>=8.0.5 --- panel/io/ipywidget.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/panel/io/ipywidget.py b/panel/io/ipywidget.py index 0324b432f2..ae9c93478d 100644 --- a/panel/io/ipywidget.py +++ b/panel/io/ipywidget.py @@ -24,6 +24,18 @@ from ..util import classproperty from .state import set_curdoc, state +try: + # Support for ipywidgets>=8.0.5 + import comm + + from comm.base_comm import BaseComm + + class DummyComm(BaseComm): + def publish_msg(self, *args, **kwargs): pass + + comm.create_comm = lambda *args, **kwargs: DummyComm(target_name='panel-temp-comm', primary=False) +except Exception: + pass def _get_kernel(cls=None, doc=None): doc = doc or state.curdoc @@ -48,9 +60,10 @@ def _on_widget_constructed(widget, doc=None): return widget._document = doc kernel = _get_kernel(doc=doc) - if widget.comm and isinstance(widget.comm.kernel, PanelKernel): + if widget.comm and widget.comm.target_name != 'panel-temp-comm' and isinstance(widget.comm.kernel, PanelKernel): return args = dict( + kernel=kernel, target_name='jupyter.widget', data={}, buffers=[], metadata={'version': __protocol_version__} )