pyqtgraph/pyqtgraph/widgets/BusyCursor.py
Martin Chase 2fb04b754c
Fix BusyCursor to use internal stack provided by setOverrideCursor/restoreOverrideCursor (#1827)
* un-busy as many times as needed

* lint

* add test to prove cursor behavior

* tentative change in the hopes that all supported qt versions behave properly

* remove unnecessary code

* use contextmanager decorator instead of class

* use full path to WaitCursor

* restore docstring; refactor variable for clarity

* fix docstring whitespace

* break up long lines

* use variable to shorten instead
2021-06-09 13:32:24 -07:00

29 lines
766 B
Python

# -*- coding: utf-8 -*-
from contextlib import contextmanager
from ..Qt import QtGui, QtCore
__all__ = ["BusyCursor"]
@contextmanager
def BusyCursor():
"""
Display a busy mouse cursor during long operations.
Usage::
with BusyCursor():
doLongOperation()
May be nested. If called from a non-gui thread, then the cursor will not be affected.
"""
app = QtCore.QCoreApplication.instance()
in_gui_thread = (app is not None) and (QtCore.QThread.currentThread() == app.thread())
try:
if in_gui_thread:
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CursorShape.WaitCursor))
yield
finally:
if in_gui_thread:
QtGui.QApplication.restoreOverrideCursor()