Rate-limit event processing inside ProgressDialog

This commit is contained in:
Luke Campagnola 2020-07-13 12:55:12 -07:00
parent ab5a2c5d11
commit f9327ea910

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from ..Qt import QtGui, QtCore
from .. import ptime
__all__ = ['ProgressDialog']
@ -49,6 +50,9 @@ class ProgressDialog(QtGui.QProgressDialog):
self._subBars = []
self.nested = nested
# for rate-limiting Qt event processing during progress bar update
self._lastProcessEvents = None
isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
self.disabled = disable or (not isGuiThread)
if self.disabled:
@ -203,7 +207,10 @@ class ProgressDialog(QtGui.QProgressDialog):
# Qt docs say this should happen automatically, but that doesn't seem
# to be the case.
if self.windowModality() == QtCore.Qt.WindowModal:
now = ptime.time()
if self._lastProcessEvents is None or (now - self._lastProcessEvents) > 0.2:
QtGui.QApplication.processEvents()
self._lastProcessEvents = now
def setLabelText(self, val):
if self.disabled: