backend_gtk4cairo.py 998 B

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