Skip to content

Commit 3a53d04

Browse files
committed
ENH: mpl_gui to main library
1 parent 11e357a commit 3a53d04

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

lib/matplotlib/mpl_gui/_manage_backend.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import importlib
21
import sys
32
import logging
43
import types
@@ -55,22 +54,14 @@ def select_gui_toolkit(newbackend=None):
5554

5655
if newbackend is rcsetup._auto_backend_sentinel:
5756
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]
7161
else:
7262
candidates = []
73-
candidates += ["macosx", "qt5agg", "gtk3agg", "tkagg", "wxagg"]
63+
candidates += [
64+
"macosx", "qtagg", "gtk4agg", "gtk3agg", "tkagg", "wxagg"]
7465

7566
# Don't try to fallback on the cairo-based backends as they each have
7667
# an additional dependency (pycairo) over the agg-based backend, and
@@ -93,8 +84,7 @@ def select_gui_toolkit(newbackend=None):
9384
# body is filled with the module's globals.
9485

9586
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)
9888
if hasattr(mod, "Backend"):
9989
orig_class = mod.Backend
10090

@@ -135,9 +125,8 @@ def show_managers(cls, *, managers, block):
135125
mod.Backend = BackendClass
136126
sys.modules[mod_name] = mod
137127

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
141130
if required_framework is not None:
142131
current_framework = cbook._get_running_interactive_framework()
143132
if (

0 commit comments

Comments
 (0)