1
- import importlib
2
1
import sys
3
2
import logging
4
3
import types
@@ -55,22 +54,14 @@ def select_gui_toolkit(newbackend=None):
55
54
56
55
if newbackend is rcsetup ._auto_backend_sentinel :
57
56
current_framework = cbook ._get_running_interactive_framework ()
58
- mapping = {
59
- "qt" : "qtagg" ,
60
- "gtk3" : "gtk3agg" ,
61
- "gtk4" : "gtk4agg" ,
62
- "wx" : "wxagg" ,
63
- "tk" : "tkagg" ,
64
- "macosx" : "macosx" ,
65
- "headless" : "agg" ,
66
- }
67
-
68
- best_guess = mapping .get (current_framework , None )
69
- if best_guess is not None :
70
- candidates = [best_guess ]
57
+ if (current_framework and
58
+ (backend := backend_registry .backend_for_gui_framework (
59
+ current_framework ))):
60
+ candidates = [backend ]
71
61
else :
72
62
candidates = []
73
- candidates += ["macosx" , "qt5agg" , "gtk3agg" , "tkagg" , "wxagg" ]
63
+ candidates += [
64
+ "macosx" , "qtagg" , "gtk4agg" , "gtk3agg" , "tkagg" , "wxagg" ]
74
65
75
66
# Don't try to fallback on the cairo-based backends as they each have
76
67
# an additional dependency (pycairo) over the agg-based backend, and
@@ -93,8 +84,7 @@ def select_gui_toolkit(newbackend=None):
93
84
# body is filled with the module's globals.
94
85
95
86
backend_name = backend_registry .resolve_gui_or_backend (newbackend )[0 ]
96
- print (backend_name )
97
- mod = importlib .import_module ('matplotlib.backends.backend_' + backend_name )
87
+ mod = backend_registry .load_backend_module (newbackend )
98
88
if hasattr (mod , "Backend" ):
99
89
orig_class = mod .Backend
100
90
@@ -135,9 +125,8 @@ def show_managers(cls, *, managers, block):
135
125
mod .Backend = BackendClass
136
126
sys .modules [mod_name ] = mod
137
127
138
- required_framework = getattr (
139
- BackendClass .FigureCanvas , "required_interactive_framework" , None
140
- )
128
+ canvas_class = mod .FigureCanvas
129
+ required_framework = canvas_class .required_interactive_framework
141
130
if required_framework is not None :
142
131
current_framework = cbook ._get_running_interactive_framework ()
143
132
if (
0 commit comments