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

Skip to content

Commit 6821ad2

Browse files
committed
WXCairo backend.
1 parent 2274725 commit 6821ad2

File tree

7 files changed

+73
-8
lines changed

7 files changed

+73
-8
lines changed

doc/api/backend_wxcairo_api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
:mod:`matplotlib.backends.backend_wxcairo`
3+
==========================================
4+
5+
.. automodule:: matplotlib.backends.backend_wxcairo
6+
:members:
7+
:undoc-members:
8+
:show-inheritance:

doc/api/index_backend_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ backends
2626
backend_tkagg_api.rst
2727
backend_webagg_api.rst
2828
backend_wxagg_api.rst
29+
backend_wxcairo_api.rst

doc/users/whats_new/more-cairo.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cairo rendering for Qt and WX canvases
2+
--------------------------------------
3+
4+
The new ``Qt4Cairo``, ``Qt5Cairo``, and ``WXCairo`` backends allow Qt and WX
5+
canvases to use cairo rendering instead of Agg.

doc/users/whats_new/qtcairo.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import six
5+
6+
from .backend_cairo import cairo, FigureCanvasCairo, RendererCairo
7+
from .backend_wx import (
8+
_BackendWx, _FigureCanvasWxBase, FigureFrameWx, NavigationToolbar2Wx)
9+
10+
import wx
11+
12+
13+
class FigureFrameWxCairo(FigureFrameWx):
14+
def get_canvas(self, fig):
15+
return FigureCanvasWxCairo(self, -1, fig)
16+
17+
18+
class FigureCanvasWxCairo(_FigureCanvasWxBase, FigureCanvasCairo):
19+
"""
20+
The FigureCanvas contains the figure and does event handling.
21+
22+
In the wxPython backend, it is derived from wxPanel, and (usually) lives
23+
inside a frame instantiated by a FigureManagerWx. The parent window
24+
probably implements a wxSizer to control the displayed control size - but
25+
we give a hint as to our preferred minimum size.
26+
"""
27+
28+
def __init__(self, parent, id, figure):
29+
# _FigureCanvasWxBase should be fixed to have the same signature as
30+
# every other FigureCanvas and use cooperative inheritance, but in the
31+
# meantime the following will make do.
32+
_FigureCanvasWxBase.__init__(self, parent, id, figure)
33+
FigureCanvasCairo.__init__(self, figure)
34+
self._renderer = RendererCairo(self.figure.dpi)
35+
36+
def draw(self, drawDC=None):
37+
FigureCanvasCairo.draw(self)
38+
width = int(self.figure.bbox.width)
39+
height = int(self.figure.bbox.height)
40+
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
41+
self._renderer.set_ctx_from_surface(surface)
42+
self._renderer.set_width_height(width, height)
43+
self.figure.draw(self._renderer)
44+
buf = surface.get_data()
45+
self.bitmap = wx.Bitmap.FromBufferRGBA(width, height, buf)
46+
self._isDrawn = True
47+
self.gui_repaint(drawDC=drawDC, origin='WXCairo')
48+
49+
50+
@_BackendWx.export
51+
class _BackendWxCairo(_BackendWx):
52+
FigureCanvas = FigureCanvasWxCairo
53+
_frame_class = FigureFrameWxCairo

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo',
4040
'TkAgg',
4141
'WebAgg',
42-
'WX', 'WXAgg']
42+
'WX', 'WXAgg', 'WXCairo']
4343
non_interactive_bk = ['agg', 'cairo', 'gdk',
4444
'pdf', 'pgf', 'ps', 'svg', 'template']
4545
all_backends = interactive_bk + non_interactive_bk

tutorials/introductory/usage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,12 @@ def my_plotter(ax, data1, data2, param_dict):
446446
# activated in IPython with ``%matplotlib gtk``.
447447
# GTKCairo Cairo rendering to a :term:`GTK` 2.x canvas (requires PyGTK_,
448448
# and pycairo_ or cairocffi_; Python2 only).
449-
# WXAgg Agg rendering to a :term:`wxWidgets` canvas (requires wxPython_;
449+
# WXAgg Agg rendering to a :term:`wxWidgets` canvas (requires wxPython_ --
450450
# v4.0 (in beta) is required for Python3). This backend can be
451-
# activated in IPython with ``%matplotlib wx``.#
451+
# activated in IPython with ``%matplotlib wx``.
452+
# WXCairo Cairo rendering to a :term:`wxWidgets` canvas (requires wxPython_
453+
# -- v4.0 (in beta) is required for Python3, and pycairo_ or
454+
# cairocffi_).
452455
# ========= ================================================================
453456
#
454457
# .. _`Anti-Grain Geometry`: http://antigrain.com/

0 commit comments

Comments
 (0)