10000 Simplify tk tooltip setup. by anntzer · Pull Request #19011 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Simplify tk tooltip setup. #19011

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
merged 1 commit into from
Nov 24, 2023
Merged

Simplify tk tooltip setup. #19011

merged 1 commit into from
Nov 24, 2023

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Nov 25, 2020

The whole module is private, so we can just clean it up directly.

Instead of creating and hiding a new tip window each time, we can just
create a single one and show/hide it as needed.

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@QuLogic
Copy link
Member
QuLogic commented Dec 23, 2020

This causes some kind of deadlock if you mouse over buttons too quickly. I just moved left and right over the pan/zoom buttons and it reacts slower and slower until one of the tooltips stays visible and it stops changing to any other one. Sometimes it will unfreeze but going back over something else will get stuck again.

@anntzer
Copy link
Contributor Author
anntzer commented Dec 24, 2020

I can't seem to repro this, either on Arch or on Fedora... do you have a screencast?

@QuLogic
Copy link
Member
QuLogic commented Dec 24, 2020

This one is on master:

Screencast-master.mp4

Tooltips swap around fluidly and disappear as necessary.

This one is on this branch:

Screencast-tooltip.mp4

Whenever the tooltip shows up, it randomly causes freezes and mouse jitteriness.

@anntzer
Copy link
Contributor Author
anntzer commented Dec 26, 2020

Ah, you may be using Wayland? I can indeed repro with Wayland, not with X... I'll investigate more; let's convert to draft for now.

@anntzer anntzer marked this pull request as draft December 26, 2020 13:44
@QuLogic
Copy link
Member
QuLogic commented Jan 4, 2021

Yes I am; maybe this is an XWayland bug too?

@anntzer
Copy link
Contributor Author
anntzer commented Jan 4, 2021

Indeed, this was easy enough to repro independently of matplotlib:

import tkinter as tk

root = tk.Tk()

w = tk.Toplevel(root)
w.withdraw()

def enter(e):
    x = root.winfo_rootx()
    y = root.winfo_rooty()
    w.geometry(f"+{x+25}+{y+25}")  # overlapping windows => very slow
    # w.geometry(f"+{x+300}+{y+300}")  # non overlapping => no problem
    w.deiconify()

def leave(e):
    w.withdraw()

root.bind("<Enter>", enter)
root.bind("<Leave>", leave)

root.mainloop()

Do you have experience interacting with the wayland devs (I personally don't use wayland at all...)? If so can you report this to them? Otherwise I'll open an issue myself...

@github-actions
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Sep 15, 2023
@anntzer
Copy link
Contributor Author
anntzer commented Sep 15, 2023

OK, I went for a much less extensive cleanup, basically keeping the old logic. The new commit message:


Remove the separate createTooltip constructor, remove the unused x, y,
id attributes, and make showtip/hidetip directly usable as callbacks.

widget and text remain public attributes as one could imaging wanting to
update them (reparenting the tooltip or changing the text).

@anntzer anntzer marked this pull request as ready for review September 15, 2023 18:10
@anntzer anntzer removed the status: inactive Marked by the “Stale” Github Action label Sep 15, 2023
widget.bind('<Leave>', leave)

8000
def __init__(self, widget):
def __init__(self, widget, text):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have a short docstring explaining its use. Instantiating a class without binding it to a variable is an unusual construct. (I'm not even sure who holds the reference to the object, but I suppose, it's through the bound methods?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the callbacks maintain the ToolTip alive (this was already the case previously via the enter() and leave() callbacks).
I agree that instantiating the class without binding it is rather awkward, so I decided again to go back a closure-based approach like I originally tried (but keeping the repeated window create/deletions that existed in the previous code).

... switching everything to use closures.
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Nov 24, 2023
@QuLogic QuLogic removed the status: inactive Marked by the “Stale” Github Action label Nov 24, 2023
@QuLogic QuLogic added this to the v3.9.0 milestone Nov 24, 2023
@QuLogic QuLogic merged commit 4f12525 into matplotlib:main Nov 24, 2023
@anntzer anntzer deleted the tktip branch November 24, 2023 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0