backend_gtk3cairo.py 967 B

1234567891011121314151617181920212223242526
  1. from contextlib import nullcontext
  2. from .backend_cairo import FigureCanvasCairo
  3. from .backend_gtk3 import Gtk, FigureCanvasGTK3, _BackendGTK3
  4. class FigureCanvasGTK3Cairo(FigureCanvasCairo, FigureCanvasGTK3):
  5. def on_draw_event(self, widget, ctx):
  6. with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
  7. else nullcontext()):
  8. self._renderer.set_context(ctx)
  9. scale = self.device_pixel_ratio
  10. # Scale physical drawing to logical size.
  11. ctx.scale(1 / scale, 1 / scale)
  12. allocation = self.get_allocation()
  13. Gtk.render_background(
  14. self.get_style_context(), ctx,
  15. allocation.x, allocation.y,
  16. allocation.width, allocation.height)
  17. self._renderer.dpi = self.figure.dpi
  18. self.figure.draw(self._renderer)
  19. @_BackendGTK3.export
  20. class _BackendGTK3Cairo(_BackendGTK3):
  21. FigureCanvas = FigureCanvasGTK3Cairo