Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
QuLogic merged 1 commit into matplotlib:master from anntzer:qt-event-loop
Apr 30, 2017
Merged

Conversation

Copy link
Contributor

@anntzer anntzer commented Mar 2, 2017

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.

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.
Copy link
Member

@phobson phobson left a 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.

FigureCanvasBase.stop_event_loop_default(self)

stop_event_loop.__doc__ = FigureCanvasBase.stop_event_loop_default.__doc__
def start_event_loop(self, timeout=0):
Copy link
Member

@tacaswell tacaswell Apr 20, 2017
edited
Loading

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?

Copy link
Contributor Author

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.

event_loop.exec_()

def stop_event_loop(self, event=None):
if hasattr(self, "_event_loop"):
Copy link
Member

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)?

Copy link
Contributor Author

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

Copy link
Member

@QuLogic QuLogic left a 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.

@QuLogic QuLogic merged commit a7c0ea7 into matplotlib:master Apr 30, 2017
@QuLogic QuLogic added this to the 2.1 (next point release) milestone Apr 30, 2017
@anntzer anntzer deleted the qt-event-loop branch April 30, 2017 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@tacaswell tacaswell tacaswell left review comments

@QuLogic QuLogic QuLogic approved these changes

@phobson phobson phobson approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
v2.1
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /