Skip to content

Commit

Permalink
Merge pull request #3199 from minrk/deprecated-private-header
Browse files Browse the repository at this point in the history
OutputWidget: use public API to get parent header
  • Loading branch information
SylvainCorlay authored May 8, 2021
2 parents e0d41f6 + f2ed880 commit 2e040b5
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit 2e040b5

Please sign in to comment.