From 949584d3fa916db9a39129666013043bbcb1f576 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 16 Mar 2021 19:33:26 +1000 Subject: [PATCH] don't show busy cursor immediately Setting it straight away causes the cursor to flash on quick operations, like saving the current note. Delay it for 300ms, which should hopefully be long enough to not get in the way, but short enough to give indication that long-running requests are being processed. --- qt/aqt/progress.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/qt/aqt/progress.py b/qt/aqt/progress.py index d5002208e..6f99524e7 100644 --- a/qt/aqt/progress.py +++ b/qt/aqt/progress.py @@ -20,6 +20,7 @@ class ProgressManager: self.inDB = False self.blockUpdates = False self._show_timer: Optional[QTimer] = None + self._busy_cursor_timer: Optional[QTimer] = None self._win: Optional[ProgressDialog] = None self._levels = 0 @@ -94,7 +95,10 @@ class ProgressManager: self._win.setWindowTitle("Anki") self._win.setWindowModality(Qt.ApplicationModal) self._win.setMinimumWidth(300) - self._setBusy() + self._busy_cursor_timer = QTimer(self.mw) + self._busy_cursor_timer.setSingleShot(True) + self._busy_cursor_timer.start(300) + qconnect(self._busy_cursor_timer.timeout, self._set_busy_cursor) self._shown: float = 0 self._counter = min self._min = min @@ -148,7 +152,10 @@ class ProgressManager: if self._levels == 0: if self._win: self._closeWin() - self._unsetBusy() + if self._busy_cursor_timer: + self._busy_cursor_timer.stop() + self._busy_cursor_timer = None + self._restore_cursor() if self._show_timer: self._show_timer.stop() self._show_timer = None @@ -187,10 +194,10 @@ class ProgressManager: self._win = None self._shown = 0 - def _setBusy(self) -> None: + def _set_busy_cursor(self) -> None: self.mw.app.setOverrideCursor(QCursor(Qt.WaitCursor)) - def _unsetBusy(self) -> None: + def _restore_cursor(self) -> None: self.app.restoreOverrideCursor() def busy(self) -> int: