2019-02-05 04:59:03 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
2012-12-21 08:51:59 +01:00
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2020-02-08 23:59:29 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2013-10-22 07:28:45 +02:00
|
|
|
import difflib
|
2017-12-11 07:20:00 +01:00
|
|
|
import html
|
2019-03-04 08:25:19 +01:00
|
|
|
import json
|
2019-12-20 10:19:03 +01:00
|
|
|
import re
|
|
|
|
import unicodedata as ucd
|
2021-03-14 13:08:37 +01:00
|
|
|
from enum import Enum, auto
|
2021-02-02 15:00:29 +01:00
|
|
|
from typing import Any, Callable, List, Match, Optional, Sequence, Tuple, Union
|
2020-02-27 04:11:21 +01:00
|
|
|
|
|
|
|
from PyQt5.QtCore import Qt
|
2019-12-16 10:46:40 +01:00
|
|
|
|
2020-01-13 04:57:51 +01:00
|
|
|
from anki import hooks
|
2019-12-16 10:46:40 +01:00
|
|
|
from anki.cards import Card
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
from anki.collection import Config, OperationInfo
|
2021-03-14 13:08:37 +01:00
|
|
|
from anki.types import assert_exhaustive
|
2020-01-23 06:08:10 +01:00
|
|
|
from anki.utils import stripHTML
|
2020-01-13 09:37:08 +01:00
|
|
|
from aqt import AnkiQt, gui_hooks
|
2020-12-22 04:01:06 +01:00
|
|
|
from aqt.profiles import VideoDriver
|
2012-12-21 08:51:59 +01:00
|
|
|
from aqt.qt import *
|
Rework reschedule tool
The old rescheduling dialog's two options have been split into two
separate menu items, "Forget", and "Set Due Date"
For cards that are not review cards, "Set Due Date" behaves like the
old reschedule option, changing the cards into a review card, and
and setting both the interval and due date to the provided number of
days.
When "Set Due Date" is applied to a review card, it no longer resets
the card's interval. Instead, it looks at how much the provided number
of days will change the original interval, and adjusts the interval by
that amount, so that cards that are answered earlier receive a smaller
next interval, and cards that are answered after a longer delay receive
a bonus.
For example, imagine a card was answered on day 5, and given an interval
of 10 days, so it has a due date of day 15.
- if on day 10 the due date is changed to day 12 (today+2), the card
is being scheduled 3 days earlier than it was supposed to be, so the
interval will be adjusted to 7 days.
- and if on day 10 the due date is changed to day 20, the interval will
be changed from 10 days to 15 days.
There is no separate option to reset the interval of a review card, but
it can be accomplished by forgetting the card(s), and then setting the
desired due date.
Other notes:
- Added the action to the review screen as well.
- Set the shortcut to Ctrl+Shift+D, and changed the existing Delete
Tags shortcut to Ctrl+Alt+Shift+A.
2021-02-07 11:58:16 +01:00
|
|
|
from aqt.scheduling import set_due_date_dialog
|
2020-12-16 10:09:45 +01:00
|
|
|
from aqt.sound import av_player, play_clicked_audio, record_audio
|
2020-01-23 06:08:10 +01:00
|
|
|
from aqt.theme import theme_manager
|
2020-01-22 01:46:35 +01:00
|
|
|
from aqt.toolbar import BottomBar
|
2020-11-17 08:42:43 +01:00
|
|
|
from aqt.utils import (
|
|
|
|
TR,
|
|
|
|
askUserDialog,
|
|
|
|
downArrow,
|
|
|
|
qtMenuShortcutWorkaround,
|
|
|
|
tooltip,
|
|
|
|
tr,
|
|
|
|
)
|
2020-10-14 02:10:16 +02:00
|
|
|
from aqt.webview import AnkiWebView
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2013-10-22 07:28:45 +02:00
|
|
|
|
2020-02-08 23:59:29 +01:00
|
|
|
class ReviewerBottomBar:
|
2020-02-27 04:11:21 +01:00
|
|
|
def __init__(self, reviewer: Reviewer) -> None:
|
2020-02-08 23:59:29 +01:00
|
|
|
self.reviewer = reviewer
|
|
|
|
|
2020-04-13 01:04:30 +02:00
|
|
|
|
2021-03-14 13:08:37 +01:00
|
|
|
class RefreshNeeded(Enum):
|
|
|
|
NO = auto()
|
|
|
|
NOTE_MARK = auto()
|
|
|
|
CARD_FLAG = auto()
|
|
|
|
QUEUE = auto()
|
|
|
|
CARD = auto()
|
|
|
|
|
|
|
|
|
2020-04-13 00:59:36 +02:00
|
|
|
def replay_audio(card: Card, question_side: bool) -> None:
|
|
|
|
if question_side:
|
|
|
|
av_player.play_tags(card.question_av_tags())
|
|
|
|
else:
|
|
|
|
tags = card.answer_av_tags()
|
|
|
|
if card.replay_question_audio_on_answer_side():
|
|
|
|
tags = card.question_av_tags() + tags
|
|
|
|
av_player.play_tags(tags)
|
2020-02-08 23:59:29 +01:00
|
|
|
|
2020-04-13 01:04:30 +02:00
|
|
|
|
2017-02-06 23:21:33 +01:00
|
|
|
class Reviewer:
|
2012-12-21 08:51:59 +01:00
|
|
|
"Manage reviews. Maintains a separate state."
|
|
|
|
|
2020-01-13 04:57:51 +01:00
|
|
|
def __init__(self, mw: AnkiQt) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw = mw
|
|
|
|
self.web = mw.web
|
2020-01-15 22:41:23 +01:00
|
|
|
self.card: Optional[Card] = None
|
2019-12-16 10:46:40 +01:00
|
|
|
self.cardQueue: List[Card] = []
|
2012-12-21 08:51:59 +01:00
|
|
|
self.hadCardQueue = False
|
2019-12-16 10:46:40 +01:00
|
|
|
self._answeredIds: List[int] = []
|
2020-02-27 04:11:21 +01:00
|
|
|
self._recordedAudio: Optional[str] = None
|
|
|
|
self.typeCorrect: str = None # web init happens before this is set
|
2020-01-15 22:41:23 +01:00
|
|
|
self.state: Optional[str] = None
|
2021-03-14 13:08:37 +01:00
|
|
|
self.refresh_needed = RefreshNeeded.NO
|
2020-01-22 01:46:35 +01:00
|
|
|
self.bottom = BottomBar(mw, mw.bottomWeb)
|
2020-01-15 07:53:24 +01:00
|
|
|
hooks.card_did_leech.append(self.onLeech)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def show(self) -> None:
|
|
|
|
self.mw.setStateShortcuts(self._shortcutKeys()) # type: ignore
|
2020-02-08 23:59:29 +01:00
|
|
|
self.web.set_bridge_command(self._linkHandler, self)
|
|
|
|
self.bottom.web.set_bridge_command(self._linkHandler, ReviewerBottomBar(self))
|
2020-02-27 04:11:21 +01:00
|
|
|
self._reps: int = None
|
2021-03-14 13:08:37 +01:00
|
|
|
self.refresh_needed = RefreshNeeded.QUEUE
|
|
|
|
self.refresh_if_needed()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def lastCard(self) -> Optional[Card]:
|
2012-12-21 08:51:59 +01:00
|
|
|
if self._answeredIds:
|
|
|
|
if not self.card or self._answeredIds[-1] != self.card.id:
|
|
|
|
try:
|
|
|
|
return self.mw.col.getCard(self._answeredIds[-1])
|
|
|
|
except TypeError:
|
|
|
|
# id was deleted
|
2020-02-27 04:11:21 +01:00
|
|
|
return None
|
|
|
|
return None
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-01-15 22:41:23 +01:00
|
|
|
def cleanup(self) -> None:
|
2020-01-15 07:53:24 +01:00
|
|
|
gui_hooks.reviewer_will_end()
|
2020-10-14 11:54:29 +02:00
|
|
|
self.card = None
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-14 13:08:37 +01:00
|
|
|
def refresh_if_needed(self) -> None:
|
|
|
|
if self.refresh_needed is RefreshNeeded.NO:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
return
|
2021-03-14 13:08:37 +01:00
|
|
|
elif self.refresh_needed is RefreshNeeded.NOTE_MARK:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
self.card.load()
|
|
|
|
self._update_mark_icon()
|
2021-03-14 13:08:37 +01:00
|
|
|
elif self.refresh_needed is RefreshNeeded.CARD_FLAG:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
# fixme: v3 mtime check
|
|
|
|
self.card.load()
|
|
|
|
self._update_flag_icon()
|
2021-03-14 13:08:37 +01:00
|
|
|
elif self.refresh_needed is RefreshNeeded.QUEUE:
|
2021-03-13 14:59:32 +01:00
|
|
|
self.mw.col.reset()
|
|
|
|
self.nextCard()
|
2021-03-14 13:08:37 +01:00
|
|
|
elif self.refresh_needed is RefreshNeeded.CARD:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
self.card.load()
|
|
|
|
self._showQuestion()
|
2021-03-14 13:08:37 +01:00
|
|
|
else:
|
|
|
|
assert_exhaustive(self.refresh_needed)
|
|
|
|
|
|
|
|
self.refresh_needed = RefreshNeeded.NO
|
|
|
|
|
|
|
|
def op_executed(self, op: OperationInfo, focused: bool) -> None:
|
|
|
|
if op.kind == OperationInfo.UPDATE_NOTE_TAGS:
|
|
|
|
self.refresh_needed = RefreshNeeded.NOTE_MARK
|
|
|
|
elif op.kind == OperationInfo.SET_CARD_FLAG:
|
|
|
|
self.refresh_needed = RefreshNeeded.CARD_FLAG
|
|
|
|
elif self.mw.col.op_affects_study_queue(op):
|
|
|
|
self.refresh_needed = RefreshNeeded.QUEUE
|
|
|
|
elif op.changes.note or op.changes.notetype or op.changes.tag:
|
|
|
|
self.refresh_needed = RefreshNeeded.CARD
|
|
|
|
else:
|
|
|
|
self.refresh_needed = RefreshNeeded.NO
|
|
|
|
|
|
|
|
if focused:
|
|
|
|
self.refresh_if_needed()
|
2021-03-13 14:59:32 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# Fetching a card
|
|
|
|
##########################################################################
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def nextCard(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
elapsed = self.mw.col.timeboxReached()
|
|
|
|
if elapsed:
|
2020-02-27 04:11:21 +01:00
|
|
|
assert not isinstance(elapsed, bool)
|
2020-11-18 00:22:27 +01:00
|
|
|
part1 = tr(TR.STUDYING_CARD_STUDIED_IN, count=elapsed[1])
|
2019-12-23 01:34:10 +01:00
|
|
|
mins = int(round(elapsed[0] / 60))
|
2020-11-18 00:22:27 +01:00
|
|
|
part2 = tr(TR.STUDYING_MINUTE, count=mins)
|
2020-11-17 08:42:43 +01:00
|
|
|
fin = tr(TR.STUDYING_FINISH)
|
2021-02-11 01:09:06 +01:00
|
|
|
diag = askUserDialog(f"{part1} {part2}", [tr(TR.STUDYING_CONTINUE), fin])
|
2013-05-24 05:53:41 +02:00
|
|
|
diag.setIcon(QMessageBox.Information)
|
|
|
|
if diag.run() == fin:
|
|
|
|
return self.mw.moveToState("deckBrowser")
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw.col.startTimebox()
|
|
|
|
if self.cardQueue:
|
|
|
|
# undone/edited cards to show
|
|
|
|
c = self.cardQueue.pop()
|
|
|
|
c.startTimer()
|
|
|
|
self.hadCardQueue = True
|
|
|
|
else:
|
|
|
|
if self.hadCardQueue:
|
|
|
|
# the undone/edited cards may be sitting in the regular queue;
|
|
|
|
# need to reset
|
|
|
|
self.mw.col.reset()
|
|
|
|
self.hadCardQueue = False
|
|
|
|
c = self.mw.col.sched.getCard()
|
|
|
|
self.card = c
|
|
|
|
if not c:
|
|
|
|
self.mw.moveToState("overview")
|
|
|
|
return
|
|
|
|
if self._reps is None or self._reps % 100 == 0:
|
|
|
|
# we recycle the webview periodically so webkit can free memory
|
|
|
|
self._initWeb()
|
2017-08-02 08:22:54 +02:00
|
|
|
self._showQuestion()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Audio
|
|
|
|
##########################################################################
|
|
|
|
|
2020-04-13 00:59:36 +02:00
|
|
|
def replayAudio(self) -> None:
|
|
|
|
if self.state == "question":
|
|
|
|
replay_audio(self.card, True)
|
|
|
|
elif self.state == "answer":
|
|
|
|
replay_audio(self.card, False)
|
2020-01-21 05:47:03 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# Initializing the webview
|
|
|
|
##########################################################################
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def revHtml(self) -> str:
|
2017-08-10 13:39:04 +02:00
|
|
|
extra = self.mw.col.conf.get("reviewExtra", "")
|
2019-12-23 01:34:10 +01:00
|
|
|
fade = ""
|
2020-12-22 04:01:06 +01:00
|
|
|
if self.mw.pm.video_driver() == VideoDriver.Software:
|
2019-12-23 01:34:10 +01:00
|
|
|
fade = "<script>qFade=0;</script>"
|
2021-02-11 01:09:06 +01:00
|
|
|
return f"""
|
2017-08-16 12:30:29 +02:00
|
|
|
<div id=_mark>★</div>
|
2017-08-12 08:08:10 +02:00
|
|
|
<div id=_flag>⚑</div>
|
2021-02-11 01:09:06 +01:00
|
|
|
{fade}
|
2017-08-06 04:01:30 +02:00
|
|
|
<div id=qa></div>
|
2021-02-11 01:09:06 +01:00
|
|
|
{extra}
|
|
|
|
"""
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _initWeb(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
self._reps = 0
|
|
|
|
# main window
|
2019-12-23 01:34:10 +01:00
|
|
|
self.web.stdHtml(
|
|
|
|
self.revHtml(),
|
2020-11-01 05:26:58 +01:00
|
|
|
css=["css/reviewer.css"],
|
2019-12-23 01:34:10 +01:00
|
|
|
js=[
|
2020-12-28 14:18:07 +01:00
|
|
|
"js/vendor/jquery.min.js",
|
2020-12-31 16:47:20 +01:00
|
|
|
"js/vendor/css_browser_selector.min.js",
|
2020-11-15 11:22:28 +01:00
|
|
|
"js/mathjax.js",
|
2020-11-03 15:49:07 +01:00
|
|
|
"js/vendor/mathjax/tex-chtml.js",
|
2020-11-01 05:26:58 +01:00
|
|
|
"js/reviewer.js",
|
2019-12-23 01:34:10 +01:00
|
|
|
],
|
2020-02-12 22:00:13 +01:00
|
|
|
context=self,
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
# show answer / ease buttons
|
|
|
|
self.bottom.web.show()
|
|
|
|
self.bottom.web.stdHtml(
|
|
|
|
self._bottomHTML(),
|
2020-11-01 05:26:58 +01:00
|
|
|
css=["css/toolbar-bottom.css", "css/reviewer-bottom.css"],
|
2020-12-28 14:18:07 +01:00
|
|
|
js=["js/vendor/jquery.min.js", "js/reviewer-bottom.js"],
|
2020-02-12 22:00:13 +01:00
|
|
|
context=ReviewerBottomBar(self),
|
2017-07-28 08:19:06 +02:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Showing the question
|
|
|
|
##########################################################################
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _mungeQA(self, buf: str) -> str:
|
2020-01-24 02:06:11 +01:00
|
|
|
return self.typeAnsFilter(self.mw.prepare_card_text_for_display(buf))
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-01-15 22:41:23 +01:00
|
|
|
def _showQuestion(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
self._reps += 1
|
|
|
|
self.state = "question"
|
2020-02-27 04:11:21 +01:00
|
|
|
self.typedAnswer: str = None
|
2012-12-21 08:51:59 +01:00
|
|
|
c = self.card
|
|
|
|
# grab the question and play audio
|
2020-05-13 03:17:44 +02:00
|
|
|
q = c.q()
|
2020-01-24 02:06:11 +01:00
|
|
|
# play audio?
|
2020-04-13 01:04:30 +02:00
|
|
|
if c.autoplay():
|
2020-10-14 02:10:16 +02:00
|
|
|
AnkiWebView.setPlaybackRequiresGesture(False)
|
2020-07-30 20:06:16 +02:00
|
|
|
sounds = c.question_av_tags()
|
|
|
|
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
|
|
|
av_player.play_tags(sounds)
|
2020-02-25 08:49:06 +01:00
|
|
|
else:
|
2020-10-14 02:10:16 +02:00
|
|
|
AnkiWebView.setPlaybackRequiresGesture(True)
|
2020-03-14 11:04:19 +01:00
|
|
|
av_player.clear_queue_and_maybe_interrupt()
|
2020-07-30 20:06:16 +02:00
|
|
|
sounds = []
|
|
|
|
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
|
|
|
av_player.play_tags(sounds)
|
2012-12-21 08:51:59 +01:00
|
|
|
# render & update bottom
|
|
|
|
q = self._mungeQA(q)
|
2020-01-15 08:45:35 +01:00
|
|
|
q = gui_hooks.card_will_show(q, c, "reviewQuestion")
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2020-01-23 06:08:10 +01:00
|
|
|
bodyclass = theme_manager.body_classes_for_card_ord(c.ord)
|
2017-07-29 06:24:45 +02:00
|
|
|
|
2021-02-11 01:09:06 +01:00
|
|
|
self.web.eval(f"_showQuestion({json.dumps(q)},'{bodyclass}');")
|
2021-03-05 13:45:55 +01:00
|
|
|
self._update_flag_icon()
|
|
|
|
self._update_mark_icon()
|
2017-08-02 08:22:54 +02:00
|
|
|
self._showAnswerButton()
|
2020-10-03 22:33:01 +02:00
|
|
|
self.mw.web.setFocus()
|
2012-12-21 08:51:59 +01:00
|
|
|
# user hook
|
2020-01-15 08:45:35 +01:00
|
|
|
gui_hooks.reviewer_did_show_question(c)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def autoplay(self, card: Card) -> bool:
|
2020-04-13 01:04:30 +02:00
|
|
|
print("use card.autoplay() instead of reviewer.autoplay(card)")
|
|
|
|
return card.autoplay()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-05 13:45:55 +01:00
|
|
|
def _update_flag_icon(self) -> None:
|
2021-03-06 15:17:17 +01:00
|
|
|
self.web.eval(f"_drawFlag({self.card.user_flag()});")
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-05 13:45:55 +01:00
|
|
|
def _update_mark_icon(self) -> None:
|
|
|
|
self.web.eval(f"_drawMark({json.dumps(self.card.note().has_tag('marked'))});")
|
|
|
|
|
|
|
|
_drawMark = _update_mark_icon
|
|
|
|
_drawFlag = _update_flag_icon
|
2017-08-16 12:30:29 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# Showing the answer
|
|
|
|
##########################################################################
|
|
|
|
|
2020-01-15 22:41:23 +01:00
|
|
|
def _showAnswer(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
if self.mw.state != "review":
|
|
|
|
# showing resetRequired screen; ignore space
|
|
|
|
return
|
|
|
|
self.state = "answer"
|
|
|
|
c = self.card
|
|
|
|
a = c.a()
|
|
|
|
# play audio?
|
2020-04-13 01:04:30 +02:00
|
|
|
if c.autoplay():
|
2020-07-30 20:06:16 +02:00
|
|
|
sounds = c.answer_av_tags()
|
|
|
|
gui_hooks.reviewer_will_play_answer_sounds(c, sounds)
|
|
|
|
av_player.play_tags(sounds)
|
2020-02-25 08:49:06 +01:00
|
|
|
else:
|
2020-03-14 11:04:19 +01:00
|
|
|
av_player.clear_queue_and_maybe_interrupt()
|
2020-07-30 20:06:16 +02:00
|
|
|
sounds = []
|
|
|
|
gui_hooks.reviewer_will_play_answer_sounds(c, sounds)
|
|
|
|
av_player.play_tags(sounds)
|
2017-08-07 08:15:15 +02:00
|
|
|
a = self._mungeQA(a)
|
2020-01-15 08:45:35 +01:00
|
|
|
a = gui_hooks.card_will_show(a, c, "reviewAnswer")
|
2012-12-21 08:51:59 +01:00
|
|
|
# render and update bottom
|
2021-02-11 01:09:06 +01:00
|
|
|
self.web.eval(f"_showAnswer({json.dumps(a)});")
|
2012-12-21 08:51:59 +01:00
|
|
|
self._showEaseButtons()
|
2020-10-03 22:33:01 +02:00
|
|
|
self.mw.web.setFocus()
|
2012-12-21 08:51:59 +01:00
|
|
|
# user hook
|
2020-01-15 08:45:35 +01:00
|
|
|
gui_hooks.reviewer_did_show_answer(c)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Answering a card
|
|
|
|
############################################################
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _answerCard(self, ease: int) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
"Reschedule card and show next."
|
|
|
|
if self.mw.state != "review":
|
|
|
|
# showing resetRequired screen; ignore key
|
|
|
|
return
|
|
|
|
if self.state != "answer":
|
|
|
|
return
|
|
|
|
if self.mw.col.sched.answerButtons(self.card) < ease:
|
|
|
|
return
|
2020-01-24 15:36:05 +01:00
|
|
|
proceed, ease = gui_hooks.reviewer_will_answer_card(
|
|
|
|
(True, ease), self, self.card
|
|
|
|
)
|
|
|
|
if not proceed:
|
|
|
|
return
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw.col.sched.answerCard(self.card, ease)
|
2020-01-24 15:36:05 +01:00
|
|
|
gui_hooks.reviewer_did_answer_card(self, self.card, ease)
|
2012-12-21 08:51:59 +01:00
|
|
|
self._answeredIds.append(self.card.id)
|
|
|
|
self.mw.autosave()
|
|
|
|
self.nextCard()
|
|
|
|
|
|
|
|
# Handlers
|
|
|
|
############################################################
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _shortcutKeys(
|
|
|
|
self,
|
|
|
|
) -> List[Union[Tuple[str, Callable], Tuple[Qt.Key, Callable]]]:
|
2017-06-22 08:36:54 +02:00
|
|
|
return [
|
|
|
|
("e", self.mw.onEditCurrent),
|
|
|
|
(" ", self.onEnterKey),
|
|
|
|
(Qt.Key_Return, self.onEnterKey),
|
|
|
|
(Qt.Key_Enter, self.onEnterKey),
|
2020-08-23 16:46:19 +02:00
|
|
|
("m", self.showContextMenu),
|
2017-06-22 08:36:54 +02:00
|
|
|
("r", self.replayAudio),
|
|
|
|
(Qt.Key_F5, self.replayAudio),
|
2021-03-06 15:17:17 +01:00
|
|
|
("Ctrl+1", lambda: self.set_flag_on_current_card(1)),
|
|
|
|
("Ctrl+2", lambda: self.set_flag_on_current_card(2)),
|
|
|
|
("Ctrl+3", lambda: self.set_flag_on_current_card(3)),
|
|
|
|
("Ctrl+4", lambda: self.set_flag_on_current_card(4)),
|
2021-03-05 13:45:55 +01:00
|
|
|
("*", self.toggle_mark_on_current_note),
|
2021-03-04 12:40:59 +01:00
|
|
|
("=", self.bury_current_note),
|
|
|
|
("-", self.bury_current_card),
|
|
|
|
("!", self.suspend_current_note),
|
|
|
|
("@", self.suspend_current_card),
|
2021-03-05 10:09:08 +01:00
|
|
|
("Ctrl+Delete", self.delete_current_note),
|
Rework reschedule tool
The old rescheduling dialog's two options have been split into two
separate menu items, "Forget", and "Set Due Date"
For cards that are not review cards, "Set Due Date" behaves like the
old reschedule option, changing the cards into a review card, and
and setting both the interval and due date to the provided number of
days.
When "Set Due Date" is applied to a review card, it no longer resets
the card's interval. Instead, it looks at how much the provided number
of days will change the original interval, and adjusts the interval by
that amount, so that cards that are answered earlier receive a smaller
next interval, and cards that are answered after a longer delay receive
a bonus.
For example, imagine a card was answered on day 5, and given an interval
of 10 days, so it has a due date of day 15.
- if on day 10 the due date is changed to day 12 (today+2), the card
is being scheduled 3 days earlier than it was supposed to be, so the
interval will be adjusted to 7 days.
- and if on day 10 the due date is changed to day 20, the interval will
be changed from 10 days to 15 days.
There is no separate option to reset the interval of a review card, but
it can be accomplished by forgetting the card(s), and then setting the
desired due date.
Other notes:
- Added the action to the review screen as well.
- Set the shortcut to Ctrl+Shift+D, and changed the existing Delete
Tags shortcut to Ctrl+Alt+Shift+A.
2021-02-07 11:58:16 +01:00
|
|
|
("Ctrl+Shift+D", self.on_set_due),
|
2017-06-22 08:36:54 +02:00
|
|
|
("v", self.onReplayRecorded),
|
|
|
|
("Shift+v", self.onRecordVoice),
|
|
|
|
("o", self.onOptions),
|
|
|
|
("1", lambda: self._answerCard(1)),
|
|
|
|
("2", lambda: self._answerCard(2)),
|
|
|
|
("3", lambda: self._answerCard(3)),
|
|
|
|
("4", lambda: self._answerCard(4)),
|
2020-01-22 03:50:33 +01:00
|
|
|
("5", self.on_pause_audio),
|
|
|
|
("6", self.on_seek_backward),
|
|
|
|
("7", self.on_seek_forward),
|
2017-06-22 08:36:54 +02:00
|
|
|
]
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def on_pause_audio(self) -> None:
|
2020-01-22 03:50:33 +01:00
|
|
|
av_player.toggle_pause()
|
|
|
|
|
|
|
|
seek_secs = 5
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def on_seek_backward(self) -> None:
|
2020-01-22 03:50:33 +01:00
|
|
|
av_player.seek_relative(-self.seek_secs)
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def on_seek_forward(self) -> None:
|
2020-01-22 03:50:33 +01:00
|
|
|
av_player.seek_relative(self.seek_secs)
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def onEnterKey(self) -> None:
|
2017-06-22 08:36:54 +02:00
|
|
|
if self.state == "question":
|
|
|
|
self._getTypedAnswer()
|
|
|
|
elif self.state == "answer":
|
2019-12-23 01:34:10 +01:00
|
|
|
self.bottom.web.evalWithCallback(
|
|
|
|
"selectedAnswerButton()", self._onAnswerButton
|
|
|
|
)
|
2018-09-24 06:16:08 +02:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _onAnswerButton(self, val: str) -> None:
|
2018-09-24 06:16:08 +02:00
|
|
|
# button selected?
|
2018-09-26 08:31:31 +02:00
|
|
|
if val and val in "1234":
|
2018-09-24 06:16:08 +02:00
|
|
|
self._answerCard(int(val))
|
|
|
|
else:
|
2017-06-22 08:36:54 +02:00
|
|
|
self._answerCard(self._defaultEase())
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _linkHandler(self, url: str) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
if url == "ans":
|
2016-07-05 05:14:45 +02:00
|
|
|
self._getTypedAnswer()
|
2012-12-21 08:51:59 +01:00
|
|
|
elif url.startswith("ease"):
|
|
|
|
self._answerCard(int(url[4:]))
|
|
|
|
elif url == "edit":
|
|
|
|
self.mw.onEditCurrent()
|
|
|
|
elif url == "more":
|
|
|
|
self.showContextMenu()
|
2020-01-21 05:47:03 +01:00
|
|
|
elif url.startswith("play:"):
|
2020-01-24 02:06:11 +01:00
|
|
|
play_clicked_audio(url, self.card)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
2016-07-07 03:08:32 +02:00
|
|
|
print("unrecognized anki link:", url)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Type in the answer
|
|
|
|
##########################################################################
|
|
|
|
|
2019-03-04 08:03:43 +01:00
|
|
|
typeAnsPat = r"\[\[type:(.+?)\]\]"
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def typeAnsFilter(self, buf: str) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
if self.state == "question":
|
|
|
|
return self.typeAnsQuestionFilter(buf)
|
|
|
|
else:
|
|
|
|
return self.typeAnsAnswerFilter(buf)
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def typeAnsQuestionFilter(self, buf: str) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
self.typeCorrect = None
|
|
|
|
clozeIdx = None
|
|
|
|
m = re.search(self.typeAnsPat, buf)
|
|
|
|
if not m:
|
|
|
|
return buf
|
|
|
|
fld = m.group(1)
|
|
|
|
# if it's a cloze, extract data
|
|
|
|
if fld.startswith("cloze:"):
|
|
|
|
# get field and cloze position
|
|
|
|
clozeIdx = self.card.ord + 1
|
|
|
|
fld = fld.split(":")[1]
|
|
|
|
# loop through fields for a match
|
2019-12-23 01:34:10 +01:00
|
|
|
for f in self.card.model()["flds"]:
|
|
|
|
if f["name"] == fld:
|
|
|
|
self.typeCorrect = self.card.note()[f["name"]]
|
2012-12-21 08:51:59 +01:00
|
|
|
if clozeIdx:
|
|
|
|
# narrow to cloze
|
2019-12-23 01:34:10 +01:00
|
|
|
self.typeCorrect = self._contentForCloze(self.typeCorrect, clozeIdx)
|
|
|
|
self.typeFont = f["font"]
|
|
|
|
self.typeSize = f["size"]
|
2012-12-21 08:51:59 +01:00
|
|
|
break
|
|
|
|
if not self.typeCorrect:
|
|
|
|
if self.typeCorrect is None:
|
|
|
|
if clozeIdx:
|
2020-11-18 02:32:22 +01:00
|
|
|
warn = tr(TR.STUDYING_PLEASE_RUN_TOOLSEMPTY_CARDS)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
2020-11-17 12:47:47 +01:00
|
|
|
warn = tr(TR.STUDYING_TYPE_ANSWER_UNKNOWN_FIELD, val=fld)
|
2012-12-21 08:51:59 +01:00
|
|
|
return re.sub(self.typeAnsPat, warn, buf)
|
|
|
|
else:
|
|
|
|
# empty field, remove type answer pattern
|
|
|
|
return re.sub(self.typeAnsPat, "", buf)
|
2019-12-23 01:34:10 +01:00
|
|
|
return re.sub(
|
|
|
|
self.typeAnsPat,
|
2021-02-11 01:09:06 +01:00
|
|
|
f"""
|
2012-12-21 08:51:59 +01:00
|
|
|
<center>
|
|
|
|
<input type=text id=typeans onkeypress="_typeAnsPress();"
|
2021-02-11 01:09:06 +01:00
|
|
|
style="font-family: '{self.typeFont}'; font-size: {self.typeSize}px;">
|
2012-12-21 08:51:59 +01:00
|
|
|
</center>
|
2021-02-11 01:09:06 +01:00
|
|
|
""",
|
2019-12-23 01:34:10 +01:00
|
|
|
buf,
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def typeAnsAnswerFilter(self, buf: str) -> str:
|
2013-06-12 04:22:13 +02:00
|
|
|
if not self.typeCorrect:
|
2013-04-27 16:12:03 +02:00
|
|
|
return re.sub(self.typeAnsPat, "", buf)
|
2013-05-20 10:56:01 +02:00
|
|
|
origSize = len(buf)
|
|
|
|
buf = buf.replace("<hr id=answer>", "")
|
|
|
|
hadHR = len(buf) != origSize
|
2012-12-21 08:51:59 +01:00
|
|
|
# munge correct value
|
2018-09-24 09:44:34 +02:00
|
|
|
cor = self.mw.col.media.strip(self.typeCorrect)
|
|
|
|
cor = re.sub("(\n|<br ?/?>|</?div>)+", " ", cor)
|
|
|
|
cor = stripHTML(cor)
|
2013-05-24 04:01:24 +02:00
|
|
|
# ensure we don't chomp multiple whitespace
|
|
|
|
cor = cor.replace(" ", " ")
|
2020-02-27 04:11:21 +01:00
|
|
|
cor = html.unescape(cor)
|
2016-05-12 06:45:35 +02:00
|
|
|
cor = cor.replace("\xa0", " ")
|
2018-09-24 09:44:34 +02:00
|
|
|
cor = cor.strip()
|
2012-12-21 08:51:59 +01:00
|
|
|
given = self.typedAnswer
|
|
|
|
# compare with typed answer
|
2013-05-20 10:32:13 +02:00
|
|
|
res = self.correct(given, cor, showBad=False)
|
2012-12-21 08:51:59 +01:00
|
|
|
# and update the type answer area
|
2021-02-01 14:28:21 +01:00
|
|
|
def repl(match: Match) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
# can't pass a string in directly, and can't use re.escape as it
|
|
|
|
# escapes too much
|
2013-05-20 10:56:01 +02:00
|
|
|
s = """
|
2012-12-21 08:51:59 +01:00
|
|
|
<span style="font-family: '%s'; font-size: %spx">%s</span>""" % (
|
2019-12-23 01:34:10 +01:00
|
|
|
self.typeFont,
|
|
|
|
self.typeSize,
|
|
|
|
res,
|
|
|
|
)
|
2013-05-20 10:56:01 +02:00
|
|
|
if hadHR:
|
|
|
|
# a hack to ensure the q/a separator falls before the answer
|
|
|
|
# comparison when user is using {{FrontSide}}
|
2021-02-11 01:09:06 +01:00
|
|
|
s = f"<hr id=answer>{s}"
|
2013-05-20 10:56:01 +02:00
|
|
|
return s
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
return re.sub(self.typeAnsPat, repl, buf)
|
|
|
|
|
2021-02-02 15:00:29 +01:00
|
|
|
def _contentForCloze(self, txt: str, idx: int) -> str:
|
2019-12-23 01:34:10 +01:00
|
|
|
matches = re.findall(r"\{\{c%s::(.+?)\}\}" % idx, txt, re.DOTALL)
|
2012-12-21 08:51:59 +01:00
|
|
|
if not matches:
|
|
|
|
return None
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2021-02-02 15:00:29 +01:00
|
|
|
def noHint(txt: str) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
if "::" in txt:
|
|
|
|
return txt.split("::")[0]
|
|
|
|
return txt
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
matches = [noHint(txt) for txt in matches]
|
2014-03-27 23:25:27 +01:00
|
|
|
uniqMatches = set(matches)
|
|
|
|
if len(uniqMatches) == 1:
|
2012-12-21 08:51:59 +01:00
|
|
|
txt = matches[0]
|
2014-03-27 23:25:27 +01:00
|
|
|
else:
|
|
|
|
txt = ", ".join(matches)
|
2012-12-21 08:51:59 +01:00
|
|
|
return txt
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def tokenizeComparison(
|
|
|
|
self, given: str, correct: str
|
|
|
|
) -> Tuple[List[Tuple[bool, str]], List[Tuple[bool, str]]]:
|
2013-06-05 11:39:42 +02:00
|
|
|
# compare in NFC form so accents appear correct
|
|
|
|
given = ucd.normalize("NFC", given)
|
|
|
|
correct = ucd.normalize("NFC", correct)
|
2017-10-18 18:12:04 +02:00
|
|
|
s = difflib.SequenceMatcher(None, given, correct, autojunk=False)
|
2020-02-27 04:11:21 +01:00
|
|
|
givenElems: List[Tuple[bool, str]] = []
|
|
|
|
correctElems: List[Tuple[bool, str]] = []
|
2013-05-20 10:32:13 +02:00
|
|
|
givenPoint = 0
|
|
|
|
correctPoint = 0
|
|
|
|
offby = 0
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def logBad(old: int, new: int, s: str, array: List[Tuple[bool, str]]) -> None:
|
2013-05-20 10:32:13 +02:00
|
|
|
if old != new:
|
2020-02-27 04:11:21 +01:00
|
|
|
array.append((False, s[old:new]))
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def logGood(
|
|
|
|
start: int, cnt: int, s: str, array: List[Tuple[bool, str]]
|
|
|
|
) -> None:
|
2013-05-20 10:32:13 +02:00
|
|
|
if cnt:
|
2020-02-27 04:11:21 +01:00
|
|
|
array.append((True, s[start : start + cnt]))
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2013-05-20 10:32:13 +02:00
|
|
|
for x, y, cnt in s.get_matching_blocks():
|
|
|
|
# if anything was missed in correct, pad given
|
2019-12-23 01:34:10 +01:00
|
|
|
if cnt and y - offby > x:
|
|
|
|
givenElems.append((False, "-" * (y - x - offby)))
|
|
|
|
offby = y - x
|
2013-05-20 10:32:13 +02:00
|
|
|
# log any proceeding bad elems
|
|
|
|
logBad(givenPoint, x, given, givenElems)
|
|
|
|
logBad(correctPoint, y, correct, correctElems)
|
2019-12-23 01:34:10 +01:00
|
|
|
givenPoint = x + cnt
|
|
|
|
correctPoint = y + cnt
|
2013-05-20 10:32:13 +02:00
|
|
|
# log the match
|
|
|
|
logGood(x, cnt, given, givenElems)
|
|
|
|
logGood(y, cnt, correct, correctElems)
|
|
|
|
return givenElems, correctElems
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def correct(self, given: str, correct: str, showBad: bool = True) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
"Diff-corrects the typed-in answer."
|
2013-05-20 10:32:13 +02:00
|
|
|
givenElems, correctElems = self.tokenizeComparison(given, correct)
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def good(s: str) -> str:
|
2021-02-11 01:09:06 +01:00
|
|
|
return f"<span class=typeGood>{html.escape(s)}</span>"
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def bad(s: str) -> str:
|
2021-02-11 01:09:06 +01:00
|
|
|
return f"<span class=typeBad>{html.escape(s)}</span>"
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def missed(s: str) -> str:
|
2021-02-11 01:09:06 +01:00
|
|
|
return f"<span class=typeMissed>{html.escape(s)}</span>"
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2013-05-20 10:32:13 +02:00
|
|
|
if given == correct:
|
|
|
|
res = good(given)
|
|
|
|
else:
|
|
|
|
res = ""
|
|
|
|
for ok, txt in givenElems:
|
2019-12-16 05:39:54 +01:00
|
|
|
txt = self._noLoneMarks(txt)
|
2013-05-20 10:32:13 +02:00
|
|
|
if ok:
|
|
|
|
res += good(txt)
|
|
|
|
else:
|
|
|
|
res += bad(txt)
|
2020-03-16 00:39:26 +01:00
|
|
|
res += "<br><span id=typearrow>↓</span><br>"
|
2013-05-20 10:32:13 +02:00
|
|
|
for ok, txt in correctElems:
|
2019-12-16 05:39:54 +01:00
|
|
|
txt = self._noLoneMarks(txt)
|
2013-05-20 10:32:13 +02:00
|
|
|
if ok:
|
|
|
|
res += good(txt)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
2013-05-20 10:32:13 +02:00
|
|
|
res += missed(txt)
|
2021-02-11 01:09:06 +01:00
|
|
|
res = f"<div><code id=typeans>{res}</code></div>"
|
2013-05-20 10:32:13 +02:00
|
|
|
return res
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _noLoneMarks(self, s: str) -> str:
|
2019-12-16 05:39:54 +01:00
|
|
|
# ensure a combining character at the start does not join to
|
|
|
|
# previous text
|
|
|
|
if s and ucd.category(s[0]).startswith("M"):
|
2021-02-11 01:09:06 +01:00
|
|
|
return f"\xa0{s}"
|
2019-12-16 05:39:54 +01:00
|
|
|
return s
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _getTypedAnswer(self) -> None:
|
2016-07-05 05:14:45 +02:00
|
|
|
self.web.evalWithCallback("typeans ? typeans.value : null", self._onTypedAnswer)
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _onTypedAnswer(self, val: None) -> None:
|
2017-10-24 09:08:36 +02:00
|
|
|
self.typedAnswer = val or ""
|
2016-07-05 05:14:45 +02:00
|
|
|
self._showAnswer()
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# Bottom bar
|
|
|
|
##########################################################################
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _bottomHTML(self) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
return """
|
2016-06-07 06:27:33 +02:00
|
|
|
<center id=outer>
|
|
|
|
<table id=innertable width=100%% cellspacing=0 cellpadding=0>
|
2012-12-21 08:51:59 +01:00
|
|
|
<tr>
|
|
|
|
<td align=left width=50 valign=top class=stat>
|
|
|
|
<br>
|
2016-06-06 07:50:03 +02:00
|
|
|
<button title="%(editkey)s" onclick="pycmd('edit');">%(edit)s</button></td>
|
2012-12-21 08:51:59 +01:00
|
|
|
<td align=center valign=top id=middle>
|
|
|
|
</td>
|
|
|
|
<td width=50 align=right valign=top class=stat><span id=time class=stattxt>
|
|
|
|
</span><br>
|
2016-06-06 07:50:03 +02:00
|
|
|
<button onclick="pycmd('more');">%(more)s %(downArrow)s</button>
|
2012-12-21 08:51:59 +01:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2016-06-07 06:27:33 +02:00
|
|
|
</center>
|
2012-12-21 08:51:59 +01:00
|
|
|
<script>
|
2017-07-28 08:19:06 +02:00
|
|
|
time = %(time)d;
|
2012-12-21 08:51:59 +01:00
|
|
|
</script>
|
2019-12-23 01:34:10 +01:00
|
|
|
""" % dict(
|
|
|
|
rem=self._remaining(),
|
2020-11-17 08:42:43 +01:00
|
|
|
edit=tr(TR.STUDYING_EDIT),
|
2020-11-17 12:47:47 +01:00
|
|
|
editkey=tr(TR.ACTIONS_SHORTCUT_KEY, val="E"),
|
2020-11-17 08:42:43 +01:00
|
|
|
more=tr(TR.STUDYING_MORE),
|
2019-12-23 01:34:10 +01:00
|
|
|
downArrow=downArrow(),
|
|
|
|
time=self.card.timeTaken() // 1000,
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _showAnswerButton(self) -> None:
|
2019-12-23 01:34:10 +01:00
|
|
|
middle = """
|
2012-12-21 08:51:59 +01:00
|
|
|
<span class=stattxt>%s</span><br>
|
2020-10-05 22:18:46 +02:00
|
|
|
<button title="%s" id="ansbut" class="focus" onclick='pycmd("ans");'>%s</button>""" % (
|
2019-12-23 01:34:10 +01:00
|
|
|
self._remaining(),
|
2020-11-17 12:47:47 +01:00
|
|
|
tr(TR.ACTIONS_SHORTCUT_KEY, val=tr(TR.STUDYING_SPACE)),
|
2020-11-17 08:42:43 +01:00
|
|
|
tr(TR.STUDYING_SHOW_ANSWER),
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
# wrap it in a table so it has the same top margin as the ease buttons
|
2019-12-23 01:34:10 +01:00
|
|
|
middle = (
|
|
|
|
"<table cellpadding=0><tr><td class=stat2 align=center>%s</td></tr></table>"
|
|
|
|
% middle
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
if self.card.shouldShowTimer():
|
|
|
|
maxTime = self.card.timeLimit() / 1000
|
|
|
|
else:
|
|
|
|
maxTime = 0
|
2019-12-23 01:34:10 +01:00
|
|
|
self.bottom.web.eval("showQuestion(%s,%d);" % (json.dumps(middle), maxTime))
|
2017-08-02 08:22:54 +02:00
|
|
|
self.bottom.web.adjustHeightToFit()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _showEaseButtons(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
middle = self._answerButtons()
|
2021-02-11 01:09:06 +01:00
|
|
|
self.bottom.web.eval(f"showAnswer({json.dumps(middle)});")
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _remaining(self) -> str:
|
2019-12-23 01:34:10 +01:00
|
|
|
if not self.mw.col.conf["dueCounts"]:
|
2012-12-21 08:51:59 +01:00
|
|
|
return ""
|
|
|
|
if self.hadCardQueue:
|
|
|
|
# if it's come from the undo queue, don't count it separately
|
2020-02-27 04:11:21 +01:00
|
|
|
counts: List[Union[int, str]] = list(self.mw.col.sched.counts())
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
|
|
|
counts = list(self.mw.col.sched.counts(self.card))
|
|
|
|
idx = self.mw.col.sched.countIdx(self.card)
|
2021-02-11 01:09:06 +01:00
|
|
|
counts[idx] = f"<u>{counts[idx]}</u>"
|
2012-12-21 08:51:59 +01:00
|
|
|
space = " + "
|
2021-02-11 01:09:06 +01:00
|
|
|
ctxt = f"<span class=new-count>{counts[0]}</span>"
|
|
|
|
ctxt += f"{space}<span class=learn-count>{counts[1]}</span>"
|
|
|
|
ctxt += f"{space}<span class=review-count>{counts[2]}</span>"
|
2012-12-21 08:51:59 +01:00
|
|
|
return ctxt
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _defaultEase(self) -> int:
|
2012-12-21 08:51:59 +01:00
|
|
|
if self.mw.col.sched.answerButtons(self.card) == 4:
|
|
|
|
return 3
|
|
|
|
else:
|
|
|
|
return 2
|
|
|
|
|
2020-08-19 22:15:49 +02:00
|
|
|
def _answerButtonList(self) -> Tuple[Tuple[int, str], ...]:
|
2020-08-18 16:37:45 +02:00
|
|
|
button_count = self.mw.col.sched.answerButtons(self.card)
|
|
|
|
if button_count == 2:
|
2020-08-21 04:34:44 +02:00
|
|
|
buttons_tuple: Tuple[Tuple[int, str], ...] = (
|
2020-11-17 08:42:43 +01:00
|
|
|
(1, tr(TR.STUDYING_AGAIN)),
|
|
|
|
(2, tr(TR.STUDYING_GOOD)),
|
2020-08-21 04:34:44 +02:00
|
|
|
)
|
2020-08-18 16:37:45 +02:00
|
|
|
elif button_count == 3:
|
2020-11-17 08:42:43 +01:00
|
|
|
buttons_tuple = (
|
|
|
|
(1, tr(TR.STUDYING_AGAIN)),
|
|
|
|
(2, tr(TR.STUDYING_GOOD)),
|
|
|
|
(3, tr(TR.STUDYING_EASY)),
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
2020-08-21 04:34:44 +02:00
|
|
|
buttons_tuple = (
|
2020-11-17 08:42:43 +01:00
|
|
|
(1, tr(TR.STUDYING_AGAIN)),
|
|
|
|
(2, tr(TR.STUDYING_HARD)),
|
|
|
|
(3, tr(TR.STUDYING_GOOD)),
|
|
|
|
(4, tr(TR.STUDYING_EASY)),
|
2020-08-21 04:34:44 +02:00
|
|
|
)
|
|
|
|
buttons_tuple = gui_hooks.reviewer_will_init_answer_buttons(
|
|
|
|
buttons_tuple, self, self.card
|
|
|
|
)
|
2020-08-18 16:37:45 +02:00
|
|
|
return buttons_tuple
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _answerButtons(self) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
default = self._defaultEase()
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2021-02-02 15:00:29 +01:00
|
|
|
def but(i: int, label: str) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
if i == default:
|
2020-10-05 22:18:46 +02:00
|
|
|
extra = """id="defease" class="focus" """
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
|
|
|
extra = ""
|
|
|
|
due = self._buttonTime(i)
|
2019-12-23 01:34:10 +01:00
|
|
|
return """
|
2018-09-24 06:16:08 +02:00
|
|
|
<td align=center>%s<button %s title="%s" data-ease="%s" onclick='pycmd("ease%d");'>\
|
2019-12-23 01:34:10 +01:00
|
|
|
%s</button></td>""" % (
|
|
|
|
due,
|
|
|
|
extra,
|
2020-11-17 12:47:47 +01:00
|
|
|
tr(TR.ACTIONS_SHORTCUT_KEY, val=i),
|
2019-12-23 01:34:10 +01:00
|
|
|
i,
|
|
|
|
i,
|
|
|
|
label,
|
|
|
|
)
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
buf = "<center><table cellpading=0 cellspacing=0><tr>"
|
|
|
|
for ease, label in self._answerButtonList():
|
|
|
|
buf += but(ease, label)
|
|
|
|
buf += "</tr></table>"
|
|
|
|
script = """
|
|
|
|
<script>$(function () { $("#defease").focus(); });</script>"""
|
|
|
|
return buf + script
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def _buttonTime(self, i: int) -> str:
|
2019-12-23 01:34:10 +01:00
|
|
|
if not self.mw.col.conf["estTimes"]:
|
2012-12-21 08:51:59 +01:00
|
|
|
return "<div class=spacer></div>"
|
|
|
|
txt = self.mw.col.sched.nextIvlStr(self.card, i, True) or " "
|
2021-02-11 01:09:06 +01:00
|
|
|
return f"<span class=nobold>{txt}</span><br>"
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Leeches
|
|
|
|
##########################################################################
|
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def onLeech(self, card: Card) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
# for now
|
2020-11-17 08:42:43 +01:00
|
|
|
s = tr(TR.STUDYING_CARD_WAS_A_LEECH)
|
2012-12-21 08:51:59 +01:00
|
|
|
if card.queue < 0:
|
2021-02-11 01:09:06 +01:00
|
|
|
s += f" {tr(TR.STUDYING_IT_HAS_BEEN_SUSPENDED)}"
|
2012-12-21 08:51:59 +01:00
|
|
|
tooltip(s)
|
|
|
|
|
|
|
|
# Context menu
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
# note the shortcuts listed here also need to be defined above
|
2021-02-01 13:08:56 +01:00
|
|
|
def _contextMenu(self) -> List[Any]:
|
2021-03-06 15:17:17 +01:00
|
|
|
currentFlag = self.card and self.card.user_flag()
|
2012-12-21 08:51:59 +01:00
|
|
|
opts = [
|
2019-12-23 01:34:10 +01:00
|
|
|
[
|
2020-11-17 08:42:43 +01:00
|
|
|
tr(TR.STUDYING_FLAG_CARD),
|
2019-12-23 01:34:10 +01:00
|
|
|
[
|
|
|
|
[
|
2020-11-17 08:42:43 +01:00
|
|
|
tr(TR.ACTIONS_RED_FLAG),
|
2019-12-23 01:34:10 +01:00
|
|
|
"Ctrl+1",
|
2021-03-06 15:17:17 +01:00
|
|
|
lambda: self.set_flag_on_current_card(1),
|
2019-12-23 01:34:10 +01:00
|
|
|
dict(checked=currentFlag == 1),
|
|
|
|
],
|
|
|
|
[
|
2020-11-17 08:42:43 +01:00
|
|
|
tr(TR.ACTIONS_ORANGE_FLAG),
|
2019-12-23 01:34:10 +01:00
|
|
|
"Ctrl+2",
|
2021-03-06 15:17:17 +01:00
|
|
|
lambda: self.set_flag_on_current_card(2),
|
2019-12-23 01:34:10 +01:00
|
|
|
dict(checked=currentFlag == 2),
|
|
|
|
],
|
|
|
|
[
|
2020-11-17 08:42:43 +01:00
|
|
|
tr(TR.ACTIONS_GREEN_FLAG),
|
2019-12-23 01:34:10 +01:00
|
|
|
"Ctrl+3",
|
2021-03-06 15:17:17 +01:00
|
|
|
lambda: self.set_flag_on_current_card(3),
|
2019-12-23 01:34:10 +01:00
|
|
|
dict(checked=currentFlag == 3),
|
|
|
|
],
|
|
|
|
[
|
2020-11-17 08:42:43 +01:00
|
|
|
tr(TR.ACTIONS_BLUE_FLAG),
|
2019-12-23 01:34:10 +01:00
|
|
|
"Ctrl+4",
|
2021-03-06 15:17:17 +01:00
|
|
|
lambda: self.set_flag_on_current_card(4),
|
2019-12-23 01:34:10 +01:00
|
|
|
dict(checked=currentFlag == 4),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2021-03-05 13:45:55 +01:00
|
|
|
[tr(TR.STUDYING_MARK_NOTE), "*", self.toggle_mark_on_current_note],
|
2021-03-04 12:40:59 +01:00
|
|
|
[tr(TR.STUDYING_BURY_CARD), "-", self.bury_current_card],
|
|
|
|
[tr(TR.STUDYING_BURY_NOTE), "=", self.bury_current_note],
|
Rework reschedule tool
The old rescheduling dialog's two options have been split into two
separate menu items, "Forget", and "Set Due Date"
For cards that are not review cards, "Set Due Date" behaves like the
old reschedule option, changing the cards into a review card, and
and setting both the interval and due date to the provided number of
days.
When "Set Due Date" is applied to a review card, it no longer resets
the card's interval. Instead, it looks at how much the provided number
of days will change the original interval, and adjusts the interval by
that amount, so that cards that are answered earlier receive a smaller
next interval, and cards that are answered after a longer delay receive
a bonus.
For example, imagine a card was answered on day 5, and given an interval
of 10 days, so it has a due date of day 15.
- if on day 10 the due date is changed to day 12 (today+2), the card
is being scheduled 3 days earlier than it was supposed to be, so the
interval will be adjusted to 7 days.
- and if on day 10 the due date is changed to day 20, the interval will
be changed from 10 days to 15 days.
There is no separate option to reset the interval of a review card, but
it can be accomplished by forgetting the card(s), and then setting the
desired due date.
Other notes:
- Added the action to the review screen as well.
- Set the shortcut to Ctrl+Shift+D, and changed the existing Delete
Tags shortcut to Ctrl+Alt+Shift+A.
2021-02-07 11:58:16 +01:00
|
|
|
[tr(TR.ACTIONS_SET_DUE_DATE), "Ctrl+Shift+D", self.on_set_due],
|
2021-03-04 12:40:59 +01:00
|
|
|
[tr(TR.ACTIONS_SUSPEND_CARD), "@", self.suspend_current_card],
|
|
|
|
[tr(TR.STUDYING_SUSPEND_NOTE), "!", self.suspend_current_note],
|
2021-03-05 10:09:08 +01:00
|
|
|
[tr(TR.STUDYING_DELETE_NOTE), "Ctrl+Delete", self.delete_current_note],
|
2020-11-17 08:42:43 +01:00
|
|
|
[tr(TR.ACTIONS_OPTIONS), "O", self.onOptions],
|
2012-12-21 08:51:59 +01:00
|
|
|
None,
|
2020-11-17 08:42:43 +01:00
|
|
|
[tr(TR.ACTIONS_REPLAY_AUDIO), "R", self.replayAudio],
|
|
|
|
[tr(TR.STUDYING_PAUSE_AUDIO), "5", self.on_pause_audio],
|
|
|
|
[tr(TR.STUDYING_AUDIO_5S), "6", self.on_seek_backward],
|
|
|
|
[tr(TR.STUDYING_AUDIO_AND5S), "7", self.on_seek_forward],
|
|
|
|
[tr(TR.STUDYING_RECORD_OWN_VOICE), "Shift+V", self.onRecordVoice],
|
|
|
|
[tr(TR.STUDYING_REPLAY_OWN_VOICE), "V", self.onReplayRecorded],
|
2012-12-21 08:51:59 +01:00
|
|
|
]
|
2018-01-07 18:19:49 +01:00
|
|
|
return opts
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2020-01-15 22:41:23 +01:00
|
|
|
def showContextMenu(self) -> None:
|
2018-01-07 18:19:49 +01:00
|
|
|
opts = self._contextMenu()
|
2012-12-21 08:51:59 +01:00
|
|
|
m = QMenu(self.mw)
|
2017-08-12 08:08:10 +02:00
|
|
|
self._addMenuItems(m, opts)
|
|
|
|
|
2020-01-15 08:45:35 +01:00
|
|
|
gui_hooks.reviewer_will_show_context_menu(self, m)
|
2019-02-05 05:37:07 +01:00
|
|
|
qtMenuShortcutWorkaround(m)
|
2017-08-12 08:08:10 +02:00
|
|
|
m.exec_(QCursor.pos())
|
|
|
|
|
2021-02-02 15:00:29 +01:00
|
|
|
def _addMenuItems(self, m: QMenu, rows: Sequence) -> None:
|
2017-08-12 08:08:10 +02:00
|
|
|
for row in rows:
|
2012-12-21 08:51:59 +01:00
|
|
|
if not row:
|
|
|
|
m.addSeparator()
|
|
|
|
continue
|
2017-08-12 08:08:10 +02:00
|
|
|
if len(row) == 2:
|
|
|
|
subm = m.addMenu(row[0])
|
|
|
|
self._addMenuItems(subm, row[1])
|
2019-02-05 05:37:07 +01:00
|
|
|
qtMenuShortcutWorkaround(subm)
|
2017-08-12 08:08:10 +02:00
|
|
|
continue
|
2018-11-12 03:01:54 +01:00
|
|
|
if len(row) == 4:
|
|
|
|
label, scut, func, opts = row
|
|
|
|
else:
|
|
|
|
label, scut, func = row
|
|
|
|
opts = {}
|
2012-12-21 08:51:59 +01:00
|
|
|
a = m.addAction(label)
|
2017-01-10 09:39:31 +01:00
|
|
|
if scut:
|
|
|
|
a.setShortcut(QKeySequence(scut))
|
2018-11-12 03:01:54 +01:00
|
|
|
if opts.get("checked"):
|
|
|
|
a.setCheckable(True)
|
|
|
|
a.setChecked(True)
|
2020-05-04 05:23:08 +02:00
|
|
|
qconnect(a.triggered, func)
|
2017-08-12 08:08:10 +02:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def onOptions(self) -> None:
|
2019-12-23 01:34:10 +01:00
|
|
|
self.mw.onDeckConf(self.mw.col.decks.get(self.card.odid or self.card.did))
|
2012-12-21 08:51:59 +01:00
|
|
|
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
def set_flag_on_current_card(self, desired_flag: int) -> None:
|
|
|
|
def op() -> None:
|
|
|
|
# need to toggle off?
|
|
|
|
if self.card.user_flag() == desired_flag:
|
|
|
|
flag = 0
|
|
|
|
else:
|
|
|
|
flag = desired_flag
|
|
|
|
self.mw.col.set_user_flag_for_cards(flag, [self.card.id])
|
|
|
|
|
|
|
|
self.mw.perform_op(op)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-05 13:45:55 +01:00
|
|
|
def toggle_mark_on_current_note(self) -> None:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
def op() -> None:
|
|
|
|
tag = "marked"
|
|
|
|
note = self.card.note()
|
|
|
|
if note.has_tag(tag):
|
|
|
|
self.mw.col.tags.bulk_remove([note.id], tag)
|
|
|
|
else:
|
|
|
|
self.mw.col.tags.bulk_add([note.id], tag)
|
|
|
|
|
|
|
|
self.mw.perform_op(op)
|
2017-08-16 12:30:29 +02:00
|
|
|
|
Rework reschedule tool
The old rescheduling dialog's two options have been split into two
separate menu items, "Forget", and "Set Due Date"
For cards that are not review cards, "Set Due Date" behaves like the
old reschedule option, changing the cards into a review card, and
and setting both the interval and due date to the provided number of
days.
When "Set Due Date" is applied to a review card, it no longer resets
the card's interval. Instead, it looks at how much the provided number
of days will change the original interval, and adjusts the interval by
that amount, so that cards that are answered earlier receive a smaller
next interval, and cards that are answered after a longer delay receive
a bonus.
For example, imagine a card was answered on day 5, and given an interval
of 10 days, so it has a due date of day 15.
- if on day 10 the due date is changed to day 12 (today+2), the card
is being scheduled 3 days earlier than it was supposed to be, so the
interval will be adjusted to 7 days.
- and if on day 10 the due date is changed to day 20, the interval will
be changed from 10 days to 15 days.
There is no separate option to reset the interval of a review card, but
it can be accomplished by forgetting the card(s), and then setting the
desired due date.
Other notes:
- Added the action to the review screen as well.
- Set the shortcut to Ctrl+Shift+D, and changed the existing Delete
Tags shortcut to Ctrl+Alt+Shift+A.
2021-02-07 11:58:16 +01:00
|
|
|
def on_set_due(self) -> None:
|
|
|
|
if self.mw.state != "review" or not self.card:
|
|
|
|
return
|
|
|
|
|
|
|
|
set_due_date_dialog(
|
|
|
|
mw=self.mw,
|
|
|
|
parent=self.mw,
|
|
|
|
card_ids=[self.card.id],
|
2021-03-12 05:50:31 +01:00
|
|
|
config_key=Config.String.SET_DUE_REVIEWER,
|
Rework reschedule tool
The old rescheduling dialog's two options have been split into two
separate menu items, "Forget", and "Set Due Date"
For cards that are not review cards, "Set Due Date" behaves like the
old reschedule option, changing the cards into a review card, and
and setting both the interval and due date to the provided number of
days.
When "Set Due Date" is applied to a review card, it no longer resets
the card's interval. Instead, it looks at how much the provided number
of days will change the original interval, and adjusts the interval by
that amount, so that cards that are answered earlier receive a smaller
next interval, and cards that are answered after a longer delay receive
a bonus.
For example, imagine a card was answered on day 5, and given an interval
of 10 days, so it has a due date of day 15.
- if on day 10 the due date is changed to day 12 (today+2), the card
is being scheduled 3 days earlier than it was supposed to be, so the
interval will be adjusted to 7 days.
- and if on day 10 the due date is changed to day 20, the interval will
be changed from 10 days to 15 days.
There is no separate option to reset the interval of a review card, but
it can be accomplished by forgetting the card(s), and then setting the
desired due date.
Other notes:
- Added the action to the review screen as well.
- Set the shortcut to Ctrl+Shift+D, and changed the existing Delete
Tags shortcut to Ctrl+Alt+Shift+A.
2021-02-07 11:58:16 +01:00
|
|
|
)
|
|
|
|
|
2021-03-04 12:40:59 +01:00
|
|
|
def suspend_current_note(self) -> None:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
self.mw.perform_op(
|
|
|
|
lambda: self.mw.col.sched.suspend_cards(
|
|
|
|
[c.id for c in self.card.note().cards()]
|
|
|
|
),
|
|
|
|
success=lambda _: tooltip(tr(TR.STUDYING_NOTE_SUSPENDED)),
|
|
|
|
)
|
2013-01-29 01:46:17 +01:00
|
|
|
|
2021-03-04 12:40:59 +01:00
|
|
|
def suspend_current_card(self) -> None:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
self.mw.perform_op(
|
|
|
|
lambda: self.mw.col.sched.suspend_cards([self.card.id]),
|
|
|
|
success=lambda _: tooltip(tr(TR.STUDYING_CARD_SUSPENDED)),
|
|
|
|
)
|
2021-03-04 12:40:59 +01:00
|
|
|
|
|
|
|
def bury_current_card(self) -> None:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
self.mw.perform_op(
|
|
|
|
lambda: self.mw.col.sched.bury_cards([self.card.id]),
|
|
|
|
success=lambda _: tooltip(tr(TR.STUDYING_CARD_BURIED)),
|
|
|
|
)
|
2021-03-04 12:40:59 +01:00
|
|
|
|
|
|
|
def bury_current_note(self) -> None:
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
self.mw.perform_op(
|
|
|
|
lambda: self.mw.col.sched.bury_note(self.card.note()),
|
|
|
|
success=lambda _: tooltip(tr(TR.STUDYING_NOTE_BURIED)),
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-05 10:09:08 +01:00
|
|
|
def delete_current_note(self) -> None:
|
2012-12-22 00:51:21 +01:00
|
|
|
# need to check state because the shortcut is global to the main
|
|
|
|
# window
|
|
|
|
if self.mw.state != "review" or not self.card:
|
|
|
|
return
|
2012-12-21 08:51:59 +01:00
|
|
|
cnt = len(self.card.note().cards())
|
2021-03-13 14:59:32 +01:00
|
|
|
|
|
|
|
self.mw.perform_op(
|
|
|
|
lambda: self.mw.col.remove_notes([self.card.note().id]),
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
success=lambda _: tooltip(
|
|
|
|
tr(TR.STUDYING_NOTE_AND_ITS_CARD_DELETED, count=cnt)
|
|
|
|
),
|
2021-03-13 14:59:32 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def onRecordVoice(self) -> None:
|
2021-02-01 14:28:21 +01:00
|
|
|
def after_record(path: str) -> None:
|
2020-12-16 10:09:45 +01:00
|
|
|
self._recordedAudio = path
|
|
|
|
self.onReplayRecorded()
|
|
|
|
|
2020-12-18 07:52:00 +01:00
|
|
|
record_audio(self.mw, self.mw, False, after_record)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-27 04:11:21 +01:00
|
|
|
def onReplayRecorded(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
if not self._recordedAudio:
|
2020-11-17 08:42:43 +01:00
|
|
|
tooltip(tr(TR.STUDYING_YOU_HAVENT_RECORDED_YOUR_VOICE_YET))
|
2020-02-27 04:11:21 +01:00
|
|
|
return
|
2020-01-20 11:10:38 +01:00
|
|
|
av_player.play_file(self._recordedAudio)
|
2021-03-04 12:40:59 +01:00
|
|
|
|
|
|
|
# legacy
|
|
|
|
|
|
|
|
onBuryCard = bury_current_card
|
|
|
|
onBuryNote = bury_current_note
|
|
|
|
onSuspend = suspend_current_note
|
|
|
|
onSuspendCard = suspend_current_card
|
2021-03-05 10:09:08 +01:00
|
|
|
onDelete = delete_current_note
|
2021-03-05 13:45:55 +01:00
|
|
|
onMark = toggle_mark_on_current_note
|
2021-03-06 15:17:17 +01:00
|
|
|
setFlag = set_flag_on_current_card
|