-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Implement blocking Qt event loop. #8185
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
Conversation
Avoids raising a deprecation warning (due to use of the default busy waiting loop) when running e.g. ``` plt.gca(); plt.gcf().ginput(4) ``` or ``` plt.gca(); plt.gcf().ginput(4, timeout=2) ``` The implementation is similar to the one for the Wx backend.
94e208e
to
872675c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users report that this has worked out so 👍 from me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need an event loop separate from the one provided in the 'qApp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire machinery is only used by blocking_input.py (ginput), in order to not block event handling while waiting for the user to select points on the plot. See https://wiki.qt.io/Threads_Events_QObjects#Forcing_event_dispatching for the pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to check if it's running, too (i.e., if the timer has already expired and called quit)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you can re-quit an already exited loop:
In [1]: plt.gca(); plt.gcf().ginput(4, timeout=2)
Out[1]:
[(0.70564516129032262, 0.42803030303030309),
(0.38911290322580649, 0.26298701298701299)]
In [2]: el = plt.gcf().canvas._event_loop; print(el.isRunning()); el.quit()
False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work for me.
Avoids raising a deprecation warning (due to use of the default busy
waiting loop) when running e.g.
or
The implementation is similar to the one for the Wx backend.