@@ -364,36 +364,62 @@ def isinteractive():
364
364
return matplotlib .is_interactive ()
365
365
366
366
367
- def ioff ():
368
- """
369
- Turn the interactive mode off.
367
+ class _ioff_class ():
368
+ def __call__ (self ):
369
+ """
370
+ Turn the interactive mode off.
371
+
372
+ See Also
373
+ --------
374
+ ion : enable interactive mode
375
+ isinteractive : query current state
376
+
377
+ show : show windows (and maybe block)
378
+ pause : show windows, run GUI event loop, and block for a time
379
+ """
380
+ matplotlib .interactive (False )
381
+ uninstall_repl_displayhook ()
370
382
371
- See Also
372
- --------
373
- ion : enable interactive mode
374
- isinteractive : query current state
383
+ def __enter__ (self ):
384
+ self .wasinteractive = isinteractive ()
385
+ self .__call__ ()
375
386
376
- show : show windows (and maybe block)
377
- pause : show windows, run GUI event loop, and block for a time
378
- """
379
- matplotlib . interactive ( False )
380
- uninstall_repl_displayhook ()
387
+ def __exit__ ( self , exc_type , exc_value , traceback ):
388
+ if self . wasinteractive :
389
+ matplotlib . interactive ( True )
390
+ install_repl_displayhook ( )
391
+ del self . wasinteractive
381
392
382
393
383
- def ion ():
384
- """
385
- Turn the interactive mode on.
394
+ class _ion_class ():
395
+ def __call__ (self ):
396
+ """
397
+ Turn the interactive mode on.
386
398
387
- See Also
388
- --------
389
- ioff : disable interactive mode
390
- isinteractive : query current state
399
+ See Also
400
+ --------
401
+ ioff : disable interactive mode
402
+ isinteractive : query current state
391
403
392
- show : show windows (and maybe block)
393
- pause : show windows, run GUI event loop, and block for a time
394
- """
395
- matplotlib .interactive (True )
396
- install_repl_displayhook ()
404
+ show : show windows (and maybe block)
405
+ pause : show windows, run GUI event loop, and block for a time
406
+ """
407
+ matplotlib .interactive (True )
408
+ install_repl_displayhook ()
409
+
410
+ def __enter__ (self ):
411
+ self .wasinteractive = isinteractive ()
412
+ self .__call__ ()
413
+
414
+ def __exit__ (self , exc_type , exc_value , traceback ):
415
+ if not self .wasinteractive :
416
+ matplotlib .interactive (False )
417
+ uninstall_repl_displayhook ()
418
+ del self .wasinteractive
419
+
420
+
421
+ ioff = _ioff_class ()
422
+ ion = _ion_class ()
397
423
398
424
399
425
def pause (interval ):
0 commit comments