Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8fad359

Browse files
authored
Merge pull request #14521 from anntzer/rif
Move required_interactive_framework to canvas class.
2 parents d8123e6 + 675f48f commit 8fad359

11 files changed

+47
-29
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
API changes
2+
```````````
3+
4+
The ``required_interactive_framework`` attribute of backend modules introduced
5+
in Matplotlib 3.0 has been moved to the FigureCanvas class, in order to let it
6+
be inherited by third-party canvas subclasses and to make it easier to know
7+
what interactive framework is required by a canvas class.
8+
9+
``backend_qt4.FigureCanvasQT5``, which is an alias for
10+
``backend_qt5.FigureCanvasQT`` (but only exists under that name in
11+
``backend_qt4``), has been removed.

lib/matplotlib/backend_bases.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,12 @@ class FigureCanvasBase:
15771577
----------
15781578
figure : `matplotlib.figure.Figure`
15791579
A high-level figure instance
1580-
15811580
"""
1581+
1582+
# Set to one of {"qt5", "qt4", "gtk3", "wx", "tk", "macosx"} if an
1583+
# interactive framework is required, or None otherwise.
1584+
required_interactive_framework = None
1585+
15821586
events = [
15831587
'resize_event',
15841588
'draw_event',
@@ -1654,8 +1658,7 @@ def _fix_ipython_backend2gui(cls):
16541658
# In case we ever move the patch to IPython and remove these APIs,
16551659
# don't break on our side.
16561660
return
1657-
backend_mod = sys.modules[cls.__module__]
1658-
rif = getattr(backend_mod, "required_interactive_framework", None)
1661+
rif = getattr(cls, "required_interactive_framework", None)
16591662
backend2gui_rif = {"qt5": "qt", "qt4": "qt", "gtk3": "gtk3",
16601663
"wx": "wx", "macosx": "osx"}.get(rif)
16611664
if backend2gui_rif:
@@ -3299,10 +3302,6 @@ class _Backend:
32993302
# class FooBackend(_Backend):
33003303
# # override the attributes and methods documented below.
33013304

3302-
# Set to one of {"qt5", "qt4", "gtk3", "wx", "tk", "macosx"} if an
3303-
# interactive framework is required, or None otherwise.
3304-
required_interactive_framework = None
3305-
33063305
# `backend_version` may be overridden by the subclass.
33073306
backend_version = "unknown"
33083307

@@ -3385,14 +3384,15 @@ def show(cls, block=None):
33853384

33863385
@staticmethod
33873386
def export(cls):
3388-
for name in ["required_interactive_framework",
3389-
"backend_version",
3390-
"FigureCanvas",
3391-
"FigureManager",
3392-
"new_figure_manager",
3393-
"new_figure_manager_given_figure",
3394-
"draw_if_interactive",
3395-
"show"]:
3387+
for name in [
3388+
"backend_version",
3389+
"FigureCanvas",
3390+
"FigureManager",
3391+
"new_figure_manager",
3392+
"new_figure_manager_given_figure",
3393+
"draw_if_interactive",
3394+
"show",
3395+
]:
33963396
setattr(sys.modules[cls.__module__], name, getattr(cls, name))
33973397

33983398
# For back-compatibility, generate a shim `Show` class.

lib/matplotlib/backends/_backend_tk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def _on_timer(self):
124124

125125

126126
class FigureCanvasTk(FigureCanvasBase):
127+
required_interactive_framework = "tk"
128+
127129
keyvald = {65507: 'control',
128130
65505: 'shift',
129131
65513: 'alt',
@@ -864,7 +866,6 @@ def trigger(self, *args):
864866

865867
@_Backend.export
866868
class _BackendTk(_Backend):
867-
required_interactive_framework = "tk"
868869
FigureManager = FigureManagerTk
869870

870871
@classmethod

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def _on_timer(self):
9797

9898

9999
class FigureCanvasGTK3(Gtk.DrawingArea, FigureCanvasBase):
100+
required_interactive_framework = "gtk3"
101+
100102
keyvald = {65507: 'control',
101103
65505: 'shift',
102104
65513: 'alt',
@@ -985,7 +987,6 @@ def error_msg_gtk(msg, parent=None):
985987

986988
@_Backend.export
987989
class _BackendGTK3(_Backend):
988-
required_interactive_framework = "gtk3"
989990
FigureCanvas = FigureCanvasGTK3
990991
FigureManager = FigureManagerGTK3
991992

lib/matplotlib/backends/backend_macosx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ class FigureCanvasMac(_macosx.FigureCanvas, FigureCanvasAgg):
5353
----------
5454
figure : `matplotlib.figure.Figure`
5555
A high-level Figure instance
56-
5756
"""
5857

58+
required_interactive_framework = "macosx"
59+
5960
def __init__(self, figure):
6061
FigureCanvasBase.__init__(self, figure)
6162
width, height = self.get_width_height()
@@ -172,7 +173,6 @@ def set_message(self, message):
172173

173174
@_Backend.export
174175
class _BackendMac(_Backend):
175-
required_interactive_framework = "macosx"
176176
FigureCanvas = FigureCanvasMac
177177
FigureManager = FigureManagerMac
178178

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from .backend_qt5 import (
22
backend_version, SPECIAL_KEYS, SUPER, ALT, CTRL, SHIFT, MODIFIER_KEYS,
3-
cursord, _create_qApp, _BackendQT5, TimerQT, MainWindow, FigureManagerQT,
4-
NavigationToolbar2QT, SubplotToolQt, error_msg_qt, exception_handler)
5-
from .backend_qt5 import FigureCanvasQT as FigureCanvasQT5
3+
cursord, _create_qApp, _BackendQT5, TimerQT, MainWindow, FigureCanvasQT,
4+
FigureManagerQT, NavigationToolbar2QT, SubplotToolQt, error_msg_qt,
5+
exception_handler)
66

77

88
@_BackendQT5.export
99
class _BackendQT4(_BackendQT5):
10-
required_interactive_framework = "qt4"
10+
class FigureCanvas(FigureCanvasQT):
11+
required_interactive_framework = "qt4"

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
@_BackendQT5Agg.export
1010
class _BackendQT4Agg(_BackendQT5Agg):
11-
required_interactive_framework = "qt4"
11+
class FigureCanvas(FigureCanvasQTAgg):
12+
required_interactive_framework = "qt4"
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from .backend_qt5cairo import _BackendQT5Cairo
1+
from .backend_qt5cairo import _BackendQT5Cairo, FigureCanvasQTCairo
22

33

44
@_BackendQT5Cairo.export
55
class _BackendQT4Cairo(_BackendQT5Cairo):
6-
required_interactive_framework = "qt4"
6+
class FigureCanvas(FigureCanvasQTCairo):
7+
required_interactive_framework = "qt4"

lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def _timer_stop(self):
215215

216216

217217
class FigureCanvasQT(QtWidgets.QWidget, FigureCanvasBase):
218+
required_interactive_framework = "qt5"
218219

219220
# map Qt button codes to MouseEvent's ones:
220221
buttond = {QtCore.Qt.LeftButton: MouseButton.LEFT,
@@ -1026,7 +1027,6 @@ def trigger(self, *args, **kwargs):
10261027

10271028
@_Backend.export
10281029
class _BackendQT5(_Backend):
1029-
required_interactive_framework = "qt5"
10301030
FigureCanvas = FigureCanvasQT
10311031
FigureManager = FigureManagerQT
10321032

lib/matplotlib/backends/backend_wx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel):
518518
we give a hint as to our preferred minimum size.
519519
"""
520520

521+
required_interactive_framework = "wx"
522+
521523
keyvald = {
522524
wx.WXK_CONTROL: 'control',
523525
wx.WXK_SHIFT: 'shift',
@@ -1889,7 +1891,6 @@ def OnPrintPage(self, page):
18891891

18901892
@_Backend.export
18911893
class _BackendWx(_Backend):
1892-
required_interactive_framework = "wx"
18931894
FigureCanvas = FigureCanvasWx
18941895
FigureManager = FigureManagerWx
18951896
_frame_class = FigureFrameWx

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def switch_backend(newbackend):
224224
_log.debug("Loaded backend %s version %s.",
225225
newbackend, Backend.backend_version)
226226

227-
required_framework = Backend.required_interactive_framework
227+
required_framework = getattr(
228+
Backend.FigureCanvas, "required_interactive_framework", None)
228229
if required_framework is not None:
229230
current_framework = \
230231
matplotlib.backends._get_running_interactive_framework()

0 commit comments

Comments
 (0)