Title pretty much says it all but I will elaborate.
I’ve been desperate for a way to get windows notifications as soon as a card is due so I slapped together some code. I’ve managed to make a button in Anki that sends notifications but to finish it I need a way to run a line of code every minute or so.
Are there any hooks that are already run at fairly constant intervals?
One that runs whenever a card becomes due would also work.
Any help would be appreciated.
1 Like
ijgnd
November 18, 2020, 7:21pm
2
maybe you can adjust some of this?
return diffText = tr(TR.QT_MISC_SECOND, count=diff) warn = tr(TR.QT_MISC_IN_ORDER_TO_ENSURE_YOUR_COLLECTION, val="%s") % diffText showWarning(warn) self.app.closeAllWindows() # Timers ########################################################################## def setup_timers(self) -> None: # refresh decks every 10 minutes self.progress.timer(10 * 60 * 1000, self.onRefreshTimer, True) # check media sync every 5 minutes self.progress.timer(5 * 60 * 1000, self.on_autosync_timer, True) # ensure Python interpreter runs at least once per second, so that # SIGINT/SIGTERM is processed without a long delay self.progress.timer(1000, lambda: None, True, False) def onRefreshTimer(self): if self.state == "deckBrowser": self.deckBrowser.refresh()
self.blockUpdates = False self._show_timer: Optional[QTimer] = None self._win = None self._levels = 0 # Safer timers ########################################################################## # A custom timer which avoids firing while a progress dialog is active # (likely due to some long-running DB operation) def timer(self, ms, func, repeat, requiresCollection=True): """Create and start a standard Anki timer. If the timer fires while a progress window is shown: - if it is a repeating timer, it will wait the same delay again - if it is non-repeating, it will try again in 100ms If requiresCollection is True, the timer will not fire if the collection has been unloaded. Setting it to False will allow the timer to fire even when there is no collection, but will still only fire when there is no current progress dialog."""
I haven’t tried this.
This definitely seems to be what I need and I’ll see if I can figure it out.
That said I really have a miniscule amount of experience so I’m just gonna spitfire some questions before I continue to fumble around for hours.
Would I need to recompile something to edit this or is there a file that I could easily open and edit in the anki installation.
Or could I call that that self.progress.timer fuction from within an addon somehow?
ijgnd
November 19, 2020, 3:26am
4
make a new folder 00000
in your addons21 folder. in it make a text file __init__.py
.
Put this into the file:
from aqt import mw
from aqt.utils import tooltip
def myfunc()
tooltip("some message", parent=mw)
mw.progress.timer(15000, myfunc, True)
restart anki.
This should show a tooltip every 15 seconds in the main window
3 Likes
Thanks that’s perfect, I almost had it by the time I read it but I wrote “self.progress.timer” instead so you still ended up saving me.