diff --git a/docs/environment.yml b/docs/environment.yml index e747e14a..ed8a82f7 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -3,6 +3,7 @@ name: pythreejs_docs channels: - conda-forge dependencies: +- ipydatawidgets>=4.3.2 - python=3.10 - nodejs - numpy diff --git a/pythreejs/_base/Three.py b/pythreejs/_base/Three.py index 7d1beee8..92cc1eac 100644 --- a/pythreejs/_base/Three.py +++ b/pythreejs/_base/Three.py @@ -39,21 +39,29 @@ def _on_ret_val(self, method_name, ret_val): """Message callback used internally for logging exec returns""" self.log.info('%s() -> %s' % (method_name, ret_val)) - def _repr_mimebundle_(self, **kwargs): - if self._previewable: - from IPython.display import display - from .renderable import Preview - plaintext = repr(self) - if len(plaintext) > 110: - plaintext = plaintext[:110] + '…' - preview = Preview(self) - return { - 'text/plain': plaintext, - 'application/vnd.jupyter.widget-view+json': { - "version_major": 2, - "version_minor": 0, - "model_id": preview._model_id + if hasattr(Widget, "_ipython_display_"): # ipywidgets < 8.0.0 + def _ipython_display_(self, **kwargs): + if self._previewable: + from IPython.display import display + from .renderable import Preview + return display(Preview(self), **kwargs) + else: + return super(ThreeWidget, self)._ipython_display_(**kwargs) + else: + def _repr_mimebundle_(self, **kwargs): + if self._previewable: + from .renderable import Preview + plaintext = repr(self) + if len(plaintext) > 110: + plaintext = plaintext[:110] + '…' + preview = Preview(self) + return { + 'text/plain': plaintext, + 'application/vnd.jupyter.widget-view+json': { + "version_major": 2, + "version_minor": 0, + "model_id": preview._model_id + } } - } - else: - return super(ThreeWidget, self)._repr_mimebundle_(**kwargs) + else: + return super(ThreeWidget, self)._repr_mimebundle_(**kwargs) \ No newline at end of file diff --git a/setup.py b/setup.py index 383471bb..3492c4dc 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,7 @@ 'ipywidgets>=7.2.1', 'ipydatawidgets>=1.1.1', 'numpy', + 'traitlets', ], 'extras_require': { 'test': [