# Is it possible to delay the closing of collection?

**URL:** <https://forums.ankiweb.net/t/is-it-possible-to-delay-the-closing-of-collection/31204>\
**Category:** Add-ons\
**Created:** [June 13, 2023, 4:25pm UTC](https://forums.ankiweb.net/t/is-it-possible-to-delay-the-closing-of-collection/31204 "2023-06-13T16:25:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![L.M.Sherlock](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/l.m.sherlock/32/16770_2.png) [@L.M.Sherlock](https://forums.ankiweb.net/u/L.M.Sherlock)\
**Post date:** [June 13, 2023, 4:25pm UTC](https://forums.ankiweb.net/t/is-it-possible-to-delay-the-closing-of-collection/31204/1 "2023-06-13T16:25:53Z")

</div>

I’m the author of [fsrs4anki-helper](https://github.com/open-spaced-repetition/fsrs4anki-helper). Recently, I’m developing the auto-rescheduling feature, which could reschedule cards reviewed in another device.

I added the function to the hook of `sync_did_finish`. After the function finished, it will use tooltip to show the result of auto-rescheduling. Here I encounter a problem:

When user enable the auto sync, syncing will be triggered when user closes the collection. The message displayed in tooltip will disappear quickly. So the user doesn’t have enough time to see the message.

Is there any way to delay the closing of collection when the tooltip shows the message? I try to use `time.sleep()`, but it freezes the collection, and the tooltip are delayed, too.

---

<div class="post-metadata">

**Author:** ![Shigeyuki](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shigeyuki/32/23878_2.png) [@Shigeyuki](https://forums.ankiweb.net/u/Shigeyuki)\
**Post date:** [June 13, 2023, 7:45pm UTC](https://forums.ankiweb.net/t/is-it-possible-to-delay-the-closing-of-collection/31204/2 "2023-06-13T19:45:26Z")

</div>

Maybe QMessageBox could be used to block Anki from closing until the user presses OK.

```auto
def sync_did_finish_text():
    msgBox = QMessageBox()
    msgBox.setText("sync did finish")
    msgBox.exec()

from aqt import gui_hooks
gui_hooks.sync_did_finish.append(sync_did_finish_text)

```

---

<div class="post-metadata">

**Author:** ![L.M.Sherlock](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/l.m.sherlock/32/16770_2.png) [@L.M.Sherlock](https://forums.ankiweb.net/u/L.M.Sherlock)\
**Post date:** [June 14, 2023, 1:14am UTC](https://forums.ankiweb.net/t/is-it-possible-to-delay-the-closing-of-collection/31204/3 "2023-06-14T01:14:31Z")

</div>

It’s a little annoying to require the users to click the button every time they close the collection.

---

<div class="post-metadata">

**Author:** ![Shigeyuki](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shigeyuki/32/23878_2.png) [@Shigeyuki](https://forums.ankiweb.net/u/Shigeyuki)\
**Post date:** [June 14, 2023, 1:51am UTC](https://forums.ankiweb.net/t/is-it-possible-to-delay-the-closing-of-collection/31204/4 "2023-06-14T01:51:23Z")

</div>

Qtimer can be used to automatically close the QMessageBox. (The button is hidden by “NoButton”)

```auto
from aqt import QMessageBox, QTimer
from aqt import gui_hooks

def sync_did_finish_text():
    msgBox = QMessageBox()
    msgBox.setStandardButtons(QMessageBox.StandardButton.NoButton)
    msgBox.setText("sync did finish")
    timer = QTimer()
    timer.singleShot(3000, msgBox.accept)
    msgBox.exec()

gui_hooks.sync_did_finish.append(sync_did_finish_text)

```

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [June 15, 2023, 8:58am UTC](https://forums.ankiweb.net/t/is-it-possible-to-delay-the-closing-of-collection/31204/5 "2023-06-15T08:58:48Z")

</div>

> [@L.M.Sherlock](#):
>
> It’s a little annoying to require the users to click the button every time they close the collection.

…or make them wait longer for Anki to close? 🙂 Is the message you’re presenting to the user important enough that it should delay shutdown?
