Skip to content

Backport PR #14979: FIX: Don't enable IPython integration if not ente… #15189

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
25 changes: 16 additions & 9 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,20 @@ def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
self.key = key


def _is_non_interactive_terminal_ipython(ip):
"""
Return whether we are in a a terminal IPython, but non interactive.

When in _terminal_ IPython, ip.parent will have and `interact` attribute,
if this attribute is False we do not setup eventloop integration as the
user will _not_ interact with IPython. In all other case (ZMQKernel, or is
interactive), we do.
"""
return (hasattr(ip, 'parent')
and (ip.parent is not None)
and getattr(ip.parent, 'interact', None) is False)


class FigureCanvasBase(object):
"""
The canvas the figure renders into.
Expand Down Expand Up @@ -1620,15 +1634,8 @@ def _fix_ipython_backend2gui(cls):
backend2gui_rif = {"qt5": "qt", "qt4": "qt", "gtk3": "gtk3",
"wx": "wx", "macosx": "osx"}.get(rif)
if backend2gui_rif:
pt.backend2gui[get_backend()] = backend2gui_rif
# Work around pylabtools.find_gui_and_backend always reading from
# rcParamsOrig.
orig_origbackend = mpl.rcParamsOrig["backend"]
try:
mpl.rcParamsOrig["backend"] = mpl.rcParams["backend"]
ip.enable_matplotlib()
finally:
mpl.rcParamsOrig["backend"] = orig_origbackend
if _is_non_interactive_terminal_ipython(ip):
ip.enable_gui(backend2gui_rif)

@contextmanager
def _idle_draw_cntx(self):
Expand Down