@@ -1532,6 +1532,20 @@ def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
15321532 self .key = key
15331533
15341534
1535+ def _is_non_interactive_terminal_ipython (ip ):
1536+ """
1537+ Return whether we are in a a terminal IPython, but non interactive.
1538+
1539+ When in _terminal_ IPython, ip.parent will have and `interact` attribute,
1540+ if this attribute is False we do not setup eventloop integration as the
1541+ user will _not_ interact with IPython. In all other case (ZMQKernel, or is
1542+ interactive), we do.
1543+ """
1544+ return (hasattr (ip , 'parent' )
1545+ and (ip .parent is not None )
1546+ and getattr (ip .parent , 'interact' , None ) is False )
1547+
1548+
15351549class FigureCanvasBase (object ):
15361550 """
15371551 The canvas the figure renders into.
@@ -1620,15 +1634,8 @@ def _fix_ipython_backend2gui(cls):
16201634 backend2gui_rif = {"qt5" : "qt" , "qt4" : "qt" , "gtk3" : "gtk3" ,
16211635 "wx" : "wx" , "macosx" : "osx" }.get (rif )
16221636 if backend2gui_rif :
1623- pt .backend2gui [get_backend ()] = backend2gui_rif
1624- # Work around pylabtools.find_gui_and_backend always reading from
1625- # rcParamsOrig.
1626- orig_origbackend = mpl .rcParamsOrig ["backend" ]
1627- try :
1628- mpl .rcParamsOrig ["backend" ] = mpl .rcParams ["backend" ]
1629- ip .enable_matplotlib ()
1630- finally :
1631- mpl .rcParamsOrig ["backend" ] = orig_origbackend
1637+ if _is_non_interactive_terminal_ipython (ip ):
1638+ ip .enable_gui (backend2gui_rif )
16321639
16331640 @contextmanager
16341641 def _idle_draw_cntx (self ):
0 commit comments