from ..Qt import QtGui, QtCore

__all__ = ['BusyCursor']

class BusyCursor(object):
    """Class for displaying a busy mouse cursor during long operations.
    Usage::

        with pyqtgraph.BusyCursor():
            doLongOperation()

    May be nested.
    """
    active = []

    def __enter__(self):
        QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
        BusyCursor.active.append(self)

    def __exit__(self, *args):
        BusyCursor.active.pop(-1)
        if len(BusyCursor.active) == 0:
            QtGui.QApplication.restoreOverrideCursor()
        
@@ -299,16 +299,74 @@
 (self):%0A
+        if QtGui.QApplication.instance() is not None:%0A    
         
@@ -439,32 +439,36 @@
 ursor))%0A        
+    
 BusyCursor.activ
@@ -481,16 +481,95 @@
 nd(self)
+%0A            self._active = True%0A        else:%0A            self._active = False
 %0A%0A    de
@@ -593,16 +593,45 @@
 *args):%0A
+        if self._active:%0A    
         
@@ -656,16 +656,20 @@
 pop(-1)%0A
+    
         
@@ -700,16 +700,20 @@
 ) == 0:%0A
+    
         

Disable BusyCursor when there is no QApplication