Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c55901

Browse files
authored
Merge pull request #17989 from QuLogic/toolbar-flicker
gtk/tk: Ensure no flicker when hovering over images.
2 parents b38a870 + 7803062 commit 1c55901

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,14 @@ def __init__(self, canvas, window, *, pack_toolbar=True):
512512
if tooltip_text is not None:
513513
ToolTip.createToolTip(button, tooltip_text)
514514

515+
# This filler item ensures the toolbar is always at least two text
516+
# lines high. Otherwise the canvas gets redrawn as the mouse hovers
517+
# over images because those use two-line messages which resize the
518+
# toolbar.
519+
label = tk.Label(master=self,
520+
text='\N{NO-BREAK SPACE}\n\N{NO-BREAK SPACE}')
521+
label.pack(side=tk.RIGHT)
522+
515523
self.message = tk.StringVar(master=self)
516524
self._message_label = tk.Label(master=self, textvariable=self.message)
517525
self._message_label.pack(side=tk.RIGHT)

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,17 @@ def __init__(self, canvas, window):
521521
toolitem.set_draw(False)
522522
toolitem.set_expand(True)
523523

524+
# This filler item ensures the toolbar is always at least two text
525+
# lines high. Otherwise the canvas gets redrawn as the mouse hovers
526+
# over images because those use two-line messages which resize the
527+
# toolbar.
528+
toolitem = Gtk.ToolItem()
529+
self.insert(toolitem, -1)
530+
label = Gtk.Label()
531+
label.set_markup(
532+
'<small>\N{NO-BREAK SPACE}\n\N{NO-BREAK SPACE}</small>')
533+
toolitem.add(label)
534+
524535
toolitem = Gtk.ToolItem()
525536
self.insert(toolitem, -1)
526537
self.message = Gtk.Label()
@@ -536,7 +547,8 @@ def ctx(self):
536547
return self.canvas.get_property("window").cairo_create()
537548

538549
def set_message(self, s):
539-
self.message.set_label(s)
550+
escaped = GLib.markup_escape_text(s)
551+
self.message.set_markup(f'<small>{escaped}</small>')
540552

541553
def set_cursor(self, cursor):
542554
window = self.canvas.get_property("window")

0 commit comments

Comments
 (0)