jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.17k stars 949 forks source link

DRAFT: Single widget manager per kernel #3920

Closed fleming79 closed 6 months ago

fleming79 commented 6 months ago

This PR is exploring the possibility of a per-kernel widget manager as suggested by @jasongrout in the comments of the recently merged PR: https://github.com/jupyter-widgets/ipywidgets/pull/3004.

This PR follows on from a recent PR https://github.com/jupyter-widgets/ipywidgets/pull/3893, but could be easily re-based independently.

In it's current form, it can render the same widget in notebook[s] and consoles connected to the same kernel. The only requirement being that the KernelWidgetManager is registered to (instantiated with) the kernel.

image

How it works

KernelWidgetManager was modified to create only one instance per kernel.id. WidgetManager was changed to be an interface for notebooks that swaps the notebook (panel) rendermime factory to use the KernelWidgetManager corresponding to the new kernel as the kernel is changed.

Other changes

github-actions[bot] commented 6 months ago

Binder :point_left: Launch a binder notebook on branch fleming79/ipywidgets/single-widget-manager-per-kernel

martinRenou commented 6 months ago

Thanks for opening a PR for this! Was this closed on purpose?

fleming79 commented 6 months ago

Yes and no.

If there is still the possibility of a per-kernel widget manager I can re-open or make a new PR with updates.

martinRenou commented 6 months ago

I believe we're still open to refactor the widget manager logic to be more "general" and less tight to the Notebook (or the console). #3004 was merged as-is because it's already an improvement of the current state, but Jason's comments in the PR are still relevant.