Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2227d9f

Browse filesBrowse files
committed
gtk: Ensure pending draws are done before GTK draw
Originally, the resize event happens first, adds an idle draw callback, and then the widget draws itself. Since the draw callback only happens when _idle_, it happens after the draw, so the figure appears blank. After the mouse is released, the idle draw callback fires, and the figure appears again. This is already done in the Qt backend [1], and doing so ensures the figure remains visible during resizes with the mouse. [1] https://github.com/matplotlib/matplotlib/blob/0afc5d6ca49cf6e8aa1da76b5bab0faca2f340f2/lib/matplotlib/backends/backend_qtagg.py#L25
1 parent 0afc5d6 commit 2227d9f
Copy full SHA for 2227d9f

File tree

Expand file treeCollapse file tree

4 files changed

+24
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+24
-4
lines changed

‎lib/matplotlib/backends/backend_gtk3agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3agg.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .. import cbook, transforms
44
from . import backend_agg, backend_gtk3
5-
from .backend_gtk3 import Gtk, _BackendGTK3
5+
from .backend_gtk3 import GLib, Gtk, _BackendGTK3
66

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

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

1616
def on_draw_event(self, widget, ctx):
17+
if self._idle_draw_id:
18+
GLib.source_remove(self._idle_draw_id)
19+
self._idle_draw_id = 0
20+
self.draw()
21+
1722
scale = self.device_pixel_ratio
1823
allocation = self.get_allocation()
1924
w = allocation.width * scale

‎lib/matplotlib/backends/backend_gtk3cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3cairo.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
from contextlib import nullcontext
22

33
from .backend_cairo import FigureCanvasCairo
4-
from .backend_gtk3 import Gtk, FigureCanvasGTK3, _BackendGTK3
4+
from .backend_gtk3 import GLib, Gtk, FigureCanvasGTK3, _BackendGTK3
55

66

77
class FigureCanvasGTK3Cairo(FigureCanvasCairo, FigureCanvasGTK3):
88
def on_draw_event(self, widget, ctx):
9+
if self._idle_draw_id:
10+
GLib.source_remove(self._idle_draw_id)
11+
self._idle_draw_id = 0
12+
self.draw()
13+
914
with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
1015
else nullcontext()):
1116
self._renderer.set_context(ctx)

‎lib/matplotlib/backends/backend_gtk4agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk4agg.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .. import cbook
44
from . import backend_agg, backend_gtk4
5-
from .backend_gtk4 import Gtk, _BackendGTK4
5+
from .backend_gtk4 import GLib, Gtk, _BackendGTK4
66

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

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

1313
def on_draw_event(self, widget, ctx):
14+
if self._idle_draw_id:
15+
GLib.source_remove(self._idle_draw_id)
16+
self._idle_draw_id = 0
17+
self.draw()
18+
1419
scale = self.device_pixel_ratio
1520
allocation = self.get_allocation()
1621

‎lib/matplotlib/backends/backend_gtk4cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk4cairo.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
from contextlib import nullcontext
22

33
from .backend_cairo import FigureCanvasCairo
4-
from .backend_gtk4 import Gtk, FigureCanvasGTK4, _BackendGTK4
4+
from .backend_gtk4 import GLib, Gtk, FigureCanvasGTK4, _BackendGTK4
55

66

77
class FigureCanvasGTK4Cairo(FigureCanvasCairo, FigureCanvasGTK4):
88
_context_is_scaled = True
99

1010
def on_draw_event(self, widget, ctx):
11+
if self._idle_draw_id:
12+
GLib.source_remove(self._idle_draw_id)
13+
self._idle_draw_id = 0
14+
self.draw()
15+
1116
with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
1217
else nullcontext()):
1318
self._renderer.set_context(ctx)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.