Skip to content

OutputWidget: use public API to get parent header #3199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions ipywidgets/widgets/widget_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Output(DOMWidget):
context will be captured and displayed in the widget instead of the standard output
area.

You can also use the .capture() method to decorate a function or a method. Any output
You can also use the .capture() method to decorate a function or a method. Any output
produced by the function will then go to the output widget. This is useful for
debugging widget callbacks, for example.

Expand Down Expand Up @@ -108,9 +108,16 @@ def __enter__(self):
"""Called upon entering output widget context manager."""
self._flush()
ip = get_ipython()
if ip and hasattr(ip, 'kernel') and hasattr(ip.kernel, '_parent_header'):
self.msg_id = ip.kernel._parent_header['header']['msg_id']
self.__counter += 1
if ip and getattr(ip, "kernel", None) is not None:
if hasattr(ip.kernel, "get_parent"):
parent = ip.kernel.get_parent()
elif hasattr(ip.kernel, "_parent_header"):
# ipykernel < 6: kernel._parent_header is the parent *request*
parent = ip.kernel._parent_header

if parent and parent.get("header"):
self.msg_id = parent["header"]["msg_id"]
self.__counter += 1

def __exit__(self, etype, evalue, tb):
"""Called upon exiting output widget context manager."""
Expand Down