Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import importlib 

2import logging 

3import os 

4import sys 

5 

6import matplotlib 

7from matplotlib import cbook 

8from matplotlib.backend_bases import _Backend 

9 

10_log = logging.getLogger(__name__) 

11 

12 

13# NOTE: plt.switch_backend() (called at import time) will add a "backend" 

14# attribute here for backcompat. 

15 

16 

17def _get_running_interactive_framework(): 

18 """ 

19 Return the interactive framework whose event loop is currently running, if 

20 any, or "headless" if no event loop can be started, or None. 

21 

22 Returns 

23 ------- 

24 Optional[str] 

25 One of the following values: "qt5", "qt4", "gtk3", "wx", "tk", 

26 "macosx", "headless", ``None``. 

27 """ 

28 QtWidgets = (sys.modules.get("PyQt5.QtWidgets") 

29 or sys.modules.get("PySide2.QtWidgets")) 

30 if QtWidgets and QtWidgets.QApplication.instance(): 

31 return "qt5" 

32 QtGui = (sys.modules.get("PyQt4.QtGui") 

33 or sys.modules.get("PySide.QtGui")) 

34 if QtGui and QtGui.QApplication.instance(): 

35 return "qt4" 

36 Gtk = sys.modules.get("gi.repository.Gtk") 

37 if Gtk and Gtk.main_level(): 

38 return "gtk3" 

39 wx = sys.modules.get("wx") 

40 if wx and wx.GetApp(): 

41 return "wx" 

42 tkinter = sys.modules.get("tkinter") 

43 if tkinter: 

44 for frame in sys._current_frames().values(): 

45 while frame: 

46 if frame.f_code == tkinter.mainloop.__code__: 

47 return "tk" 

48 frame = frame.f_back 

49 if 'matplotlib.backends._macosx' in sys.modules: 

50 if sys.modules["matplotlib.backends._macosx"].event_loop_is_running(): 

51 return "macosx" 

52 if sys.platform.startswith("linux") and not os.environ.get("DISPLAY"): 

53 return "headless" 

54 return None