From 93ebee6ddc3214303a18287528e9afc30adeb46b Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 27 Jun 2018 15:16:26 +0200 Subject: [PATCH] Add private API retrieving the current event loop and backend GUI info. Work towards implementation of backend switching. Note that the API is kept private for now as the lack of extensibility is a bit unsatisfying; perhaps we'll figure out a better way to do it if other custom implementers (e.g., code editors?) get interested in looking into it. The `required_event_loop` variable could be made private for now, or not... --- doc/api/next_api_changes/2018-06-27-AL.rst | 7 +++ lib/matplotlib/backends/__init__.py | 50 ++++++++++++++++++++++ lib/matplotlib/backends/_backend_tk.py | 1 + lib/matplotlib/backends/backend_gtk3.py | 1 + lib/matplotlib/backends/backend_macosx.py | 1 + lib/matplotlib/backends/backend_qt4.py | 2 +- lib/matplotlib/backends/backend_qt5.py | 1 + lib/matplotlib/backends/backend_wx.py | 1 + src/_macosx.m | 15 +++++++ 9 files changed, 78 insertions(+), 1 deletion(-) diff --git a/doc/api/next_api_changes/2018-06-27-AL.rst b/doc/api/next_api_changes/2018-06-27-AL.rst index 74c32d357386..51a8171bf02d 100644 --- a/doc/api/next_api_changes/2018-06-27-AL.rst +++ b/doc/api/next_api_changes/2018-06-27-AL.rst @@ -4,3 +4,10 @@ Changes to backend loading Failure to load backend modules (``macosx`` on non-framework builds and ``gtk3`` when running headless) now raises `ImportError` (instead of `RuntimeError` and `TypeError`, respectively. + +Third-party backends that integrate with an interactive framework are now +encouraged to define the ``required_interactive_framework`` global value to one +of the following values: "qt5", "qt4", "gtk3", "wx", "tk", or "macosx". This +information will be used to determine whether it is possible to switch from a +backend to another (specifically, whether they use the same interactive +framework). diff --git a/lib/matplotlib/backends/__init__.py b/lib/matplotlib/backends/__init__.py index e506d3100927..2467a4235373 100644 --- a/lib/matplotlib/backends/__init__.py +++ b/lib/matplotlib/backends/__init__.py @@ -1,5 +1,7 @@ import importlib import logging +import os +import sys import traceback import matplotlib @@ -14,6 +16,54 @@ if not line.startswith(' File "