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

Skip to content

Commit b426599

Browse files
committed
Various backend cleanups.
Split out from the qt5cairo and wxcairo PRs. - GTK3: is_drawable is the same as mapped & visible (https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-is-drawable) - Synchronous draw appears unnecessary on GTK3 based on tests (probably was only needed in early animation code). - Most of the Wx printout code has been removed in 84ffb60; this PR just deprecates some remnants of it. MenuButtonWx is likewise unused since the removal of "classic" toolbars in 4243470; this PR deprecates it. - Don't initialize the wx statusbar to "None" (which just looks strange) -- other backends just start with an empty status text. - _convert_agg_to_wx_image is unused; _WX28_clipped_agg_as_bitmap can reasonably be inlined into _convert_agg_to_wx_bitmap. - Remove some unused private tk apis. - Simplify toolkit mocking in the docs. In particular pycairo is Py3-compatible only since 1.11.0 so the version_check is unneeded. - Removed the old list of deprecations (18-02-15) that has already been integrated into the 3.0 release notes in favor of a new list (for 3.1).
1 parent f1b64ad commit b426599

12 files changed

+59
-199
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ per-file-ignores =
3131
matplotlib/_cm.py: E202, E203, E302
3232
matplotlib/_mathtext_data.py: E203, E261
3333
matplotlib/backend_bases.py: E225
34-
matplotlib/backends/_backend_tk.py: E203, E222, E225, E231, E271, E301, E303, E401, E501, E701
34+
matplotlib/backends/_backend_tk.py: E203, E222, E225, E231, E271, E301, E303, E501, E701
3535
matplotlib/backends/backend_agg.py: E261, E302, E701
3636
matplotlib/backends/backend_cairo.py: E203, E221, E261, E303, E402, E711
3737
matplotlib/backends/backend_gtk3.py: E203, E221, E222, E225, E251, E261, E501

doc/api/api_changes/2018-08-17-AL-deprecations.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ API deprecations
33

44
The following API elements are deprecated:
55

6+
- ``backend_gtk3cairo.FigureCanvasGTK3Cairo``,
7+
- ``backend_wx.debug_on_error``, ``backend_wx.fake_stderr``,
8+
``backend_wx.raise_msg_to_str``, ``backend_wx.MenuButtonWx``,
9+
``backend_wx.PrintoutWx``,
610
- ``tk_window_focus``,
711
- ``mlab.demean``,

doc/api/backend_wxagg_api.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
:mod:`matplotlib.backends.backend_wxagg`
33
========================================
44

5-
.. automodule:: matplotlib.backends.backend_wxagg
6-
:members:
7-
:undoc-members:
8-
:show-inheritance:
5+
**NOTE** Not included, to avoid adding a dependency to building the docs.
6+
7+
.. .. automodule:: matplotlib.backends.backend_wxagg
8+
.. :members:
9+
.. :undoc-members:
10+
.. :show-inheritance:

doc/api/next_api_changes/2018-02-15-AL-deprecations.rst

Lines changed: 0 additions & 59 deletions
This file was deleted.

doc/sphinxext/mock_gui_toolkits.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,8 @@ class MyCairoCffi(MagicMock):
66
__name__ = "cairocffi"
77

88

9-
class MyWX(MagicMock):
10-
class Panel(object):
11-
pass
12-
13-
class ToolBar(object):
14-
pass
15-
16-
class Frame(object):
17-
pass
18-
19-
class StatusBar(object):
20-
pass
21-
22-
239
def setup(app):
2410
sys.modules.update(
2511
cairocffi=MyCairoCffi(),
26-
wx=MyWX(),
2712
)
2813
return {'parallel_read_safe': True, 'parallel_write_safe': True}

lib/matplotlib/backends/_backend_tk.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import math
1+
from contextlib import contextmanager
22
import logging
3+
import math
34
import os.path
45
import sys
56
import tkinter as Tk
67
from tkinter.simpledialog import SimpleDialog
7-
from contextlib import contextmanager
8+
import tkinter.filedialog
9+
import tkinter.messagebox
810

911
import numpy as np
1012

11-
from . import _tkagg
12-
1313
import matplotlib
14-
from matplotlib import backend_tools, rcParams
14+
from matplotlib import backend_tools, cbook, rcParams
1515
from matplotlib.backend_bases import (
1616
_Backend, FigureCanvasBase, FigureManagerBase, NavigationToolbar2,
1717
StatusbarBase, TimerBase, ToolContainerBase, cursors)
1818
from matplotlib.backend_managers import ToolManager
1919
from matplotlib._pylab_helpers import Gcf
2020
from matplotlib.figure import Figure
2121
from matplotlib.widgets import SubplotTool
22+
from . import _tkagg
2223

2324
try:
2425
from matplotlib._windowing import GetForegroundWindow, SetForegroundWindow
@@ -54,18 +55,6 @@ def _restore_foreground_window_at_end():
5455
}
5556

5657

57-
def raise_msg_to_str(msg):
58-
"""msg is a return arg from a raise. Join with new lines"""
59-
if not isinstance(msg, str):
60-
msg = '\n'.join(map(str, msg))
61-
return msg
62-
63-
64-
def error_msg_tkpaint(msg, parent=None):
65-
import tkinter.messagebox
66-
tkinter.messagebox.showerror("matplotlib", msg)
67-
68-
6958
def blit(photoimage, aggimage, offsets, bbox=None):
7059
"""
7160
Blit *aggimage* to *photoimage*.
@@ -686,7 +675,6 @@ def configure_subplots(self):
686675
window.grab_set()
687676

688677
def save_figure(self, *args):
689-
import tkinter.filedialog, tkinter.messagebox
690678
filetypes = self.canvas.get_supported_filetypes().copy()
691679
default_filetype = self.canvas.get_default_filetype()
692680

@@ -906,7 +894,6 @@ def set_message(self, s):
906894

907895
class SaveFigureTk(backend_tools.SaveFigureBase):
908896
def trigger(self, *args):
909-
import tkinter.filedialog, tkinter.messagebox
910897
filetypes = self.figure.canvas.get_supported_filetypes().copy()
911898
default_filetype = self.figure.canvas.get_default_filetype()
912899

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,11 @@ def draw(self):
394394
Draw the figure using the renderer.
395395
"""
396396
self.renderer = self.get_renderer(cleared=True)
397-
# acquire a lock on the shared font cache
398-
RendererAgg.lock.acquire()
399-
400-
toolbar = self.toolbar
401-
try:
397+
with RendererAgg.lock:
402398
self.figure.draw(self.renderer)
403-
# A GUI class may be need to update a window using this draw, so
404-
# don't forget to call the superclass.
399+
# A GUI class may be need to update a window using this draw,
400+
# so don't forget to call the superclass.
405401
super().draw()
406-
finally:
407-
RendererAgg.lock.release()
408402

409403
def get_renderer(self, cleared=False):
410404
l, b, w, h = self.figure.bbox.bounds

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,8 @@ def on_draw_event(self, widget, ctx):
278278
pass
279279

280280
def draw(self):
281-
if self.get_visible() and self.get_mapped():
281+
if self.is_drawable():
282282
self.queue_draw()
283-
# do a synchronous draw (its less efficient than an async draw,
284-
# but is required if/when animation is used)
285-
self.get_property("window").process_updates(False)
286283

287284
def draw_idle(self):
288285
if self._idle_draw_id != 0:

lib/matplotlib/backends/backend_gtk3cairo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from . import backend_cairo, backend_gtk3
22
from ._gtk3_compat import gi
33
from .backend_gtk3 import Gtk, _BackendGTK3
4+
from matplotlib import cbook
45
from matplotlib.backend_bases import cursors
56

67

@@ -36,11 +37,11 @@ def on_draw_event(self, widget, ctx):
3637
return False # finish event propagation?
3738

3839

40+
@cbook.deprecated("3.1", "backend_gtk3.FigureManagerGTK3")
3941
class FigureManagerGTK3Cairo(backend_gtk3.FigureManagerGTK3):
4042
pass
4143

4244

4345
@_BackendGTK3.export
4446
class _BackendGTK3Cairo(_BackendGTK3):
4547
FigureCanvas = FigureCanvasGTK3Cairo
46-
FigureManager = FigureManagerGTK3Cairo

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Render to qt from agg
2+
Render to qt from agg.
33
"""
44

55
import ctypes
@@ -31,8 +31,8 @@ def paintEvent(self, event):
3131
return
3232
self._draw_idle() # Only does something if a draw is pending.
3333

34-
# if the canvas does not have a renderer, then give up and wait for
35-
# FigureCanvasAgg.draw(self) to be called
34+
# If the canvas does not have a renderer, then give up and wait for
35+
# FigureCanvasAgg.draw(self) to be called.
3636
if not hasattr(self, 'renderer'):
3737
return
3838

0 commit comments

Comments
 (0)