Skip to content

Commit

Permalink
add v1 sched warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed May 10, 2021
1 parent 2b94636 commit 75b9936
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
22 changes: 21 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from anki.collection import Collection
from aqt import gui_hooks
from aqt.utils import askUser

from . import answer_buttons
from . import gui
from . import toolbar
from .consts import SCHED_UP_WARN_MSG


def init_answer_buttons(col: Collection):
# Upgrade scheduler version, if outdated.

if col.schedVer() != 2:
if askUser(SCHED_UP_WARN_MSG) is True:
col.changeSchedulerVer(2)
else:
return

answer_buttons.main()


answer_buttons.main()
toolbar.main()
gui.main()
gui_hooks.collection_did_load.append(init_answer_buttons)
8 changes: 0 additions & 8 deletions answer_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,3 @@ def main():
# If `pass_fail` is true, "Hard" and "Easy" buttons are removed.
# This func gets called inside _answerButtonList, which itself gets called inside _answerButtons (*)
gui_hooks.reviewer_will_init_answer_buttons.append(filter_answer_buttons)

# When Reviewer is open, print the last card's stats on the top toolbar.
gui_hooks.top_toolbar_did_init_links.append(LastEase.append_link)
gui_hooks.reviewer_did_answer_card.append(LastEase.update)

# Don't show the last card's stats when Reviewer is not open.
gui_hooks.reviewer_will_end.append(LastEase.hide)
gui_hooks.main_window_did_init.append(LastEase.hide)
15 changes: 15 additions & 0 deletions consts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from anki.lang import _

ADDON_NAME = "AJT Flexible Grading"
GITHUB = "https://github.com/Ajatt-Tools"
DONATE_LINK = "https://tatsumoto-ren.github.io/blog/donating-to-tatsumoto.html"
Expand All @@ -24,3 +26,16 @@
and <a href="{YT_LINK}">mattvsjapan</a> for the idea for this add-on.
</p>
"""
SCHED_NAG_MSG = """
<font color="%s">
You are still using the old scheduler.
The add-on is disabled.<br>
Please upgrade the scheduler and restart Anki.
</font>
"""
SCHED_UP_WARN_MSG = _(
f"You've installed {ADDON_NAME}, " +
"but you're still using the outdated V1 scheduler. "
"Upgrading the scheduler to V2 will reset any cards in learning and clear filtered decks. "
"Proceed?"
)
3 changes: 3 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class SettingsMenuDialog(SettingsMenuUI):
def __init__(self, *args, **kwargs):
super(SettingsMenuDialog, self).__init__(*args, **kwargs)
self.connect_buttons()
if mw.col.schedVer() != 2:
layout = self.layout()
layout.addWidget(QLabel(SCHED_NAG_MSG % config.get_color(1)))

def connect_buttons(self):
self.ok_button.clicked.connect(self.on_confirm)
Expand Down
12 changes: 11 additions & 1 deletion toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import aqt
from anki.cards import Card
from aqt import mw
from aqt import mw, gui_hooks
from aqt.reviewer import Reviewer
from aqt.toolbar import Toolbar

Expand Down Expand Up @@ -119,3 +119,13 @@ def hide(cls) -> None:
elem.style.color = "";
elem.style.display = "none";
""")


def main():
# When Reviewer is open, print the last card's stats on the top toolbar.
gui_hooks.top_toolbar_did_init_links.append(LastEase.append_link)
gui_hooks.reviewer_did_answer_card.append(LastEase.update)

# Don't show the last card's stats when Reviewer is not open.
gui_hooks.reviewer_will_end.append(LastEase.hide)
gui_hooks.main_window_did_init.append(LastEase.hide)

0 comments on commit 75b9936

Please sign in to comment.