|
67 | 67 | Locator, IndexLocator, FixedLocator, NullLocator,\
|
68 | 68 | LinearLocator, LogLocator, AutoLocator, MultipleLocator,\
|
69 | 69 | MaxNLocator
|
70 |
| -from matplotlib.backends import pylab_setup |
| 70 | +from matplotlib.backends import pylab_setup, _get_running_interactive_framework |
71 | 71 |
|
72 | 72 | _log = logging.getLogger(__name__)
|
73 | 73 |
|
|
78 | 78 | # FIXME: Deprecate.
|
79 | 79 | def _backend_selection():
|
80 | 80 | """
|
81 |
| - If rcParams['backend_fallback'] is true, check to see if the |
82 |
| - current backend is compatible with the current running event loop, |
83 |
| - and if not switches to a compatible one. |
84 |
| - """ |
85 |
| - backend = rcParams['backend'] |
86 |
| - if not rcParams['backend_fallback'] or backend not in _interactive_bk: |
87 |
| - return |
88 |
| - is_agg_backend = rcParams['backend'].endswith('Agg') |
89 |
| - if 'wx' in sys.modules and backend not in ('WX', 'WXAgg'): |
90 |
| - import wx |
91 |
| - if wx.App.IsMainLoopRunning(): |
92 |
| - rcParams['backend'] = 'wx' + 'Agg' * is_agg_backend |
93 |
| - elif 'PyQt4.QtCore' in sys.modules and not backend == 'Qt4Agg': |
94 |
| - import PyQt4.QtGui |
95 |
| - if not PyQt4.QtGui.qApp.startingUp(): |
96 |
| - # The mainloop is running. |
97 |
| - rcParams['backend'] = 'qt4Agg' |
98 |
| - elif 'PyQt5.QtCore' in sys.modules and not backend == 'Qt5Agg': |
99 |
| - import PyQt5.QtWidgets |
100 |
| - if not PyQt5.QtWidgets.qApp.startingUp(): |
101 |
| - # The mainloop is running. |
102 |
| - rcParams['backend'] = 'qt5Agg' |
103 |
| - elif 'gtk' in sys.modules and 'gi' in sys.modules: |
104 |
| - from gi.repository import GLib |
105 |
| - if GLib.MainLoop().is_running(): |
106 |
| - rcParams['backend'] = 'GTK3Agg' |
107 |
| - elif 'Tkinter' in sys.modules and not backend == 'TkAgg': |
108 |
| - # import Tkinter |
109 |
| - pass # what if anything do we need to do for tkinter? |
| 81 | + If rcParams['backend_fallback'] is true, we will check (at backend |
| 82 | + load-time) to see if the current backend is compatible with the current |
| 83 | + running event loop, and if not switches to a compatible one. |
| 84 | + """ |
| 85 | + if rcParams["backend_fallback"]: |
| 86 | + if (dict.__getitem__(rcParams, "backend") in _interactive_bk |
| 87 | + and _get_running_interactive_framework()): |
| 88 | + dict.__setitem__( |
| 89 | + rcParams, "backend", rcsetup._auto_backend_sentinel) |
110 | 90 |
|
111 | 91 |
|
112 | 92 | _backend_selection()
|
|
0 commit comments