@@ -1532,6 +1532,20 @@ def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
1532
1532
self .key = key
1533
1533
1534
1534
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
+
1535
1549
class FigureCanvasBase (object ):
1536
1550
"""
1537
1551
The canvas the figure renders into.
@@ -1620,15 +1634,8 @@ def _fix_ipython_backend2gui(cls):
1620
1634
backend2gui_rif = {"qt5" : "qt" , "qt4" : "qt" , "gtk3" : "gtk3" ,
1621
1635
"wx" : "wx" , "macosx" : "osx" }.get (rif )
1622
1636
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 )
1632
1639
1633
1640
@contextmanager
1634
1641
def _idle_draw_cntx (self ):
0 commit comments