Skip to content

Backport PR #27988 on branch v3.8.x (gtk: Ensure pending draws are done before GTK draw) #27990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_gtk3agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .. import cbook, transforms
from . import backend_agg, backend_gtk3
from .backend_gtk3 import Gtk, _BackendGTK3
from .backend_gtk3 import GLib, Gtk, _BackendGTK3

import cairo # Presence of cairo is already checked by _backend_gtk.

Expand All @@ -14,6 +14,11 @@ def __init__(self, figure):
self._bbox_queue = []

def on_draw_event(self, widget, ctx):
if self._idle_draw_id:
GLib.source_remove(self._idle_draw_id)
self._idle_draw_id = 0
self.draw()

scale = self.device_pixel_ratio
allocation = self.get_allocation()
w = allocation.width * scale
Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_gtk3cairo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from contextlib import nullcontext

from .backend_cairo import FigureCanvasCairo
from .backend_gtk3 import Gtk, FigureCanvasGTK3, _BackendGTK3
from .backend_gtk3 import GLib, Gtk, FigureCanvasGTK3, _BackendGTK3


class FigureCanvasGTK3Cairo(FigureCanvasCairo, FigureCanvasGTK3):
def on_draw_event(self, widget, ctx):
if self._idle_draw_id:
GLib.source_remove(self._idle_draw_id)
self._idle_draw_id = 0
self.draw()

with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
else nullcontext()):
self._renderer.set_context(ctx)
Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_gtk4agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .. import cbook
from . import backend_agg, backend_gtk4
from .backend_gtk4 import Gtk, _BackendGTK4
from .backend_gtk4 import GLib, Gtk, _BackendGTK4

import cairo # Presence of cairo is already checked by _backend_gtk.

Expand All @@ -11,6 +11,11 @@ class FigureCanvasGTK4Agg(backend_agg.FigureCanvasAgg,
backend_gtk4.FigureCanvasGTK4):

def on_draw_event(self, widget, ctx):
if self._idle_draw_id:
GLib.source_remove(self._idle_draw_id)
self._idle_draw_id = 0
self.draw()

scale = self.device_pixel_ratio
allocation = self.get_allocation()

Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_gtk4cairo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from contextlib import nullcontext

from .backend_cairo import FigureCanvasCairo
from .backend_gtk4 import Gtk, FigureCanvasGTK4, _BackendGTK4
from .backend_gtk4 import GLib, Gtk, FigureCanvasGTK4, _BackendGTK4


class FigureCanvasGTK4Cairo(FigureCanvasCairo, FigureCanvasGTK4):
_context_is_scaled = True

def on_draw_event(self, widget, ctx):
if self._idle_draw_id:
GLib.source_remove(self._idle_draw_id)
self._idle_draw_id = 0
self.draw()

with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
else nullcontext()):
self._renderer.set_context(ctx)
Expand Down
Loading