|
10 | 10 | import ipykernel.kernelbase
|
11 | 11 | import IPython.display
|
12 | 12 | import ipywidgets
|
| 13 | +import ipywidgets.widgets.widget_output |
13 | 14 | from IPython.core.interactiveshell import InteractiveShell
|
14 | 15 |
|
15 | 16 | from . import app, reload, settings
|
@@ -228,6 +229,22 @@ def Thread_debug_run(self):
|
228 | 229 | _patched = False
|
229 | 230 |
|
230 | 231 |
|
| 232 | +def Output_enter(self): |
| 233 | + self._flush() |
| 234 | + |
| 235 | + def hook(msg): |
| 236 | + if msg["msg_type"] == "display_data": |
| 237 | + self.outputs += ({"output_type": "display_data", "data": msg["content"]["data"], "metadata": msg["content"]["metadata"]},) |
| 238 | + return None |
| 239 | + return msg |
| 240 | + |
| 241 | + get_ipython().display_pub.register_hook(hook) |
| 242 | + |
| 243 | + |
| 244 | +def Output_exit(self, exc_type, exc_value, traceback): |
| 245 | + get_ipython().display_pub._hooks.pop() |
| 246 | + |
| 247 | + |
231 | 248 | def patch():
|
232 | 249 | global _patched
|
233 | 250 | if _patched:
|
@@ -274,10 +291,11 @@ def patch():
|
274 | 291 | # not sure why we cannot reproduce that locally
|
275 | 292 | ipykernel.kernelbase.Kernel.initialized = classmethod(kernel_initialized_dispatch) # type: ignore
|
276 | 293 | ipywidgets.widgets.widget.get_ipython = get_ipython
|
277 |
| - |
278 | 294 | # TODO: find a way to actually monkeypatch get_ipython
|
279 | 295 | IPython.get_ipython = get_ipython
|
280 |
| - ipywidgets.widgets.widget_output.get_ipython = get_ipython |
| 296 | + |
| 297 | + ipywidgets.widgets.widget_output.Output.__enter__ = Output_enter |
| 298 | + ipywidgets.widgets.widget_output.Output.__exit__ = Output_exit |
281 | 299 |
|
282 | 300 | def model_id_debug(self: ipywidgets.widgets.widget.Widget):
|
283 | 301 | from ipyvue.ForceLoad import force_load_instance
|
|
0 commit comments