backend_tkcairo.py 845 B

1234567891011121314151617181920212223242526
  1. import sys
  2. import numpy as np
  3. from . import _backend_tk
  4. from .backend_cairo import cairo, FigureCanvasCairo
  5. from ._backend_tk import _BackendTk, FigureCanvasTk
  6. class FigureCanvasTkCairo(FigureCanvasCairo, FigureCanvasTk):
  7. def draw(self):
  8. width = int(self.figure.bbox.width)
  9. height = int(self.figure.bbox.height)
  10. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
  11. self._renderer.set_context(cairo.Context(surface))
  12. self._renderer.dpi = self.figure.dpi
  13. self.figure.draw(self._renderer)
  14. buf = np.reshape(surface.get_data(), (height, width, 4))
  15. _backend_tk.blit(
  16. self._tkphoto, buf,
  17. (2, 1, 0, 3) if sys.byteorder == "little" else (1, 2, 3, 0))
  18. @_BackendTk.export
  19. class _BackendTkCairo(_BackendTk):
  20. FigureCanvas = FigureCanvasTkCairo