use a timer to automatically show progress window

We were previously relying on the DB progress hook to cause the
progress window to display.

Qt's progress dialogs do have built in support for automatically
showing, but it's easier to add a timer than change the existing
code to use it.
This commit is contained in:
Damien Elmes 2020-03-06 13:14:37 +10:00
parent 32555b2857
commit 90d4d62c48

View file

@ -25,6 +25,7 @@ class ProgressManager:
self.app = QApplication.instance() self.app = QApplication.instance()
self.inDB = False self.inDB = False
self.blockUpdates = False self.blockUpdates = False
self._show_timer: Optional[QTimer] = None
self._win = None self._win = None
self._levels = 0 self._levels = 0
@ -114,6 +115,10 @@ class ProgressManager:
self._firstTime = time.time() self._firstTime = time.time()
self._lastUpdate = time.time() self._lastUpdate = time.time()
self._updating = False self._updating = False
self._show_timer = QTimer(self.mw)
self._show_timer.setSingleShot(True)
self._show_timer.start(600)
self._show_timer.timeout.connect(self._on_show_timer)
return self._win return self._win
def update(self, label=None, value=None, process=True, maybeShow=True): def update(self, label=None, value=None, process=True, maybeShow=True):
@ -143,6 +148,9 @@ class ProgressManager:
if self._win: if self._win:
self._closeWin() self._closeWin()
self._unsetBusy() self._unsetBusy()
if self._show_timer:
self._show_timer.stop()
self._show_timer = None
def clear(self): def clear(self):
"Restore the interface after an error." "Restore the interface after an error."
@ -189,6 +197,10 @@ class ProgressManager:
"True if processing." "True if processing."
return self._levels return self._levels
def _on_show_timer(self):
self._show_timer = None
self._showWin()
class ProgressDialog(QDialog): class ProgressDialog(QDialog):
def __init__(self, parent): def __init__(self, parent):