##// END OF EJS Templates
Darken and mypy
Ian Thomas -
Show More
@@ -24,12 +24,13 b' from warnings import warn'
24 24 #-----------------------------------------------------------------------------
25 25
26 26 magic_gui_arg = magic_arguments.argument(
27 'gui', nargs='?',
28 help="""Name of the matplotlib backend to use such as 'qt' or 'widget'.
27 "gui",
28 nargs="?",
29 help="""Name of the matplotlib backend to use such as 'qt' or 'widget'.
29 30 If given, the corresponding matplotlib backend is used,
30 31 otherwise it will be matplotlib's default
31 32 (which you can set in your matplotlib config file).
32 """
33 """,
33 34 )
34 35
35 36
@@ -93,11 +94,14 b' class PylabMagics(Magics):'
93 94 args = magic_arguments.parse_argstring(self.matplotlib, line)
94 95 if args.list:
95 96 from IPython.core.pylabtools import _matplotlib_manages_backends
97
96 98 if _matplotlib_manages_backends():
97 99 from matplotlib.backends.registry import backend_registry
100
98 101 backends_list = backend_registry.list_all()
99 102 else:
100 103 from IPython.core.pylabtools import backends
104
101 105 backends_list = list(backends.keys())
102 106 print("Available matplotlib backends: %s" % backends_list)
103 107 else:
@@ -44,7 +44,9 b' _deprecated_backends = {'
44 44 # GUI support to activate based on the desired matplotlib backend. For the
45 45 # most part it's just a reverse of the above dict, but we also need to add a
46 46 # few others that map to the same GUI manually:
47 _deprecated_backend2gui = dict(zip(_deprecated_backends.values(), _deprecated_backends.keys()))
47 _deprecated_backend2gui = dict(
48 zip(_deprecated_backends.values(), _deprecated_backends.keys())
49 )
48 50 # In the reverse mapping, there are a few extra valid matplotlib backends that
49 51 # map to the same GUI support
50 52 _deprecated_backend2gui["GTK"] = _deprecated_backend2gui["GTKCairo"] = "gtk"
@@ -279,7 +281,7 b' def select_figure_formats(shell, formats, **kwargs):'
279 281
280 282 [ f.pop(Figure, None) for f in shell.display_formatter.formatters.values() ]
281 283 mplbackend = matplotlib.get_backend().lower()
282 if mplbackend in ('nbagg', 'ipympl', 'widget', 'module://ipympl.backend_nbagg'):
284 if mplbackend in ("nbagg", "ipympl", "widget", "module://ipympl.backend_nbagg"):
283 285 formatter = shell.display_formatter.ipython_display_formatter
284 286 formatter.for_type(Figure, _reshow_nbagg_figure)
285 287
@@ -330,15 +332,16 b' def find_gui_and_backend(gui=None, gui_select=None):'
330 332 """
331 333
332 334 import matplotlib
335
333 336 if _matplotlib_manages_backends():
334 337 backend_registry = matplotlib.backends.registry.backend_registry
335 338
336 339 # gui argument may be a gui event loop or may be a backend name.
337 340 if gui in ("auto", None):
338 backend = matplotlib.rcParamsOrig['backend']
341 backend = matplotlib.rcParamsOrig["backend"]
339 342 backend, gui = backend_registry.resolve_backend(backend)
340 343 else:
341 backend, gui = backend_registry.resolve_gui_or_backend(gui)
344 backend, gui = backend_registry.resolve_gui_or_backend(gui)
342 345
343 346 return gui, backend
344 347
@@ -347,6 +350,7 b' def find_gui_and_backend(gui=None, gui_select=None):'
347 350 has_unified_qt_backend = mpl_version_info >= (3, 5)
348 351
349 352 from IPython.core.pylabtools import backends
353
350 354 backends_ = dict(backends)
351 355 if not has_unified_qt_backend:
352 356 backends_["qt"] = "qt5agg"
@@ -466,5 +470,6 b' def configure_inline_support(shell, backend):'
466 470
467 471 def _matplotlib_manages_backends():
468 472 import matplotlib
473
469 474 mpl_version_info = getattr(matplotlib, "__version_info__", (0, 0))
470 475 return mpl_version_info >= (3, 9)
@@ -31,7 +31,7 b' from IPython.terminal import pt_inputhooks'
31 31
32 32 gui_keys = tuple(sorted(pt_inputhooks.backends) + sorted(pt_inputhooks.aliases))
33 33
34 backend_keys = []
34 backend_keys: list[str] = []
35 35
36 36 shell_flags = {}
37 37
General Comments 0
You need to be logged in to leave comments. Login now