MCPcopy Index your code
hub / github.com/ipython/ipython / find_gui_and_backend

Function find_gui_and_backend

IPython/core/pylabtools.py:321–390  ·  view source on GitHub ↗

Given a gui string return the gui and mpl backend. Parameters ---------- gui : str Can be one of ('tk','gtk','wx','qt','qt4','inline','agg'). gui_select : str Can be one of ('tk','gtk','wx','qt','qt4','inline'). This is any gui already selected by the shell.

(gui=None, gui_select=None)

Source from the content-addressed store, hash-verified

319
320
321def find_gui_and_backend(gui=None, gui_select=None):
322 """Given a gui string return the gui and mpl backend.
323
324 Parameters
325 ----------
326 gui : str
327 Can be one of ('tk','gtk','wx','qt','qt4','inline','agg').
328 gui_select : str
329 Can be one of ('tk','gtk','wx','qt','qt4','inline').
330 This is any gui already selected by the shell.
331
332 Returns
333 -------
334 A tuple of (gui, backend) where backend is one of ('TkAgg','GTKAgg',
335 'WXAgg','Qt4Agg','module://matplotlib_inline.backend_inline','agg').
336 """
337
338 import matplotlib
339
340 if _matplotlib_manages_backends():
341 backend_registry = matplotlib.backends.registry.backend_registry
342
343 # gui argument may be a gui event loop or may be a backend name.
344 if gui in ("auto", None):
345 backend = matplotlib.rcParamsOrig["backend"]
346 backend, gui = backend_registry.resolve_backend(backend)
347 else:
348 gui = _convert_gui_to_matplotlib(gui)
349 backend, gui = backend_registry.resolve_gui_or_backend(gui)
350
351 gui = _convert_gui_from_matplotlib(gui)
352 return gui, backend
353
354 # Fallback to previous behaviour (Matplotlib < 3.9)
355 mpl_version_info = getattr(matplotlib, "__version_info__", (0, 0))
356 has_unified_qt_backend = mpl_version_info >= (3, 5)
357
358
359 backends_ = dict(_deprecated_backends)
360 if not has_unified_qt_backend:
361 backends_["qt"] = "qt5agg"
362
363 if gui and gui != 'auto':
364 # select backend based on requested gui
365 backend = backends_[gui]
366 if gui == 'agg':
367 gui = None
368 else:
369 # We need to read the backend from the original data structure, *not*
370 # from mpl.rcParams, since a prior invocation of %matplotlib may have
371 # overwritten that.
372 # WARNING: this assumes matplotlib 1.1 or newer!!
373 backend = matplotlib.rcParamsOrig['backend']
374
375 # In this case, we need to find what the appropriate gui selection call
376 # should be for IPython, so we can activate inputhook accordingly
377 gui = _deprecated_backend2gui.get(backend, None)
378

Callers

nothing calls this directly

Calls 4

getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…