File: BusyCursor.py

package info (click to toggle)
python-pyqtgraph 0.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,684 kB
  • sloc: python: 45,678; makefile: 115; ansic: 40
file content (35 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from ..Qt import QtGui, QtCore, QT_LIB

__all__ = ['BusyCursor']

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

        with pyqtgraph.BusyCursor():
            doLongOperation()

    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:
            if QT_LIB == 'PySide':
                # pass CursorShape rather than QCursor for PySide
                # see https://bugreports.qt.io/browse/PYSIDE-243
                QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
            else:
                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()