Skip to content

Commit

Permalink
fix: support ipywidgets 8
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Aug 23, 2022
1 parent 18d640a commit 6fb0784
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 17 additions & 1 deletion react_ipywidgets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@

__version__ = _version.__version__


ipywidget_version_major = int(widgets.__version__.split(".")[0])


class _classproperty_widget_fix(object):
def __get__(self, owner_self, owner_cls):
assert owner_self is None
return owner_cls._active_widgets


if ipywidget_version_major >= 8:
if not hasattr(widgets.Widget, "widgets"):
widgets.Widget.widgets = _classproperty_widget_fix()


_last_rc = None # used for testing
local = threading.local()
T = TypeVar("T")
Expand Down Expand Up @@ -1642,7 +1657,8 @@ def check_view_count(change):
MIME_WIDGETS: {"version_major": 2, "version_minor": 0, "model_id": widget._model_id},
}
IPython.display.display(data, raw=True)
widget._handle_displayed()
if ipywidget_version_major < 8:
widget._handle_displayed()


def make(el: Element, handle_error: bool = True):
Expand Down
11 changes: 8 additions & 3 deletions react_ipywidgets/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from . import bqplot
from . import ipyvuetify as v
from . import ipywidgets as w
from .core import ipywidget_version_major

T = TypeVar("T")

Expand All @@ -26,7 +27,7 @@ def first(container: List[T]) -> T:


def clear():
widgets.Widget.widgets = {}
widgets.Widget.widgets.clear()


def count():
Expand Down Expand Up @@ -674,8 +675,12 @@ def Buttons(checkbox):
assert vbox.children[0] is not vbox.children[1]
assert vbox.children[0].description == "Button 0"
assert vbox.children[1].description == "Button 1"
assert vbox.children[0].tooltip == ""
assert vbox.children[1].tooltip == ""
if ipywidget_version_major >= 8:
assert vbox.children[0].tooltip is None
assert vbox.children[1].tooltip is None
else:
assert vbox.children[0].tooltip == ""
assert vbox.children[1].tooltip == ""
rc.close()
checkbox.style.close()
checkbox.layout.close()
Expand Down

0 comments on commit 6fb0784

Please sign in to comment.