From f673efc2094fa9173eb4485fcf885de79fafed0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Sepp=C3=A4nen?= Date: Sun, 2 Aug 2020 11:23:55 +0300 Subject: [PATCH] Backport PR #17989: gtk/tk: Ensure no flicker when hovering over images. --- lib/matplotlib/backends/_backend_tk.py | 8 ++++++++ lib/matplotlib/backends/backend_gtk3.py | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 02062d39a5a1..49b28532d223 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -518,6 +518,14 @@ def __init__(self, canvas, window, *, pack_toolbar=True): if tooltip_text is not None: ToolTip.createToolTip(button, tooltip_text) + # This filler item ensures the toolbar is always at least two text + # lines high. Otherwise the canvas gets redrawn as the mouse hovers + # over images because those use two-line messages which resize the + # toolbar. + label = tk.Label(master=self, + text='\N{NO-BREAK SPACE}\n\N{NO-BREAK SPACE}') + label.pack(side=tk.RIGHT) + self.message = tk.StringVar(master=self) self._message_label = tk.Label(master=self, textvariable=self.message) self._message_label.pack(side=tk.RIGHT) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index fa1a507a2c39..009bb8097522 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -521,6 +521,17 @@ def __init__(self, canvas, window): toolitem.set_draw(False) toolitem.set_expand(True) + # This filler item ensures the toolbar is always at least two text + # lines high. Otherwise the canvas gets redrawn as the mouse hovers + # over images because those use two-line messages which resize the + # toolbar. + toolitem = Gtk.ToolItem() + self.insert(toolitem, -1) + label = Gtk.Label() + label.set_markup( + '\N{NO-BREAK SPACE}\n\N{NO-BREAK SPACE}') + toolitem.add(label) + toolitem = Gtk.ToolItem() self.insert(toolitem, -1) self.message = Gtk.Label() @@ -536,7 +547,8 @@ def ctx(self): return self.canvas.get_property("window").cairo_create() def set_message(self, s): - self.message.set_label(s) + escaped = GLib.markup_escape_text(s) + self.message.set_markup(f'{escaped}') def set_cursor(self, cursor): window = self.canvas.get_property("window")