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

Skip to content

[ENH]: Event to notify non-motion after a specific amount of time #29162

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

Closed
albavilanova opened this issue Nov 20, 2024 · 6 comments
Closed

[ENH]: Event to notify non-motion after a specific amount of time #29162

albavilanova opened this issue Nov 20, 2024 · 6 comments

Comments

@albavilanova
Copy link

Problem

Hi all,

I hope you are doing well.

I've been reading the documentation page on event handling and haven't found an event to detect if the mouse is not moving for some time (1 second or something configurable).

We would like to have this feature to be able to get annotations on hover on our plot only when the user stops moving the mouse, instead of when the user moves the mouse with 'motion_notify_event' as we are doing it now, which we think makes our application run more slowly.

If you have any question let me know.

Thanks,

Albs

Proposed solution

No response

@tacaswell
Copy link
Member

The general approach I think you would have to take is have a callback on motion_notify that starts a timer (and cancels a maybe running time) and then subscribe the actual callback to that timer.

I suggest starting with https://matplotlib.org/stable/api/backend_bases_api.html#matplotlib.backend_bases.FigureCanvasBase.new_timer to get timers integrated with the GUI toolkit and to make sure that the callbacks run on the main thread (threading.Timer will likely run into some "fun" thread related issues).

I don't see any technical reason why this can not be implemented outside of the core library, but I also suspect it will be subtle enough that it would be worth pulling it into core once it is working.

Is there prior art of APIs for hover that should be used as inspiration?

@timhoffm
Copy link
Member

timhoffm commented Nov 20, 2024

Going through matplotlib’s event mechanism feels relatively heavy. The underlying GUI frameworks should have appropriate events that we could subscribe to (e.g. QEvent::Tooltip for Qt). I’d expect that to be more efficient than restarting a timer through a Python function on every motion event.

See also #23378.

@albavilanova Could you describe the kind of annotations in your use case? Is it a simple text or a more complex annotation? Is it a constant annotation per Artist (Line, Rectangle…) or e.g. per data point / depending on the position within a rectangle, …)? Is the data constant and could be precomputed/provided via a high-level API such as plot([1, 2, 3], [1, 4, 9], tooltip=[“a”, “b”, “c”]) or does it need to be computed on-the fly via a function you provide?

@albavilanova
Copy link
Author

It is simple text, generated using annotate, but the text isn't static as it is computed on-the-fly. We have given it a go with Tooltip from Qt and it seems to work much faster keeping motion_notify_event. Feel free to close the issue, thank you!

@tacaswell
Copy link
Member

On reflection I agree with @timhoffm .

@tacaswell
Copy link
Member

I'm going to close this as a duplicate of #23378.

@ericpre
Copy link
Member

ericpre commented Nov 25, 2024

Would it worth considering such an event ("non-motion" event) for widgets or selectors? This would a significant improvement for situation where the callback connected to the selectors are too slow to be live: for example instead of connecting the callback on motion_notify_event, it could be connect to this non-motion_notify_event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants