Skip to content

Commit

Permalink
Implement blocking Qt event loop.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anntzer committed Apr 8, 2017
1 parent 72cea62 commit 872675c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,17 @@ def flush_events(self):
global qApp
qApp.processEvents()

def start_event_loop(self, timeout):
FigureCanvasBase.start_event_loop_default(self, timeout)

start_event_loop.__doc__ = \
FigureCanvasBase.start_event_loop_default.__doc__

def stop_event_loop(self):
FigureCanvasBase.stop_event_loop_default(self)

stop_event_loop.__doc__ = FigureCanvasBase.stop_event_loop_default.__doc__
def start_event_loop(self, timeout=0):
if hasattr(self, "_event_loop") and self._event_loop.isRunning():
raise RuntimeError("Event loop already running")
self._event_loop = event_loop = QtCore.QEventLoop()
if timeout:
timer = QtCore.QTimer.singleShot(timeout * 1000, event_loop.quit)
event_loop.exec_()

def stop_event_loop(self, event=None):
if hasattr(self, "_event_loop"):
self._event_loop.quit()


class MainWindow(QtWidgets.QMainWindow):
Expand Down

0 comments on commit 872675c

Please sign in to comment.