Ignore BusyCursor when called from thread

This commit is contained in:
Luke Campagnola 2018-04-25 13:04:52 -07:00
parent d4a4fd7fd5
commit 7daa5bdff1

View File

@ -9,13 +9,19 @@ class BusyCursor(object):
with pyqtgraph.BusyCursor(): with pyqtgraph.BusyCursor():
doLongOperation() doLongOperation()
May be nested. May be nested. If called from a non-gui thread, then the cursor will not be affected.
""" """
active = [] active = []
def __enter__(self): def __enter__(self):
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) app = QtCore.QCoreApplication.instance()
BusyCursor.active.append(self) 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): def __exit__(self, *args):
if self._active: if self._active: