|
| 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 |
0 commit comments