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
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-10-03 10:59:42 +02:00
|
|
|
from typing import Sequence
|
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
|
|
|
|
|
|
|
import aqt
|
2022-02-13 04:40:47 +01:00
|
|
|
import aqt.forms
|
2021-03-27 12:38:20 +01:00
|
|
|
from anki.cards import CardId
|
2021-04-06 08:38:42 +02:00
|
|
|
from anki.collection import (
|
|
|
|
CARD_TYPE_NEW,
|
2021-05-11 03:37:08 +02:00
|
|
|
Collection,
|
2021-04-06 08:38:42 +02:00
|
|
|
Config,
|
|
|
|
OpChanges,
|
|
|
|
OpChangesWithCount,
|
|
|
|
OpChangesWithId,
|
|
|
|
)
|
2021-03-27 12:38:20 +01:00
|
|
|
from anki.decks import DeckId
|
|
|
|
from anki.notes import NoteId
|
2022-01-20 05:25:22 +01:00
|
|
|
from anki.scheduler import CustomStudyRequest, FilteredDeckForUpdate, UnburyDeck
|
2022-03-09 07:51:41 +01:00
|
|
|
from anki.scheduler.base import ScheduleCardsAsNew
|
2021-05-11 03:37:08 +02:00
|
|
|
from anki.scheduler.v3 import CardAnswer
|
|
|
|
from anki.scheduler.v3 import Scheduler as V3Scheduler
|
2021-04-06 08:38:42 +02:00
|
|
|
from aqt.operations import CollectionOp
|
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.qt import *
|
2021-03-18 02:46:11 +01:00
|
|
|
from aqt.utils import disable_help_button, getText, tooltip, tr
|
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 set_due_date_dialog(
|
|
|
|
*,
|
2021-03-17 05:51:59 +01:00
|
|
|
parent: QWidget,
|
2021-03-29 08:48:33 +02:00
|
|
|
card_ids: Sequence[CardId],
|
2021-10-03 10:59:42 +02:00
|
|
|
config_key: Config.String.V | None,
|
|
|
|
) -> CollectionOp[OpChanges] | None:
|
2021-04-06 09:07:38 +02:00
|
|
|
assert aqt.mw
|
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
|
|
|
if not card_ids:
|
2021-04-06 08:38:42 +02:00
|
|
|
return None
|
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
|
|
|
|
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
|
|
|
default_text = (
|
2021-04-06 08:38:42 +02:00
|
|
|
aqt.mw.col.get_config_string(config_key) if config_key is not None else ""
|
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
|
|
|
)
|
2021-02-08 13:33:27 +01:00
|
|
|
prompt = "\n".join(
|
|
|
|
[
|
2021-03-26 05:21:04 +01:00
|
|
|
tr.scheduling_set_due_date_prompt(cards=len(card_ids)),
|
2021-03-26 04:48:26 +01:00
|
|
|
tr.scheduling_set_due_date_prompt_hint(),
|
2021-02-08 13:33:27 +01: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
|
|
|
(days, success) = getText(
|
2021-02-08 13:33:27 +01:00
|
|
|
prompt=prompt,
|
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
|
|
|
parent=parent,
|
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
|
|
|
default=default_text,
|
2021-03-26 04:48:26 +01:00
|
|
|
title=tr.actions_set_due_date(),
|
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
|
|
|
)
|
|
|
|
if not success or not days.strip():
|
2021-04-06 08:38:42 +02:00
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return CollectionOp(
|
|
|
|
parent, lambda col: col.sched.set_due_date(card_ids, days, config_key)
|
|
|
|
).success(
|
|
|
|
lambda _: tooltip(
|
|
|
|
tr.scheduling_set_due_date_done(cards=len(card_ids)),
|
|
|
|
parent=parent,
|
|
|
|
)
|
|
|
|
)
|
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-29 09:12:45 +02:00
|
|
|
def forget_cards(
|
2022-03-09 07:51:41 +01:00
|
|
|
*,
|
|
|
|
parent: QWidget,
|
|
|
|
card_ids: Sequence[CardId],
|
|
|
|
context: ScheduleCardsAsNew.Context.V | None = None,
|
|
|
|
) -> CollectionOp[OpChanges] | None:
|
|
|
|
assert aqt.mw
|
|
|
|
|
|
|
|
dialog = QDialog(parent)
|
|
|
|
disable_help_button(dialog)
|
|
|
|
form = aqt.forms.forget.Ui_Dialog()
|
|
|
|
form.setupUi(dialog)
|
|
|
|
|
|
|
|
if context is not None:
|
|
|
|
defaults = aqt.mw.col.sched.schedule_cards_as_new_defaults(context)
|
|
|
|
form.restore_position.setChecked(defaults.restore_position)
|
|
|
|
form.reset_counts.setChecked(defaults.reset_counts)
|
|
|
|
|
|
|
|
if not dialog.exec():
|
|
|
|
return None
|
|
|
|
|
|
|
|
restore_position = form.restore_position.isChecked()
|
|
|
|
reset_counts = form.reset_counts.isChecked()
|
|
|
|
|
2021-04-06 08:38:42 +02:00
|
|
|
return CollectionOp(
|
2022-03-09 07:51:41 +01:00
|
|
|
parent,
|
|
|
|
lambda col: col.sched.schedule_cards_as_new(
|
|
|
|
card_ids,
|
|
|
|
restore_position=restore_position,
|
|
|
|
reset_counts=reset_counts,
|
|
|
|
context=context,
|
|
|
|
),
|
2021-04-06 08:38:42 +02:00
|
|
|
).success(
|
|
|
|
lambda _: tooltip(
|
2021-03-26 05:21:04 +01:00
|
|
|
tr.scheduling_forgot_cards(cards=len(card_ids)), parent=parent
|
2021-04-06 08:38:42 +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
|
|
|
)
|
undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.
Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-16 05:26:42 +01:00
|
|
|
|
|
|
|
|
2021-03-18 02:46:11 +01:00
|
|
|
def reposition_new_cards_dialog(
|
2022-07-08 03:28:38 +02:00
|
|
|
*,
|
|
|
|
parent: QWidget,
|
|
|
|
card_ids: Sequence[CardId],
|
2021-10-03 10:59:42 +02:00
|
|
|
) -> CollectionOp[OpChangesWithCount] | None:
|
2021-04-06 08:38:42 +02:00
|
|
|
from aqt import mw
|
|
|
|
|
2021-04-06 09:07:38 +02:00
|
|
|
assert mw
|
2021-03-18 02:46:11 +01:00
|
|
|
assert mw.col.db
|
2021-04-06 09:07:38 +02:00
|
|
|
|
2021-03-18 02:46:11 +01:00
|
|
|
row = mw.col.db.first(
|
|
|
|
f"select min(due), max(due) from cards where type={CARD_TYPE_NEW} and odid=0"
|
|
|
|
)
|
|
|
|
assert row
|
|
|
|
(min_position, max_position) = row
|
|
|
|
min_position = max(min_position or 0, 0)
|
|
|
|
max_position = max_position or 0
|
|
|
|
|
2022-07-08 03:28:38 +02:00
|
|
|
dialog = QDialog(parent)
|
|
|
|
disable_help_button(dialog)
|
|
|
|
dialog.setWindowModality(Qt.WindowModality.WindowModal)
|
|
|
|
form = aqt.forms.reposition.Ui_Dialog()
|
|
|
|
form.setupUi(dialog)
|
2021-03-18 02:46:11 +01:00
|
|
|
|
2021-03-26 05:21:04 +01:00
|
|
|
txt = tr.browsing_queue_top(val=min_position)
|
|
|
|
txt += "\n" + tr.browsing_queue_bottom(val=max_position)
|
2022-07-08 03:28:38 +02:00
|
|
|
form.label.setText(txt)
|
|
|
|
|
|
|
|
form.start.selectAll()
|
2021-03-18 02:46:11 +01:00
|
|
|
|
2022-07-08 03:28:38 +02:00
|
|
|
defaults = mw.col.sched.reposition_defaults()
|
|
|
|
form.randomize.setChecked(defaults.random)
|
|
|
|
form.shift.setChecked(defaults.shift)
|
|
|
|
|
|
|
|
if not dialog.exec():
|
2021-04-06 08:38:42 +02:00
|
|
|
return None
|
2021-03-18 02:46:11 +01:00
|
|
|
|
2022-07-08 03:28:38 +02:00
|
|
|
start = form.start.value()
|
|
|
|
step = form.step.value()
|
|
|
|
randomize = form.randomize.isChecked()
|
|
|
|
shift = form.shift.isChecked()
|
2021-03-18 02:46:11 +01:00
|
|
|
|
2021-04-06 08:38:42 +02:00
|
|
|
return reposition_new_cards(
|
2021-03-18 02:46:11 +01:00
|
|
|
parent=parent,
|
|
|
|
card_ids=card_ids,
|
|
|
|
starting_from=start,
|
|
|
|
step_size=step,
|
|
|
|
randomize=randomize,
|
|
|
|
shift_existing=shift,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def reposition_new_cards(
|
|
|
|
*,
|
|
|
|
parent: QWidget,
|
2021-03-27 12:38:20 +01:00
|
|
|
card_ids: Sequence[CardId],
|
2021-03-18 02:46:11 +01:00
|
|
|
starting_from: int,
|
|
|
|
step_size: int,
|
|
|
|
randomize: bool,
|
|
|
|
shift_existing: bool,
|
2021-04-06 08:38:42 +02:00
|
|
|
) -> CollectionOp[OpChangesWithCount]:
|
|
|
|
return CollectionOp(
|
|
|
|
parent,
|
|
|
|
lambda col: col.sched.reposition_new_cards(
|
2021-03-18 02:46:11 +01:00
|
|
|
card_ids=card_ids,
|
|
|
|
starting_from=starting_from,
|
|
|
|
step_size=step_size,
|
|
|
|
randomize=randomize,
|
|
|
|
shift_existing=shift_existing,
|
|
|
|
),
|
2021-04-06 08:38:42 +02:00
|
|
|
).success(
|
|
|
|
lambda out: tooltip(
|
2021-03-26 05:21:04 +01:00
|
|
|
tr.browsing_changed_new_position(count=out.count), parent=parent
|
2021-04-06 08:38:42 +02:00
|
|
|
)
|
2021-03-18 02:46:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.
Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-16 05:26:42 +01:00
|
|
|
def suspend_cards(
|
|
|
|
*,
|
2021-04-06 08:38:42 +02:00
|
|
|
parent: QWidget,
|
2021-03-27 12:38:20 +01:00
|
|
|
card_ids: Sequence[CardId],
|
2021-04-06 08:38:42 +02:00
|
|
|
) -> CollectionOp[OpChangesWithCount]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.suspend_cards(card_ids))
|
undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.
Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-16 05:26:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
def suspend_note(
|
|
|
|
*,
|
2021-04-06 08:38:42 +02:00
|
|
|
parent: QWidget,
|
|
|
|
note_ids: Sequence[NoteId],
|
|
|
|
) -> CollectionOp[OpChangesWithCount]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.suspend_notes(note_ids))
|
undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.
Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-16 05:26:42 +01:00
|
|
|
|
|
|
|
|
2021-04-06 08:38:42 +02:00
|
|
|
def unsuspend_cards(
|
|
|
|
*, parent: QWidget, card_ids: Sequence[CardId]
|
|
|
|
) -> CollectionOp[OpChanges]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.unsuspend_cards(card_ids))
|
undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.
Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-16 05:26:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
def bury_cards(
|
|
|
|
*,
|
2021-04-06 08:38:42 +02:00
|
|
|
parent: QWidget,
|
2021-03-27 12:38:20 +01:00
|
|
|
card_ids: Sequence[CardId],
|
2021-04-06 08:38:42 +02:00
|
|
|
) -> CollectionOp[OpChangesWithCount]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.bury_cards(card_ids))
|
undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.
Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-16 05:26:42 +01:00
|
|
|
|
|
|
|
|
2021-04-06 08:38:42 +02:00
|
|
|
def bury_notes(
|
undoable ops now return changes directly; add new *_ops.py files
- Introduced a new transact() method that wraps the return value
in a separate struct that describes the changes that were made.
- Changes are now gathered from the undo log, so we don't need to
guess at what was changed - eg if update_note() is called with identical
note contents, no changes are returned. Card changes will only be set
if cards were actually generated by the update_note() call, and tag
will only be set if a new tag was added.
- mw.perform_op() has been updated to expect the op to return the changes,
or a structure with the changes in it, and it will use them to fire the
change hook, instead of fetching the changes from undo_status(), so there
is no risk of race conditions.
- the various calls to mw.perform_op() have been split into separate
files like card_ops.py. Aside from making the code cleaner, this works
around a rather annoying issue with mypy. Because we run it with
no_strict_optional, mypy is happy to accept an operation that returns None,
despite the type signature saying it requires changes to be returned.
Turning no_strict_optional on for the whole codebase is not practical
at the moment, but we can enable it for individual files.
Still todo:
- The cursor keeps moving back to the start of a field when typing -
we need to ignore the refresh hook when we are the initiator.
- The busy cursor icon should probably be delayed a few hundreds ms.
- Still need to think about a nicer way of handling saveNow()
- op_made_changes(), op_affects_study_queue() might be better embedded
as properties in the object instead
2021-03-16 05:26:42 +01:00
|
|
|
*,
|
2021-04-06 08:38:42 +02:00
|
|
|
parent: QWidget,
|
|
|
|
note_ids: Sequence[NoteId],
|
|
|
|
) -> CollectionOp[OpChangesWithCount]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.bury_notes(note_ids))
|
2021-03-24 03:56:06 +01:00
|
|
|
|
|
|
|
|
2021-12-08 00:44:47 +01:00
|
|
|
def unbury_cards(
|
|
|
|
*, parent: QWidget, card_ids: Sequence[CardId]
|
|
|
|
) -> CollectionOp[OpChanges]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.unbury_cards(card_ids))
|
|
|
|
|
|
|
|
|
2021-04-06 08:38:42 +02:00
|
|
|
def rebuild_filtered_deck(
|
|
|
|
*, parent: QWidget, deck_id: DeckId
|
|
|
|
) -> CollectionOp[OpChangesWithCount]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.rebuild_filtered_deck(deck_id))
|
2021-03-24 03:56:06 +01:00
|
|
|
|
|
|
|
|
2021-04-06 08:38:42 +02:00
|
|
|
def empty_filtered_deck(*, parent: QWidget, deck_id: DeckId) -> CollectionOp[OpChanges]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.empty_filtered_deck(deck_id))
|
rework filtered deck screen & search errors
- Filtered deck creation now happens as an atomic operation, and is
undoable.
- The logic for initial search text, normalizing searches and so on
has been pushed into the backend.
- Use protobuf to pass the filtered deck to the updated dialog, so
we don't need to deal with untyped JSON.
- Change the "revise your search?" prompt to be a simple info box -
user has access to cancel and build buttons, and doesn't need a separate
prompt. Tweak the wording so the 'show excluded' button should be more
obvious.
- Filtered decks have a time appended to them instead of a number,
primarily because it's easier to implement. No objections going back to
the old behaviour if someone wants to contribute a clean patch.
The standard de-duplication will happen if two decks are created in the
same minute with the same name.
- Tweak the default sort order, and start with two searches. The UI
will still hide the second search by default, but by starting with two,
the frontend doesn't need logic for creating the starting text.
- Search errors now have their own error type, instead of using
InvalidInput, as that was intended mainly for bad API calls. The markdown
conversion is done when the error is converted from the backend, allowing
errors to printed as a string without any special handling by the calling
code.
TODO: when building a new filtered deck, update_active() is clobbering
the undo log when the overview is refreshed
2021-03-24 12:52:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
def add_or_update_filtered_deck(
|
|
|
|
*,
|
2021-04-06 08:38:42 +02:00
|
|
|
parent: QWidget,
|
rework filtered deck screen & search errors
- Filtered deck creation now happens as an atomic operation, and is
undoable.
- The logic for initial search text, normalizing searches and so on
has been pushed into the backend.
- Use protobuf to pass the filtered deck to the updated dialog, so
we don't need to deal with untyped JSON.
- Change the "revise your search?" prompt to be a simple info box -
user has access to cancel and build buttons, and doesn't need a separate
prompt. Tweak the wording so the 'show excluded' button should be more
obvious.
- Filtered decks have a time appended to them instead of a number,
primarily because it's easier to implement. No objections going back to
the old behaviour if someone wants to contribute a clean patch.
The standard de-duplication will happen if two decks are created in the
same minute with the same name.
- Tweak the default sort order, and start with two searches. The UI
will still hide the second search by default, but by starting with two,
the frontend doesn't need logic for creating the starting text.
- Search errors now have their own error type, instead of using
InvalidInput, as that was intended mainly for bad API calls. The markdown
conversion is done when the error is converted from the backend, allowing
errors to printed as a string without any special handling by the calling
code.
TODO: when building a new filtered deck, update_active() is clobbering
the undo log when the overview is refreshed
2021-03-24 12:52:48 +01:00
|
|
|
deck: FilteredDeckForUpdate,
|
2021-04-06 08:38:42 +02:00
|
|
|
) -> CollectionOp[OpChangesWithId]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.add_or_update_filtered_deck(deck))
|
2021-04-30 12:03:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
def unbury_deck(
|
|
|
|
*,
|
|
|
|
parent: QWidget,
|
|
|
|
deck_id: DeckId,
|
|
|
|
mode: UnburyDeck.Mode.V = UnburyDeck.ALL,
|
|
|
|
) -> CollectionOp[OpChanges]:
|
|
|
|
return CollectionOp(
|
|
|
|
parent, lambda col: col.sched.unbury_deck(deck_id=deck_id, mode=mode)
|
|
|
|
)
|
2021-05-11 03:37:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
def answer_card(
|
|
|
|
*,
|
|
|
|
parent: QWidget,
|
|
|
|
answer: CardAnswer,
|
|
|
|
) -> CollectionOp[OpChanges]:
|
|
|
|
def answer_v3(col: Collection) -> OpChanges:
|
|
|
|
assert isinstance(col.sched, V3Scheduler)
|
|
|
|
return col.sched.answer_card(answer)
|
|
|
|
|
|
|
|
return CollectionOp(parent, answer_v3)
|
2022-01-20 05:25:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
def custom_study(
|
|
|
|
*,
|
|
|
|
parent: QWidget,
|
|
|
|
request: CustomStudyRequest,
|
|
|
|
) -> CollectionOp[OpChanges]:
|
|
|
|
return CollectionOp(parent, lambda col: col.sched.custom_study(request))
|