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

Commit 872675c

Browse files
committed
Implement blocking Qt event loop.
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.
1 parent 72cea62 commit 872675c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

‎lib/matplotlib/backends/backend_qt5.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,17 @@ def flush_events(self):
430430
global qApp
431431
qApp.processEvents()
432432

433-
def start_event_loop(self, timeout):
434-
FigureCanvasBase.start_event_loop_default(self, timeout)
435-
436-
start_event_loop.__doc__ = \
437-
FigureCanvasBase.start_event_loop_default.__doc__
438-
439-
def stop_event_loop(self):
440-
FigureCanvasBase.stop_event_loop_default(self)
441-
442-
stop_event_loop.__doc__ = FigureCanvasBase.stop_event_loop_default.__doc__
433+
def start_event_loop(self, timeout=0):
434+
if hasattr(self, "_event_loop") and self._event_loop.isRunning():
435+
raise RuntimeError("Event loop already running")
436+
self._event_loop = event_loop = QtCore.QEventLoop()
437+
if timeout:
438+
timer = QtCore.QTimer.singleShot(timeout * 1000, event_loop.quit)
439+
event_loop.exec_()
440+
441+
def stop_event_loop(self, event=None):
442+
if hasattr(self, "_event_loop"):
443+
self._event_loop.quit()
443444

444445

445446
class MainWindow(QtWidgets.QMainWindow):

0 commit comments

Comments
(0)

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