Skip to content

Commit

Permalink
fix get_mpl_interactive_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Oct 25, 2022
1 parent be58854 commit 99509ae
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions spyder_kernels/console/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,39 +505,21 @@ def get_mpl_interactive_backend(self):
}

try:
# --- Get interactive framework
framework = None

# This is necessary because _get_running_interactive_framework
# can't detect Tk in a Jupyter kernel.
if hasattr(self, 'app_wrapper'):
if hasattr(self.app_wrapper, 'app'):
import tkinter
if isinstance(self.app_wrapper.app, tkinter.Tk):
framework = 'tk'

if framework is None:
try:
# This is necessary for Matplotlib 3.3.0+
from matplotlib import cbook
framework = cbook._get_running_interactive_framework()
except AttributeError:
# For older versions
from matplotlib import backends
framework = backends._get_running_interactive_framework()
gui = self.shell.active_eventloop

if gui in mapping:
return MPL_BACKENDS_TO_SPYDER[mapping[gui]]

# --- Return backend according to framework
if framework is None:
if gui in [None, 'inline']:
# Since no interactive backend has been set yet, this is
# equivalent to having the inline one.
return 0
elif framework in mapping:
return MPL_BACKENDS_TO_SPYDER[mapping[framework]]
else:
# This covers the case of other backends (e.g. Wx or Gtk)
# which users can set interactively with the %matplotlib
# magic but not through our Preferences.
return -1

# This covers the case of other backends (e.g. Wx or Gtk)
# which users can set interactively with the %matplotlib
# magic but not through our Preferences.
return -1
except Exception:
return None

Expand Down

0 comments on commit 99509ae

Please sign in to comment.