Skip to content

Commit

Permalink
fix: prevent NotebookWidgets.display_html in ipython shell (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunato committed Jun 23, 2021
1 parent 139f5c6 commit e44c9e4
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions eodag/utils/notebook.py
Expand Up @@ -18,26 +18,40 @@


def check_ipython():
"""Check if called from ipython / notebook"""
"""Check if called from ipython"""
try:
__IPYTHON__
return True
except NameError:
return False


def check_notebook():
"""Check if called from a notebook"""
try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
return False # Other type
except NameError:
return False # Probably standard Python interpreter


class NotebookWidgets(object):
"""Display / handle ipython widgets"""

ipython = False
is_notebook = False
html_box = None
html_box_shown = False
display = None

def __init__(self):
self.ipython = check_ipython()
self.is_notebook = check_notebook()

if self.ipython:
if self.is_notebook:
from IPython.display import HTML, display, update_display

self.display = display
Expand All @@ -49,7 +63,7 @@ def __init__(self):
def display_html(self, html_value):
"""Display HTML message"""

if self.ipython:
if self.is_notebook:
self.html_box.data = html_value

if not self.html_box_shown:
Expand All @@ -63,6 +77,6 @@ def display_html(self, html_value):
def clear_html(self):
"""Clear HTML message"""

if self.ipython:
if self.is_notebook:
self.html_box.data = ""
self._update_display(self.html_box, display_id=self._html_handle.display_id)

0 comments on commit e44c9e4

Please sign in to comment.