Merge pull request #672 from campagnola/busy-cursor-fix

Busy cursor fix
This commit is contained in:
Luke Campagnola 2018-04-25 13:18:20 -07:00 committed by GitHub
commit 43209593c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,16 +9,22 @@ class BusyCursor(object):
with pyqtgraph.BusyCursor():
doLongOperation()
May be nested.
May be nested. If called from a non-gui thread, then the cursor will not be affected.
"""
active = []
def __enter__(self):
app = QtCore.QCoreApplication.instance()
isGuiThread = (app is not None) and (QtCore.QThread.currentThread() == app.thread())
if isGuiThread and QtGui.QApplication.instance() is not None:
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
BusyCursor.active.append(self)
self._active = True
else:
self._active = False
def __exit__(self, *args):
if self._active:
BusyCursor.active.pop(-1)
if len(BusyCursor.active) == 0:
QtGui.QApplication.restoreOverrideCursor()