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

Skip to content

Commit 5325b83

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. - _convert_agg_to_wx_image is unused; _WX28_clipped_agg_as_bitmap can reasonably be inlined into _convert_agg_to_wx_bitmap.
1 parent 7673002 commit 5325b83

File tree

9 files changed

+44
-109
lines changed

9 files changed

+44
-109
lines changed

doc/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Matplotlib documentation build configuration file, created by
42
# sphinx-quickstart on Fri May 2 12:33:25 2008.
53
#

doc/sphinxext/mock_gui_toolkits.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,13 @@ def getapi(*args):
113113

114114

115115
class MyWX(MagicMock):
116-
class Panel(object):
117-
pass
118-
119-
class ToolBar(object):
120-
pass
121-
122-
class Frame(object):
123-
pass
124-
116+
Frame = Panel = Printout = ToolBar = type("", (), {})
125117
VERSION_STRING = '2.9'
126118

127119

128120
def setup(app):
129121
sys.modules['cairocffi'] = MyCairoCffi()
122+
sys.modules['cairo'].__name__ = 'cairocffi'
130123
sys.modules['PyQt4'] = MyPyQt4()
131124
sys.modules['sip'] = MySip()
132125
sys.modules['wx'] = MyWX()

lib/matplotlib/backends/backend_agg.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,25 +417,21 @@ def restore_region(self, region, bbox=None, xy=None):
417417
return renderer.restore_region(region, bbox, xy)
418418

419419
def draw(self):
420-
"""
421-
Draw the figure using the renderer
422-
"""
420+
"""Draw the figure using the renderer."""
423421
self.renderer = self.get_renderer(cleared=True)
424-
# acquire a lock on the shared font cache
425-
RendererAgg.lock.acquire()
426-
427422
toolbar = self.toolbar
428423
try:
429424
# if toolbar:
430425
# toolbar.set_cursor(cursors.WAIT)
431-
self.figure.draw(self.renderer)
426+
with RendererAgg.lock:
427+
self.figure.draw(self.renderer)
432428
# A GUI class may be need to update a window using this draw, so
433429
# don't forget to call the superclass.
434430
super(FigureCanvasAgg, self).draw()
435431
finally:
436432
# if toolbar:
437433
# toolbar.set_cursor(toolbar._lastCursor)
438-
RendererAgg.lock.release()
434+
pass
439435

440436
def get_renderer(self, cleared=False):
441437
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
@@ -275,11 +275,8 @@ def on_draw_event(self, widget, ctx):
275275
pass
276276

277277
def draw(self):
278-
if self.get_visible() and self.get_mapped():
278+
if self.is_drawable():
279279
self.queue_draw()
280-
# do a synchronous draw (its less efficient than an async draw,
281-
# but is required if/when animation is used)
282-
self.get_property("window").process_updates (False)
283280

284281
def draw_idle(self):
285282
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
@@ -6,6 +6,7 @@
66
from . import backend_cairo, backend_gtk3
77
from .backend_cairo import cairo, HAS_CAIRO_CFFI
88
from .backend_gtk3 import _BackendGTK3
9+
from matplotlib import cbook
910
from matplotlib.backend_bases import cursors
1011

1112

@@ -45,11 +46,11 @@ def on_draw_event(self, widget, ctx):
4546
return False # finish event propagation?
4647

4748

49+
@cbook.deprecated("2.2", "backend_gtk3.FigureManagerGTK3")
4850
class FigureManagerGTK3Cairo(backend_gtk3.FigureManagerGTK3):
4951
pass
5052

5153

5254
@_BackendGTK3.export
5355
class _BackendGTK3Cairo(_BackendGTK3):
5456
FigureCanvas = FigureCanvasGTK3Cairo
55-
FigureManager = FigureManagerGTK3Cairo

lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
31
import six
42

53
import functools
64
import os
75
import re
86
import signal
97
import sys
10-
from six import unichr
118
import traceback
129

1310
import matplotlib
@@ -438,7 +435,7 @@ def _get_key(self, event):
438435
if event_key > MAX_UNICODE:
439436
return None
440437

441-
key = unichr(event_key)
438+
key = chr(event_key)
442439
# qt delivers capitalized letters. fix capitalization
443440
# note that capslock is ignored
444441
if 'shift' in mods:

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
"""
2-
Render to qt from agg
2+
Render to qt from agg.
33
"""
4-
from __future__ import (absolute_import, division, print_function,
5-
unicode_literals)
6-
74
import six
85

96
import ctypes
@@ -40,8 +37,8 @@ def paintEvent(self, e):
4037
return
4138
self._draw_idle() # Only does something if a draw is pending.
4239

43-
# if the canvas does not have a renderer, then give up and wait for
44-
# FigureCanvasAgg.draw(self) to be called
40+
# If the canvas does not have a renderer, then give up and wait for
41+
# FigureCanvasAgg.draw(self) to be called.
4542
if not hasattr(self, 'renderer'):
4643
return
4744

lib/matplotlib/backends/backend_wx.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
should be included with this source code.
1414
1515
"""
16-
from __future__ import (absolute_import, division, print_function,
17-
unicode_literals)
1816

1917
import six
20-
from six.moves import xrange
21-
import six
2218

23-
import sys
24-
import os
2519
import os.path
2620
import math
21+
import sys
2722
import weakref
2823
import warnings
2924

@@ -33,13 +28,13 @@
3328
NavigationToolbar2, RendererBase, TimerBase, cursors)
3429
from matplotlib.backend_bases import _has_pil
3530

31+
from matplotlib import cbook, rcParams, backend_tools
3632
from matplotlib._pylab_helpers import Gcf
3733
from matplotlib.cbook import is_writable_file_like, warn_deprecated
3834
from matplotlib.figure import Figure
3935
from matplotlib.path import Path
4036
from matplotlib.transforms import Affine2D
4137
from matplotlib.widgets import SubplotTool
42-
from matplotlib import cbook, rcParams, backend_tools
4338

4439
from . import wx_compat as wxc
4540
import wx
@@ -50,30 +45,25 @@
5045
# traceback is performed, and pdb activated, for all uncaught exceptions in
5146
# this case
5247
_DEBUG = 5
53-
if _DEBUG < 5:
54-
import traceback
55-
import pdb
5648
_DEBUG_lvls = {1: 'Low ', 2: 'Med ', 3: 'High', 4: 'Error'}
5749

5850

5951
def DEBUG_MSG(string, lvl=3, o=None):
6052
if lvl >= _DEBUG:
61-
cls = o.__class__
62-
# Jeremy, often times the commented line won't print but the
63-
# one below does. I think WX is redefining stderr, damned
64-
# beast
65-
# print("%s- %s in %s" % (_DEBUG_lvls[lvl], string, cls),
66-
# file=sys.stderr)
67-
print("%s- %s in %s" % (_DEBUG_lvls[lvl], string, cls))
53+
print("%s- %s in %s" % (_DEBUG_lvls[lvl], string, type(o)))
6854

6955

56+
@cbook.deprecated("2.2")
7057
def debug_on_error(type, value, tb):
7158
"""Code due to Thomas Heller - published in Python Cookbook (O'Reilley)"""
59+
import pdb
60+
import traceback
7261
traceback.print_exception(type, value, tb)
7362
print()
74-
pdb.pm() # jdh uncomment
63+
pdb.pm()
7564

7665

66+
@cbook.deprecated("2.2")
7767
class fake_stderr(object):
7868
"""
7969
Wx does strange things with stderr, as it makes the assumption that
@@ -108,6 +98,7 @@ def error_msg_wx(msg, parent=None):
10898
return None
10999

110100

101+
@cbook.deprecated("2.2")
111102
def raise_msg_to_str(msg):
112103
"""msg is a return arg from a raise. Join with new lines."""
113104
if not isinstance(msg, six.string_types):
@@ -1316,11 +1307,7 @@ def resize(self, width, height):
13161307
self.canvas.SetInitialSize(wx.Size(width, height))
13171308
self.window.GetSizer().Fit(self.window)
13181309

1319-
# Identifiers for toolbar controls - images_wx contains bitmaps for the images
1320-
# used in the controls. wxWindows does not provide any stock images, so I've
1321-
# 'stolen' those from GTK2, and transformed them into the appropriate format.
1322-
# import images_wx
1323-
1310+
# Identifiers for toolbar controls.
13241311

13251312
_NTB_AXISMENU = wx.NewId()
13261313
_NTB_AXISMENU_BUTTON = wx.NewId()
@@ -1332,7 +1319,6 @@ def resize(self, width, height):
13321319
_NTB_Y_PAN_DOWN = wx.NewId()
13331320
_NTB_Y_ZOOMIN = wx.NewId()
13341321
_NTB_Y_ZOOMOUT = wx.NewId()
1335-
# _NTB_SUBPLOT =wx.NewId()
13361322
_NTB_SAVE = wx.NewId()
13371323
_NTB_CLOSE = wx.NewId()
13381324

@@ -1437,7 +1423,7 @@ def updateAxes(self, maxAxis):
14371423
"""Ensures that there are entries for max_axis axes in the menu
14381424
(selected by default)."""
14391425
if maxAxis > len(self._axisId):
1440-
for i in range(len(self._axisId) + 1, maxAxis + 1, 1):
1426+
for i in range(len(self._axisId) + 1, maxAxis + 1):
14411427
menuId = wx.NewId()
14421428
self._axisId.append(menuId)
14431429
self._menu.Append(menuId, "Axis %d" % i,
@@ -1449,7 +1435,7 @@ def updateAxes(self, maxAxis):
14491435
for menuId in self._axisId[maxAxis:]:
14501436
self._menu.Delete(menuId)
14511437
self._axisId = self._axisId[:maxAxis]
1452-
self._toolbar.set_active(list(xrange(maxAxis)))
1438+
self._toolbar.set_active(range(maxAxis))
14531439

14541440
def getActiveAxes(self):
14551441
"""Return a list of the selected axes."""
@@ -1870,6 +1856,7 @@ def remove_rubberband(self, dc=None):
18701856

18711857
# < Additions for printing support: Matt Newville
18721858

1859+
@cbook.deprecated("2.2")
18731860
class PrintoutWx(wx.Printout):
18741861
"""
18751862
Simple wrapper around wx Printout class -- all the real work
@@ -1954,7 +1941,7 @@ def OnPrintPage(self, page):
19541941
self.canvas.figure.dpi = fig_dpi
19551942
self.canvas.draw()
19561943
return True
1957-
# >
1944+
19581945

19591946
########################################################################
19601947
#

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
3-
41
import six
52

63
import wx
@@ -68,33 +65,14 @@ def blit(self, bbox=None):
6865
srcDC.SelectObject(wx.NullBitmap)
6966
self.gui_repaint()
7067

71-
filetypes = FigureCanvasAgg.filetypes
72-
7368

7469
@cbook.deprecated("2.2")
7570
class NavigationToolbar2WxAgg(NavigationToolbar2Wx):
7671
def get_canvas(self, frame, fig):
7772
return FigureCanvasWxAgg(frame, -1, fig)
7873

7974

80-
# agg/wxPython image conversion functions (wxPython >= 2.8)
81-
82-
83-
def _convert_agg_to_wx_image(agg, bbox):
84-
"""
85-
Convert the region of the agg buffer bounded by bbox to a wx.Image. If
86-
bbox is None, the entire buffer is converted.
87-
88-
Note: agg must be a backend_agg.RendererAgg instance.
89-
"""
90-
if bbox is None:
91-
# agg => rgb -> image
92-
image = wxc.EmptyImage(int(agg.width), int(agg.height))
93-
image.SetData(agg.tostring_rgb())
94-
return image
95-
else:
96-
# agg => rgba buffer -> bitmap => clipped bitmap => image
97-
return wx.ImageFromBitmap(_WX28_clipped_agg_as_bitmap(agg, bbox))
75+
# agg/wxPython image conversion functions.
9876

9977

10078
def _convert_agg_to_wx_bitmap(agg, bbox):
@@ -110,36 +88,27 @@ def _convert_agg_to_wx_bitmap(agg, bbox):
11088
agg.buffer_rgba())
11189
else:
11290
# agg => rgba buffer -> bitmap => clipped bitmap
113-
return _WX28_clipped_agg_as_bitmap(agg, bbox)
114-
91+
l, b, width, height = bbox.bounds
92+
r = l + width
93+
t = b + height
11594

116-
def _WX28_clipped_agg_as_bitmap(agg, bbox):
117-
"""
118-
Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.
119-
120-
Note: agg must be a backend_agg.RendererAgg instance.
121-
"""
122-
l, b, width, height = bbox.bounds
123-
r = l + width
124-
t = b + height
125-
126-
srcBmp = wxc.BitmapFromBuffer(int(agg.width), int(agg.height),
127-
agg.buffer_rgba())
128-
srcDC = wx.MemoryDC()
129-
srcDC.SelectObject(srcBmp)
95+
srcBmp = wxc.BitmapFromBuffer(int(agg.width), int(agg.height),
96+
agg.buffer_rgba())
97+
srcDC = wx.MemoryDC()
98+
srcDC.SelectObject(srcBmp)
13099

131-
destBmp = wxc.EmptyBitmap(int(width), int(height))
132-
destDC = wx.MemoryDC()
133-
destDC.SelectObject(destBmp)
100+
destBmp = wxc.EmptyBitmap(int(width), int(height))
101+
destDC = wx.MemoryDC()
102+
destDC.SelectObject(destBmp)
134103

135-
x = int(l)
136-
y = int(int(agg.height) - t)
137-
destDC.Blit(0, 0, int(width), int(height), srcDC, x, y)
104+
x = int(l)
105+
y = int(int(agg.height) - t)
106+
destDC.Blit(0, 0, int(width), int(height), srcDC, x, y)
138107

139-
srcDC.SelectObject(wx.NullBitmap)
140-
destDC.SelectObject(wx.NullBitmap)
108+
srcDC.SelectObject(wx.NullBitmap)
109+
destDC.SelectObject(wx.NullBitmap)
141110

142-
return destBmp
111+
return destBmp
143112

144113

145114
@_BackendWx.export

0 commit comments

Comments
 (0)