From 6a68046fee4037493ba00719882ad33585ad9f92 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 18 Jul 2021 10:31:47 -0700 Subject: [PATCH] Add helpers --- plugin/util.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plugin/util.py b/plugin/util.py index e2d6741..99a6457 100644 --- a/plugin/util.py +++ b/plugin/util.py @@ -84,3 +84,48 @@ def setting(key): return aqt.mw.addonManager.getConfig(__name__).get(key, defaults[key]) except: raise Exception('setting {} not found'.format(key)) + + +# +# Anki Helpers +# + +def window(self): + return aqt.mw + + +def reviewer(): + return window().reviewer + + +def collection(self): + return window().col + + +def decks(self): + return collection().decks + + +def scheduler(self): + return collection().sched + + +def database(self): + return collection().db + + +def media(self): + return collection().media + + +def deckNames(): + return decks().allNames() + + +class EditScope: + def __enter__(self): + window().requireReset() + + def __exit__(self): + window().maybeReset() +