From d4a4fd7fd5565276dabd7990721210bf9df6dd42 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 25 Apr 2018 13:04:26 -0700 Subject: [PATCH 1/2] fix busy cursor nesting Prevents permenent busy cursor --- pyqtgraph/widgets/BusyCursor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/widgets/BusyCursor.py b/pyqtgraph/widgets/BusyCursor.py index d99fe589..5fab3358 100644 --- a/pyqtgraph/widgets/BusyCursor.py +++ b/pyqtgraph/widgets/BusyCursor.py @@ -18,7 +18,7 @@ class BusyCursor(object): BusyCursor.active.append(self) def __exit__(self, *args): - BusyCursor.active.pop(-1) - if len(BusyCursor.active) == 0: + if self._active: + BusyCursor.active.pop(-1) QtGui.QApplication.restoreOverrideCursor() \ No newline at end of file From 7daa5bdff13149f246fb6d13b330ec7fe3d44785 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 25 Apr 2018 13:04:52 -0700 Subject: [PATCH 2/2] Ignore BusyCursor when called from thread --- pyqtgraph/widgets/BusyCursor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/widgets/BusyCursor.py b/pyqtgraph/widgets/BusyCursor.py index 5fab3358..e7a26810 100644 --- a/pyqtgraph/widgets/BusyCursor.py +++ b/pyqtgraph/widgets/BusyCursor.py @@ -9,13 +9,19 @@ 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): - QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) - BusyCursor.active.append(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: