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