From 2f725a68a9f90f8e5f953ddde65e68eed5b69a71 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 20 Jul 2020 17:17:38 -0400 Subject: [PATCH] gtk: Fix `draw` on unmapped windows. Most other backends do not skip drawing on unmapped windows; this skip causes explicit draws to do nothing and breaks things that expect it to work. For example, the `TextBox` example broke since the widget was changed to set text before showing the window. This required drawing to work in order to measure text size and place the caret. --- lib/matplotlib/backends/backend_gtk3.py | 6 ++++-- lib/matplotlib/backends/backend_gtk3agg.py | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index c9094eb1df33..52386d7b5bfd 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -539,8 +539,10 @@ def set_message(self, s): self.message.set_label(s) def set_cursor(self, cursor): - self.canvas.get_property("window").set_cursor(cursord[cursor]) - Gtk.main_iteration() + window = self.canvas.get_property("window") + if window is not None: + window.set_cursor(cursord[cursor]) + Gtk.main_iteration() def draw_rubberband(self, event, x0, y0, x1, y1): height = self.canvas.figure.bbox.height diff --git a/lib/matplotlib/backends/backend_gtk3agg.py b/lib/matplotlib/backends/backend_gtk3agg.py index 5e26ff385282..ecd15327aa02 100644 --- a/lib/matplotlib/backends/backend_gtk3agg.py +++ b/lib/matplotlib/backends/backend_gtk3agg.py @@ -67,8 +67,7 @@ def blit(self, bbox=None): self.queue_draw_area(x, y, width, height) def draw(self): - if self.get_visible() and self.get_mapped(): - backend_agg.FigureCanvasAgg.draw(self) + backend_agg.FigureCanvasAgg.draw(self) super().draw() def print_png(self, filename, *args, **kwargs):