Commit Graph

1246 Commits

Author SHA1 Message Date
Damien Elmes
d120cd7f8a update to latest mypy
mypy's move to external types-* packages is a PITA, as it requires them
to be installed in site-packages, and provides no way to specify a custom
site-packages folder, necessitating extra scripts to mock the
site-packages path, and copy+rename the stub packages into a separate
folder.
2021-06-16 16:04:59 +10:00
Damien Elmes
dcfb2f1052 multiple assignment confuses mypy 2021-06-15 08:42:34 +02:00
RumovZ
46d226c5a8 Fix typo 2021-06-13 08:59:58 +02:00
RumovZ
ab7c07e830 Use fields_check() instead of duplicate_or_empty() 2021-06-12 17:34:46 +02:00
RumovZ
9acc03773a Check for out-of-place/missing clozes when adding 2021-06-12 10:05:42 +02:00
RumovZ
aeedb4dc11 Add check for out-of-place/missing clozes 2021-06-12 10:02:21 +02:00
Damien Elmes
968bd1b27a specific encoding of strings.json
https://forums.ankiweb.net/t/win10-build-error-unicodedecodeerror-gbk-codec-cant-decode-byte-0x91/10714
2021-06-11 20:12:38 +10:00
Damien Elmes
61e86cc29d new change notetype implementation for the frontend
- changes can now be undone
- the same field can now be mapped to multiple target fields, allowing
fields to be cloned
- the old Qt dialog has been removed
- the old col.models.change() API calls the new code, to avoid
breaking existing consumers. It requires the field map to always
be passed in, but that appears to have been the common case.
- closes #1175
2021-06-10 22:19:24 +10:00
cherryblossom
92fe68abfe
fix documentation links 2021-06-03 16:51:03 +10:00
Damien Elmes
368e3d6d92 fix styling changes not updating preview
regression caused by 050ef11a96
2021-06-02 15:13:34 +10:00
Damien Elmes
578b1b0552
Merge pull request #1213 from RumovZ/new-flags
Add pink, turquoise and purple flags
2021-06-02 11:22:26 +10:00
Damien Elmes
0f5627bb7a limit custom study to 100 tags
The hard limit from sqlite may be larger, but things slow down as more
tags are selected.

https://forums.ankiweb.net/t/unable-to-create-custom-test/10467

There are a number of things that could be improved here:

- we should show a live count so users are aware of the limit
- we should be filling in the parent tags when they're not explicitly
listed on a card
- we should reconsider disabling the 'tags to include' by default

It may make sense to defer these changes until we can move this screen
into Svelte/handle the processing in the backend.
2021-06-02 11:15:39 +10:00
RumovZ
c97c6c6e98 Add violet, turquoise and purple flags 2021-05-31 12:03:30 +02:00
Damien Elmes
29c4869aef remove deck protobuf from frontend
Like the previous change, avoid exposing the protobuf as a public API
for now. It requires more thought, and is probably better done with
either extra helper accessors like decks.name(), or via a native class.
2021-05-31 16:31:06 +10:00
Damien Elmes
bb323615dd remove deck config and notetype protobuf from frontend
Not yet used by anything yet, and we may want to use native classes
for these instead, like is done for Notes and Cards. Decks to follow.
2021-05-31 16:27:58 +10:00
Damien Elmes
25e4e4c8f6 fix exporting of non-default deck configs 2021-05-31 16:27:58 +10:00
Damien Elmes
93459cc48f
Merge pull request #1200 from RumovZ/template-checks
Template checks
2021-05-29 10:28:06 +10:00
RumovZ
33bf391114 Allow empty field name in templates 2021-05-28 11:37:05 +02:00
RumovZ
c6e78e6f21 Adjusts tests to pass new template checks 2021-05-28 10:08:55 +02:00
Damien Elmes
6cc713cbe8 add v3 scheduler to prefs screen 2021-05-27 23:09:49 +10:00
Damien Elmes
903eefc5c9 next_states() didn't need to be public 2021-05-26 15:12:48 +10:00
Damien Elmes
57ec4cc7b5 change get_queued_cards() to no longer return congrats info 2021-05-26 12:59:45 +10:00
RumovZ
6fae0ea21f Update tests to avoid duplicate front templates 2021-05-25 21:58:12 +02:00
Damien Elmes
e9309c5378 expose the ability to get/set aux notetype/template keys
template keys are not currently adjusted when card templates are
repositioned.
2021-05-25 22:13:53 +10:00
Damien Elmes
050ef11a96 pass css and latex svg flag back from rendering op
This could potentially help us avoid having to refetch the notetype
during study in the future, though updates to Note initialization and
the LaTeX handling would be required first.
2021-05-25 18:41:43 +10:00
Damien Elmes
02c7f7989e support passing in a native notetype object to render_uncommitted_card() 2021-05-25 16:58:06 +10:00
Damien Elmes
10aa897674 prevent models.setCurrent() clearing the undo queue 2021-05-24 14:54:31 +10:00
Damien Elmes
adcdb422c5 config updates by the frontend now skip undo by default 2021-05-24 14:50:46 +10:00
abdo
f4143b6025 Fix wrong stock note type being used
https://forums.ankiweb.net/t/anki-2-1-45-alpha/10061/49
2021-05-23 07:56:59 +03:00
Damien Elmes
3d4cf26758 expose undoable config changes to frontend; refresh sidebar
The browser header handling still needs updating
2021-05-21 17:50:41 +10:00
Damien Elmes
99b7da49a9 report changed cards when changing deck/flag
+ fix repeated flag shortcut not toggling
2021-05-21 16:03:05 +10:00
Damien Elmes
cbd2314e27 add v3 scheduler to col.sched type union
Will allow us to catch issues like the custom study one in the future
2021-05-19 16:06:52 +10:00
Damien Elmes
b6a3842fd9 fix custom study in v3 scheduler 2021-05-19 15:58:18 +10:00
Damien Elmes
590ef6da0a compat fixes for add-on usage of col.decks.active() 2021-05-19 15:41:37 +10:00
Damien Elmes
9f3f6bab7d enable redo support
Also:

- fix issues where the Undo action in the Browse screen was not
consistent with the main window. The existing hook signature has been
changed; from a snapshot of the add-on code from a few months ago, it
was not a hook that was being used by anyone.
- change the undo shortcut in the Browse window to match the main
window. It was different because undoing a change in the editing area
could accidentally trigger an undo of an operation, but the damage is
limited now that (most) operations can be redone. If it still proves to
be a problem, perhaps we should just always swallow ctrl+z when an
editing field is focused.
2021-05-19 15:18:39 +10:00
RumovZ
3b5e8e5041 Fix black workaround for format calls 2021-05-18 22:19:09 +02:00
Damien Elmes
009878f75d add legacy NoteType alias
https://github.com/johnpincock/SpecialFields/issues/28
2021-05-18 09:18:46 +10:00
Damien Elmes
13519a929c rework various aspects of the test scheduler
- Daily limits are no longer inherited - each deck limits its own
cards, and the selected deck enforces a maximum limit.
- Fetching of review cards now uses a single query, and sorts in advance.
In collections with a large number of overdue cards and decks, this is
faster than iterating over each deck in turn.
- Include interday learning count in review count & review limit, and
allow them to be buried.
- Warn when parent review limit is lower than child deck in deck options.
- Cap the new card limit to the review limit.
- Add option to control whether new card fetching short-circuits.
2021-05-16 20:23:07 +10:00
Damien Elmes
c41d5ca4bf work around Windows issue on latest Black
Thanks Rumo!
d797900386
2021-05-13 20:15:51 +10:00
Damien Elmes
dbbcb3e38c expose new sorting options in test scheduler options; move things around 2021-05-13 15:23:16 +10:00
Damien Elmes
49a1580566 use new API for test scheduler
Avoids duplicate work, and is a step towards allowing the next
states to be modified by third-party code.

Also:

- fixed incorrect underlined count, due to reviews being labeled as
learning cards
- fixed reviewer not refreshing when undoing a test review, by splitting
up backend queue rebuilding from frontend reviewer refresh
- moved answering into a CollectionOp
2021-05-11 13:06:03 +10:00
Damien Elmes
6622ea1c70 drop leech hook in test scheduler
The explicit flush was clearing undo history, and the hook will need
re-working to support propagating OpChanges correctly. It will likely
come back as a GUI hook, instead of one in pylib.
2021-05-10 16:18:29 +10:00
Damien Elmes
ea319b3dfc ensure v2 scheduler before test scheduler enabled 2021-05-10 14:57:30 +10:00
Damien Elmes
1918031399 update find_duplicates to use QueryOp/CollectionOp 2021-05-08 16:58:18 +10:00
Damien Elmes
7442eed41a update docstrings for latest black 2021-05-07 18:12:56 +10:00
Damien Elmes
d878de54c0 default to the v2 scheduler in new collections
ported from 53d9433d94
2021-05-06 19:09:28 +10:00
Damien Elmes
6ca089c36c don't throw an error when an invalid sort order is provided 2021-05-06 17:00:58 +10:00
Damien Elmes
be994f4102 add support for custom undo steps, and merging multiple actions
Allows add-on authors to define their own label for a group of undoable
operations. For example:

def mark_and_bury(
    *,
    parent: QWidget,
    card_id: CardId,
) -> CollectionOp[OpChanges]:
    def op(col: Collection) -> OpChanges:
        target = col.add_custom_undo_entry("Mark and Bury")
        col.sched.bury_cards([card_id])
        card = col.get_card(card_id)
        col.tags.bulk_add(note_ids=[card.nid], tags="marked")
        return col.merge_undo_entries(target)

    return CollectionOp(parent, op)

The .add_custom_undo_entry() is for adding your own custom actions.
When extending a standard Anki action, instead store `target = 
col.undo_status().last_step` after executing the standard operation.

This started out as a bigger refactor that required a separate
.commit_undoable() call to be run after each operation, instead of
having each operation return changes directly. But that proved to be
somewhat cumbersome in unit tests, and ran the risk of unexpected
behaviour if the caller invoked an operation without remembering to
finalize it.
2021-05-06 16:39:06 +10:00
Damien Elmes
abab4826bb support undo for (renamed) unbury_deck() action 2021-04-30 20:03:20 +10:00
Damien Elmes
9a46ad6352 undoing of notetype fields
- fix stale cache issue
- update add cards screen in response to op changes
2021-04-30 17:15:59 +10:00
Damien Elmes
394fe86f8f notetype removal undoable 2021-04-30 16:01:47 +10:00
Damien Elmes
ea758f0092 update GUI to allow notetype addition undo
- backend now updates current notetype as part of addition
- frontend no longer implicitly adds, so we can assign a new name and
add in a single operation
2021-04-30 15:58:08 +10:00
Damien Elmes
610f0b5254 use aux var when retrieving last deck for notetype
The adding case was already covered by defaults_for_adding(), but we
the code was using the old variable when adding new cards to an existing
note.
2021-04-29 19:15:27 +10:00
rgreenblatt
c7772794aa solve missing escape of ' (fixes #1144) 2021-04-22 00:54:11 -04:00
Damien Elmes
55277aa90a implement deck config saving on JS end 2021-04-20 19:50:05 +10:00
Damien Elmes
76eb119870 add schema change prompt to removal, tweak return struct 2021-04-18 17:33:12 +10:00
Damien Elmes
7f738c11a2 deck config prototype work in progress
Still in the early stages, and not hooked up yet.
2021-04-14 22:33:10 +10:00
Damien Elmes
c49d6ce49f run black/isort on Python scripts 2021-04-14 18:22:02 +10:00
Damien Elmes
28fdbd67ae add missing copyright headers to *.rs 2021-04-13 18:59:16 +10:00
Damien Elmes
948fc5f777 add missing copyright headers to *.py 2021-04-13 18:45:35 +10:00
RumovZ
fadec3dc5b Merge branch 'master' into backend-columns 2021-04-11 11:18:15 +02:00
RumovZ
801f52df40 Remove from_config variant in pb SortOrder
Instead, fetch the config order on the frontend and pass a builtin
variant into the backend.
That makes the following unnecessary:
* Resolving the config sort in search/mod.rs
* Deserializing the Column enum
* Config accessors for the sort columns
2021-04-10 11:13:42 +02:00
RumovZ
d7f7deafd4 Store active browser columns in col state 2021-04-09 22:53:02 +02:00
RumovZ
055a5e8a04 Remove pb SortKind enum and use pb Columns instead 2021-04-09 18:50:30 +02:00
RumovZ
bdd257e140 Merge SortKind enum into Column enum 2021-04-09 18:03:29 +02:00
RumovZ
c74078ea9e Unify state columns
* Remove duplicate backend columns
* Remove duplicate column routines
* Move columns on frontend from state to model
* Generate available columns from Colum enum
* Add second column label for notes mode
2021-04-08 23:48:24 +02:00
RumovZ
dd56dc6650 Rename columns for future mode-independent use 2021-04-08 23:43:48 +02:00
RumovZ
f78401619a Remove Column class and use pb class instead 2021-04-08 11:17:25 +02:00
RumovZ
6c3c479906 Move BrowserColumn into BrowserColumns message 2021-04-08 10:16:06 +02:00
RumovZ
a5c02910a6 Use backend column objects on frontend 2021-04-06 19:47:03 +02:00
Damien Elmes
6e954e82a5 current deck change is now undoable
- make sure we set flag in changes when config var changed
- move current deck get/set into backend
- set_config() now returns a bool indicating whether a change was
made, so other operations can be gated off it
- active decks generation is deferred until sched.reset()
2021-04-06 21:52:06 +10:00
Damien Elmes
84fe309583 update scheduling ops
- migrate to CollectionOp()
- return actual change count when suspending/burying
- add helper to convert vec to vec of newtype
2021-04-06 16:38:42 +10:00
Damien Elmes
2de8cc1a94 update note ops
remove_note() now returns the count of removed cards, allowing us
to unify the tooltip between browser and review screen

I've left the old translation in - we'll need to write a script at
one point that gathers all references to translations in the code,
and shows ones that are unused.
2021-04-06 14:56:36 +10:00
Damien Elmes
3f62f54f14 more perform_op() tweaks
- pass the handler directly
- reviewer special-cases for flags and notes are now applied at
call site
- drop the kind attribute on OpChanges which is not needed
2021-04-06 10:14:11 +10:00
Damien Elmes
996d9f9bbc undo support for tag collapse; expand->collapse for consistency w/ decks 2021-04-05 11:47:12 +10:00
Damien Elmes
2168dfe63d add routine to set deck collapse state
Updating a deck via protobuf is now exposed on the backend, but not
currently on the frontend - I suspect we'll be better off writing
separate routines for the actions we need instead, and we get a better
undo description for free.

This is currently causing an ugly redraw in the browse screen, which
will need fixing.
2021-04-05 11:19:04 +10:00
Damien Elmes
42a4d11416 embed deck config and expose to frontend 2021-04-04 22:52:53 +10:00
Damien Elmes
c4b3ab62c8 embed deck messages 2021-04-04 21:41:16 +10:00
Damien Elmes
1a4c4373d2 expose read-only access to new notetype objects 2021-04-04 20:45:37 +10:00
Damien Elmes
c60b88cd2f expose read-only access to new deck objects 2021-04-04 20:39:56 +10:00
Damien Elmes
41c5a25dc8 simplify errors
- use a flat enum instead of oneof messages, most of which were empty
- tidy up the Python side
2021-04-03 16:06:46 +10:00
Damien Elmes
f666f15b63 use perform_op() for undo()
Instead of manually updating the UI after undoing, we just rely
on the same change notification infrastructure regular operations
use.
2021-04-03 14:38:49 +10:00
Damien Elmes
e73359510d move filtered deck labels to backend
- use strum to generate an iterator for the protobuf enum so we don't
forget to add new labels if extending in the future
- no add-ons appear to be using dynOrderLabels(), so it has been removed

@RumovZ perhaps a similar approach might work for listing the available
browser columns as well?
2021-04-01 23:53:38 +10:00
Damien Elmes
ac1b9fadde merge the filtered deck errors into an enum
Fixes the wrong message being shown when trying to move cards to a
filtered deck
2021-04-01 22:30:00 +10:00
RumovZ
ffe77b1291 Add browser column enum for backend 2021-03-30 11:59:52 +02:00
RumovZ
7b316a7151 Move order docstring back into find_cards() 2021-03-29 12:03:31 +02:00
Damien Elmes
28aae21d51 List->Sequence in a bunch of table/browser methods
Most code doesn't require a list specifically, and build a list
is an extra step.
2021-03-29 16:48:33 +10:00
Damien Elmes
13011f9708 avoid rebuilding card/note id list when searching 2021-03-29 16:25:55 +10:00
RumovZ
0d8b1c9d0b squash merge browser refactor
Closes #1100
2021-03-29 16:14:54 +10:00
Damien Elmes
cfac40febc switch NoteType to Notetype
When used as a variable, we were typically calling it a 'notetype', not
a 'note type'.
2021-03-27 22:03:19 +10:00
Damien Elmes
716b474314 add Dict suffix to Dict aliases in models.py 2021-03-27 21:46:49 +10:00
Damien Elmes
9f4a06abee ID -> Id in protobuf and Python
follow-up to dc81a7fed0
2021-03-27 21:38:20 +10:00
Damien Elmes
89d249b3b6 update to the latest rules_rust + security framework update 2021-03-27 19:28:19 +10:00
Damien Elmes
d6b9cc4d9b drop the legacy enum from rslib, and pass separate module/message idx 2021-03-27 11:56:31 +10:00
Damien Elmes
f485efce16 update remaining TR references in rslib 2021-03-27 11:18:34 +10:00
Damien Elmes
698ae855d3 update 1 arg tr strings in rslib 2021-03-27 10:39:53 +10:00
Damien Elmes
dc5fdd30d4 update no-arg TR references in rslib/ 2021-03-26 23:16:08 +10:00
Damien Elmes
b57e9be46f allow js to request specific i18n modules
Brings the payload on the congrats page with a non-English language
down from about 150k to 15k
2021-03-26 21:43:36 +10:00
Damien Elmes
1ca25c563f update most no-arg TR references in *.svelte 2021-03-26 19:13:30 +10:00
Damien Elmes
cd4572c3dd update TR references with args in *.svelte 2021-03-26 19:13:30 +10:00
Damien Elmes
df93ed0b15 update TR references with args in *.ts; fix average answer time 2021-03-26 19:10:39 +10:00
Damien Elmes
b435658acb convert no-arg TR references to method invocations in *.ts 2021-03-26 19:10:27 +10:00
Damien Elmes
3d366d5264 add types to some more Fluent variables 2021-03-26 16:52:54 +10:00
Damien Elmes
8cc6758eb1 declare variables with some common names as int instead of a union 2021-03-26 16:33:53 +10:00
Damien Elmes
e687552aeb update TR references that crossed multiple lines 2021-03-26 14:38:15 +10:00
Damien Elmes
b7587cb8d2 update TR references that contain arguments 2021-03-26 14:21:04 +10:00
Damien Elmes
0c338bfd53 update no-arg tr references in qt/ 2021-03-26 13:48:26 +10:00
Damien Elmes
ebe655975c update some more TR references in pylib; update tr_legacyglobal 2021-03-26 13:33:46 +10:00
Damien Elmes
efb1ce46d4 switch the Importers global to a callable for i18n
I18n is not set up at init time, so the strings can't be generated
at import.

@kelciour you have a few importing add-ons, so wanted to give you a
heads-up. The importing code is likely to change more in
future months, but for now this should be the only change
2021-03-26 13:28:21 +10:00
Damien Elmes
48354931da update some no-arg TR constants 2021-03-26 12:37:18 +10:00
Damien Elmes
07c6c4044c Merge branch 'int_type' into main 2021-03-26 11:38:34 +10:00
Damien Elmes
bc2c3a57ba fix incorrect constant naming 2021-03-26 11:29:07 +10:00
Damien Elmes
64bb526008 fix incorrect camelCase 2021-03-26 11:28:51 +10:00
Damien Elmes
7d5014fd5f fix typo and PEP8 naming in noteimp.py 2021-03-26 11:28:18 +10:00
Damien Elmes
8e0f00fbb9 fix .select() not handling string arguments 2021-03-26 11:27:49 +10:00
Arthur Milchior
be630adab9 NF: CardType type 2021-03-26 11:14:08 +10:00
Arthur Milchior
365de5f232 NF: CardQueue type 2021-03-26 11:14:08 +10:00
Arthur Milchior
7ea862931c NF: NoteTypeID type 2021-03-26 11:14:08 +10:00
Arthur Milchior
b54410200e NF: DeckConfID 2021-03-26 11:14:08 +10:00
Arthur Milchior
6ac1e6477e NF: DeckID type 2021-03-26 11:14:08 +10:00
Arthur Milchior
08e13013b2 NF: default_deck_conf_id as constant
So that the 1 is clearer
2021-03-26 11:14:08 +10:00
Arthur Milchior
b8f715ffea NF: default_deck_id as a constant
Otherwise it's not clear what this 1 represents
2021-03-26 11:14:08 +10:00
Arthur Milchior
3b6802530d NF: currentDeckID factorize odid or did 2021-03-26 11:14:08 +10:00
Arthur Milchior
986efeed19 NF: CardID type 2021-03-26 11:14:08 +10:00
Arthur Milchior
6ac540927a NF: NoteID type 2021-03-26 11:14:08 +10:00
Arthur Milchior
23083c3eb4 NF: add types to noteimp.py 2021-03-26 11:14:08 +10:00
Damien Elmes
9aece2a7b8 rework translation handling
Instead of generating a fluent.proto file with a giant enum, create
a .json file representing the translations that downstream consumers
can use for code generation.

This enables the generation of a separate method for each translation,
with a docstring that shows the actual text, and any required arguments
listed in the function signature.

The codebase is still using the old enum for now; updating it will need
to come in future commits, and the old enum will need to be kept
around, as add-ons are referencing it.

Other changes:

- move translation code into a separate crate
- store the translations on a per-file/module basis, which will allow
us to avoid sending 1000+ strings on each JS page load in the future
- drop the undocumented support for external .ftl files, that we weren't
using
- duplicate strings in translation files are now checked for at build
time
- fix i18n test failing when run outside Bazel
- drop slog dependency in i18n module
2021-03-26 09:41:32 +10:00
Damien Elmes
4b5944f181 move markdown dep into pylib 2021-03-24 22:19:14 +10:00
Damien Elmes
d382b33585 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 22:04:35 +10:00
Damien Elmes
181cda1979 rename&simplify the deck/config type aliases
- QueueConfig is only used by the scheduler
- DeckConfig was being used in places that Config should have been used
- Add "Dict" to the name so that the bare name is free for use with a
stronger type.
2021-03-24 16:29:02 +10:00
Damien Elmes
12597e1094 support undo of filtered deck build/empty 2021-03-24 12:56:06 +10:00
Damien Elmes
5fd79d9246
Merge pull request #1082 from RumovZ/backend-rows
Backend rows
2021-03-23 18:31:42 +10:00
Damien Elmes
84b0c8ba88 switch DeckID to a NewType
Not sure at this point whether this will buy us much in the Python
codebase over a simple int alias, but let's give it a go.
2021-03-22 23:43:54 +10:00
Damien Elmes
01161c8ed2 use perform_op() for deck creation 2021-03-22 23:17:07 +10:00
Damien Elmes
0123a382ec deck rename with perform_op() 2021-03-22 20:38:51 +10:00
Damien Elmes
6a11c0398c use perform_op() for deck drag&drop 2021-03-22 18:23:56 +10:00
Damien Elmes
7273996041 fix note importing detecting changes due to unicode differences
https://forums.ankiweb.net/t/python-checksum-rust-checksum/8195/16
2021-03-22 10:56:24 +10:00
RumovZ
a5be72742c Add BrowserRow to ignored classes 2021-03-20 16:06:26 +01:00
RumovZ
922fccee58 Use backend rows in browser.py 2021-03-20 12:03:26 +01:00
Damien Elmes
4c61c92806 speed up tag drag&drop and finish tag tidyup
approx 4x speedup when reparenting 10-15 tags and their children at once
2021-03-19 19:45:21 +10:00
Damien Elmes
9c2bff5b6d change bulk_update() into find_and_replace_tag()
Now behaves the same way as standard find&replace:
- Will match substrings
- Regexs can be used to match multiple items; we no longer split
input on spaces.
- The find&replace dialog has been updated to add tags to the field
list.
2021-03-19 19:45:21 +10:00
Damien Elmes
08895c58d9 introduce separate routine to remove tags from specific notes
We were (ab)using the bulk update routine to do deletions, but that
code was really intended to be used for finding&replacing, where an
exact match is not a requirement.
2021-03-19 19:45:21 +10:00
Damien Elmes
1621f2ff26 remove temp variable 2021-03-19 19:45:21 +10:00
Damien Elmes
09076da937 make tag deletion undoable, and speed it up
- ~4x faster than before on tag tree with 30k notes
- remove the separate clear_tag() backend method
2021-03-19 19:45:21 +10:00
Damien Elmes
157b74b671 make tag renaming undoable, and speed it up
~3x speedup when renaming a tag that's on 25k notes
2021-03-19 19:45:21 +10:00
Damien Elmes
2d8e45b6da tidy up flag/mark code 2021-03-19 19:45:21 +10:00
Damien Elmes
0331d8b588 make reposition undoable 2021-03-19 19:45:21 +10:00
Damien Elmes
de668441b5 clear_unused_tags and browser redraw improvements
- clear_unused_tags() is now undoable, and returns the number of removed
notes
- add a new mw.query_op() helper for immutable queries
- decouple "freeze/unfreeze ui state" hooks from the "interface update
required" hook, so that the former is fired even on error, and can be
made re-entrant
- use a 'block_updates' flag in Python, instead of setUpdatesEnabled(),
as the latter has the side-effect of preventing child windows like
tooltips from appearing, and forces a full redrawn when updates are
enabled again. The new behaviour leads to the card list blanking out
when a long-running op is running, but in the future if we cache the
cell values we can just display them from the cache instead.
- we were indiscriminately saving the note with saveNow(), due to the
call to saveTags(). Changed so that it only saves when the tags field
is focused.
- drain the "on_done" queue on main before launching a new background
task, to lower the chances of something in on_done making a small query
to the DB and hanging until a long op finishes
- the duplicate check in the editor was executed after the webview loads,
leading to it hanging until the sidebar finishes loading. Run it at
set_note() time instead, so that the editor loads first.
- don't throw an error when a long-running op started with with_progress()
finishes after the window it was launched from has closed
- don't throw an error when the browser is closed before the sidebar
has finished loading
2021-03-19 19:45:21 +10:00
Damien Elmes
6b0fe4b381 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-19 19:45:21 +10:00
Damien Elmes
1e849316be 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-19 19:45:21 +10:00
Damien Elmes
112cbe8b59 experiment with finer-scoped reset in perform_op()
Basic proof of concept, where the 'delete note' operation in the
reviewer has been updated to use mw.perform_op(). Instead of manually
calling .reset() afterwards, a summary of the changes is returned as
part of the undo status query, and various parts of the GUI can listen
to gui_hooks.operation_did_execute and decide whether they want to
redraw based on the scope of the changes. This should allow the sidebar
to selectively redraw just the tags area in the future for example.

Currently we're just listing out all possible areas that might be changed;
in the future we could theoretically inspect the specific changes in the
undo log to provide a more accurate report (avoiding refreshing the tags
list when no tags were added for example).

You can test it out by opening the browse screen while studying, and
then deleting the current card - the browser should update to show (deleted)
on the cards due the earlier change.

If going ahead with this, aside from updating all the screens that currently
listen for resets, some thought will be required on how we can integrate
it with legacy code that expects to called when resets are made, and expects
to call .reset() when it makes changes.

Thoughts?
2021-03-19 19:45:21 +10:00
Damien Elmes
8fc43956c2 move collection mtime bump into backend
Fixes the following issue:
- some code directly modifies the database, causing modified_in_python
to be set to true
- an undoable operation is run, which calls autosave() at the end
- autosave() notices there's an undoable operation, and commits immediately
- because modified_in_python was true, col.mtime was bumped in Python
- that invalidated the undo queue, preventing the operation from being
undone
2021-03-19 19:45:21 +10:00
Damien Elmes
a90a6ab3cd normalize first field before comparing with local DB
https://forums.ankiweb.net/t/python-checksum-rust-checksum/8195/8
2021-03-17 22:22:58 +10:00
Damien Elmes
7472181aeb Revert "ensure fields normalized before checksumming"
This reverts commit f4bd867b3b54b172125d2f2021c8c6a6e69c4c4d.
2021-03-17 22:21:13 +10:00
Damien Elmes
f8b5210df9 fix schema not being modified
https://forums.ankiweb.net/t/python-checksum-rust-checksum/8195/8
2021-03-17 22:18:31 +10:00
Damien Elmes
1ab085dfab ensure fields normalized before checksumming
https://forums.ankiweb.net/t/python-checksum-rust-checksum/8195
2021-03-13 10:23:32 +10:00
Damien Elmes
44dc3f494c avoid hanging UI when undoing in browse screen 2021-03-12 18:54:08 +10:00
Damien Elmes
57a05a2ae3 undo in background, and show progress window 2021-03-12 17:54:56 +10:00
Damien Elmes
c1316bb65f 'set due date' now undoable 2021-03-12 14:50:31 +10:00
Damien Elmes
ec8adf7371 move old scheduler files into scheduler/
Includes a hack that should allow existing imports to continue to work;
if this breaks things for you, please let me know.
2021-03-12 14:43:45 +10:00
Damien Elmes
ad973bb701 split out common scheduler code into base.py, use scheduler/ dir
Also move the legacy aliases into a separate file
2021-03-12 14:07:52 +10:00
RumovZ
f4c2fe6485 Merge branch 'master' into sidebar-tools 2021-03-11 12:08:32 +01:00
RumovZ
dad92e1e22 Annotate decks.rem as deprecated 2021-03-11 11:26:35 +01:00
Damien Elmes
984e2c2666 add a separate 'rename deck' method 2021-03-11 19:24:54 +10:00
RumovZ
f1dd010489 Remove deck remove prompt but show card count 2021-03-11 09:52:11 +01:00
Damien Elmes
4bd120cc4b split out remaining rpc methods
@david-allison-1 note this also changes the method index to start at
0 instead of 1
2021-03-11 17:04:32 +10:00
Damien Elmes
cd14987812 split out tags, deck config and card rendering 2021-03-11 16:05:06 +10:00
Damien Elmes
5df684fa6b rework backend codegen to support multiple services; split out sched
Rust requires all methods of impl Trait to be in a single file, which
means we had a giant backend/mod.rs covering all exposed methods. By
using separate service definitions for the separate areas, and updating
the code generation, we can split it into more manageable chunks -
this commit starts with the scheduling code.

In the long run, we'll probably want to split up the protobuf file into
multiple files as well.

Also dropped want_release_gil() from rsbridge, and the associated method
enum. While it allows us to skip the thread save/restore and mutex unlock/
lock, it looks to only be buying about 2.5% extra performance in the
best case (tested with timeit+format_timespan), and the majority of
the backend methods deal with I/O, and thus were already releasing the
GIL.
2021-03-11 14:51:29 +10:00
RumovZ
0c2ac4ba04 Merge branch 'master' into sidebar-tools 2021-03-10 10:34:36 +01:00
Damien Elmes
ce243c2cae Simplify note adding and the deck/notetype choosers
The existing code was really difficult to reason about:

- The default notetype depended on the selected deck, and vice versa,
and this logic was buried in the deck and notetype choosing screens,
and models.py.
- Changes to the notetype were not passed back directly, but were fired
via a hook, which changed any screen in the app that had a notetype
selector.

It also wasn't great for performance, as the most recent deck and tags
were embedded in the notetype, which can be expensive to save and sync
for large notetypes.

To address these points:

- The current deck for a notetype, and notetype for a deck, are now
stored in separate config variables, instead of directly in the deck
or notetype. These are cheap to read and write, and we'll be able to
sync them individually in the future once config syncing is updated in
the future. I seem to recall some users not wanting the tag saving
behaviour, so I've dropped that for now, but if people end up missing
it, it would be simple to add as an extra auxiliary config variable.
- The logic for getting the starting deck and notetype has been moved
into the backend. It should be the same as the older Python code, with
one exception: when "change deck depending on notetype" is enabled in
the preferences, it will start with the current notetype ("curModel"),
instead of first trying to get a deck-specific notetype.
- ModelChooser has been duplicated into notetypechooser.py, and it
has been updated to solely be concerned with keeping track of a selected
notetype - it no longer alters global state.
2021-03-10 11:53:27 +10:00
Damien Elmes
c4f6ec99f7 Remove collection repr
I find the extra info it adds to tracebacks in pytest just makes them
harder to read.
2021-03-10 11:53:27 +10:00
Damien Elmes
0207f6c0ab update Rust deps 2021-03-10 11:53:27 +10:00
Damien Elmes
3d0ddc8539 make flag changes in the reviewer undoable
This splits update_card() into separate undoable/non-undoable ops
like the change to notes in b4396b94abdeba3347d30025c5c0240d991006c9

It means that actions get a blanket 'Update Card' description - in the
future we'll probably want to either add specific actions to the backend,
or allow an enum or string to be passed in to describe the op.

Other changes:
- card.flush() can no longer be used to add new cards. Card creation
is only supposed to be done in response to changes in a note's fields,
and this functionality was only exposed because the card generation
hadn't been migrated to the backend at that point. As far as I'm aware,
only Arthur's "copy notes" add-on used this functionality, and that should
be an easy fix - when the new note is added, the associated cards will
be generated, and they can then be retrieved with note.cards()
- tidy ups/PEP8
2021-03-10 11:53:27 +10:00
Damien Elmes
f1a1b0891e make mark toggling undoable
- note.flush() behaves like before, as otherwise actions or add-ons
that perform bulk flushing would end up creating an undo entry for
each note
- added col.update_note() to opt in to the new behaviour
- tidy up the names of some related routines
2021-03-10 11:53:27 +10:00
Damien Elmes
bec77fd420 undo support for bulk tag add/remove 2021-03-10 11:47:53 +10:00
Damien Elmes
49a1970399 note deletion undo; refactoring
- transact() now automatically clears card queues unless an op
opts-out (and currently only AnswerCard does). This means there's no
risk of forgetting to clear the queues in an operation, or when undoing/
redoing
- CollectionOp->UndoableOp
- clear queues when redoing "answer card", instead of clearing redo
when clearing queues
2021-03-10 11:47:53 +10:00
Damien Elmes
9445e2ee22 drop some unused properties 2021-03-10 11:47:53 +10:00
Damien Elmes
605ad1c9ee remove unnecessary setMod() calls 2021-03-10 11:47:53 +10:00
Damien Elmes
57d7e3e2ab commit immediately when there's no active checkpoint
Reviews and operations on the backend that support undoing can now be
committed immediately, so they will not be lost in the event of a crash.

This required tweaks to a few places:

- don't set collection mtime on save() unless changes were made in
Python, as otherwise we end up accidentally clearing the backend undo
queue
- autosave() is now run on every reset()
- garbage collection now runs in a timer, instead of relying on
autosave() to be run periodically
2021-03-10 11:47:53 +10:00
Damien Elmes
40aff4447a undo support for note adding 2021-03-10 11:47:53 +10:00
Damien Elmes
b466f0ce90 rework undo
- use dataclasses for the review/checkpoint undo cases, instead of the
nasty ad-hoc list structure
- expose backend review undo to Python, and hook it into GUI
- redo is not currently exposed on the GUI, and the backend can only
cope with reviews done by the new scheduler at the moment
- the initial undo prototype code was bumping mtime/usn on undo, but
that was not ideal, as it was breaking the queue handling which expected
the mtime to match. The original rationale for bumping mtime/usn was
to avoid problems with syncing, but various operations like removing
a revlog can't be synced anyway - so we just need to ensure we clear the
undo queue prior to syncing
2021-03-10 11:47:53 +10:00
Damien Elmes
c9eeb91e0a initial work on undoing reviews+burying siblings
- fetch sfld and csum when fetching notes, to make it cheaper
to write them back out unmodified
- make `fields` private, and access it via accessors, so we can
still catch when fields have been mutated without calling
prepare_for_update()
- fix python importing code passing a string in as the checksum
2021-03-10 11:47:53 +10:00
Damien Elmes
b81e2c0265 Ensure we purge caches when rolling back
Fixes #1056
2021-03-08 10:39:18 +10:00
Damien Elmes
5f9792392a don't cap child counts to parents when reviewing in v2
https://forums.ankiweb.net/t/anki-2-1-41-beta/7305/59

When originally implemented in 21023ed3e5,
a given deck's limit was bound by its parents. This lead to a deck list
that seemed more logical in the parent limit < child limit case, as
child counts couldn't exceed a parent's, but it obscured the fact that
child decks could still be clicked on to show cards. And in the parent
limit > child limit case, the count shown for the child on the deck list
did not reflect how many cards were actually available and would be
delivered.

This change updates the reviewer to ignore parent limits when getting
review counts for the deck, which makes the behaviour consistent with
the deck list, which was recently changed to ignore parent limits.

Neither solution is ideal - this was a tradeoff v2 made in order to keep
fetching of review cards from multiple decks reasonably performant. The
experimental scheduling work moves back to respecting limits on
individual children, so this should hopefully improve in the future.

Also removed _revForDeck(), which was unused.
2021-03-02 10:23:06 +10:00
Damien Elmes
de7baa80bd switch to 4 buttons when previewing in test scheduler
- Currently we just use 1.5x and 2x the normal preview delay; we could
change this in the future.
- Don't try to capture the current state; just use a flag to denote
exit status.
- Show (end) when exiting
2021-03-01 23:47:00 +10:00
Damien Elmes
4387e3ed86 fix reps updating in v2, but do it in answerCard instead of getCard 2021-03-01 21:48:02 +10:00
Damien Elmes
8f0c8b6f8a use different approach to running tests twice
The symlink approach was breaking on Windows
2021-03-01 12:47:39 +10:00
Damien Elmes
2c6b6734b5 experimental queue building
Still a work in progress, and hidden behind a feature flag.
2021-03-01 12:18:21 +10:00
RumovZ
88c69665f3 Add support for multi deck deletion in python 2021-02-26 19:52:34 +01:00
RumovZ
92cbf168f6 Catch DeckIsFilteredError directly on frontend 2021-02-26 11:32:40 +01:00
RumovZ
ef925a88d6 Add filtered deck error localisation on backend 2021-02-26 11:32:26 +01:00
Damien Elmes
f165576992 implement leech handling
Also change the default for new users to "tag only"
2021-02-23 17:35:20 +10:00
Damien Elmes
69448365c4 move test code behind env var 2021-02-22 21:32:18 +10:00
Damien Elmes
97300a16bf implement fuzzing
Notes:

- The fuzz seed is now derived from the card id and # of reps, so
if a card is undone and done again, the same fuzz will be used.
- The intervals shown on the answer buttons now include the fuzz, instead
of hiding it from the user. This will prevent questions about due dates
being different to what was shown on the buttons, but will create
questions about due dates being different for cards with the same
interval, and some people may find it distracting for learning cards.
The new approach is easier to reason about, but time will tell
whether it's a net gain or not.
- The env var we were using to shift the clock away from rollover for
unit tests has been repurposed to also disable fuzzing, which simplifies
the tests.
- Cards in filtered decks without scheduling now have the preview delay
fuzzed.
- Sub-day learning cards are mostly fuzzed like before, but will apply
the up-to-5-minutes of fuzz regardless of the time of day.
- The answer buttons now round minute values, as the fuzz on short
intervals is distracting.
2021-02-22 21:31:53 +10:00
Damien Elmes
08c5fe474a make checkRevIvl() assert so pytest can print values; fix missed check 2021-02-22 21:31:53 +10:00
Damien Elmes
f82cf0cd4b drop some unused code 2021-02-22 21:31:53 +10:00
Damien Elmes
3af5221895 plug new answering code in
This is not the way the code is intended to be used, but making it
conform to the existing API allows us to exercise the existing unit
tests and provides partial backwards compatibility.

- Leech handling is currently broken
- Fix answered_at in wrong units, and not being used
2021-02-22 21:31:53 +10:00
Damien Elmes
f811beae5e remove burySiblings()'s dependency on newConf()/revConf() 2021-02-22 21:31:53 +10:00
Damien Elmes
7dc05253c1 fix a few more instances where v2 tests were referencing 'left today' 2021-02-22 21:31:53 +10:00
Damien Elmes
72389595fa tidy up top of file 2021-02-22 21:31:53 +10:00
Damien Elmes
63df7ee7a9 move re-queuing out of _answerCard() 2021-02-22 21:31:53 +10:00
Damien Elmes
a112a4403a duplicate schedv2.py in scheduler.py 2021-02-22 11:40:19 +10:00
Damien Elmes
c659898ee1 separate queue building and card answering 2021-02-22 11:33:28 +10:00
Damien Elmes
b8ad694006 move more routines down 2021-02-22 11:14:41 +10:00
Damien Elmes
4c5d4befbf move routines not related to building/answering to bottom of file 2021-02-22 11:07:56 +10:00
Damien Elmes
e7bcc22d6f move legacy aliases to bottom of schedv2.py 2021-02-22 10:57:08 +10:00
Damien Elmes
f50cd43e75 fix incorrect nested review counts in v2 scheduler
https://forums.ankiweb.net/t/problem-with-anki-subdecks/7689
2021-02-21 22:48:14 +10:00
Damien Elmes
53d9433d94 Revert "use v2 scheduler+new timezone handling by default for new users"
This reverts commit 8372931b9b.

I fear this will be too disruptive - let's give AnkiDroid a bit more
time to catch up. Reverting this will mean new users are presented with
an upgrade notice on first startup, which looks a bit silly, but it's
probably the lesser of two evils.
2021-02-21 19:03:46 +10:00
Damien Elmes
8372931b9b use v2 scheduler+new timezone handling by default for new users
- In corner cases, enabling the new timezone handling later can cause
reviews to shift forward or back a day, so it's best to have it on
by default.
- https://github.com/ankidroid/Anki-Android/issues/5805 has not landed
in a stable release yet, but will hopefully not be too far off by the
time 2.1.41 is released.
- Existing users will be unaffected, as the upgrade prompt in the previous
commit asks them if they use AnkiDroid.
- Users starting on AnkiDroid will be unaffected, as their collections
will still be on V1.
- The error message AnkiWeb gives when syncing an older AnkiDroid
with the new timezone enabled has been updated to direct users to the
preferences screen.
2021-02-21 17:18:08 +10:00
Damien Elmes
5ae66af5d2 rework v2 scheduler upgrade; drop downgrade
- Rework V2 upgrade so that it no longer resets cards in learning,
or empties filtered decks.
- V1 users will receive a message at the top of the deck list
encouraging them to upgrade, and they can upgrade directly from that
screen.
- The setting in the preferences screen has been removed, so users
will need to use an older Anki version if they wish to switch back to
V1.
- Prevent V2 exports with scheduling from being importable into a V1
collection - the code was previously allowing this when it shouldn't
have been.
- New collections still default to v1 at the moment.

Also add helper to get map of decks and deck configs, as there were
a few places in the codebase where that was required.
2021-02-21 15:50:41 +10:00
Damien Elmes
54fa322f3d add some flush() calls and fix a card type in test_schedv2
Will help test when code is moved to backend
2021-02-20 14:00:26 +10:00
Damien Elmes
713bf254c8 stop checking "steps left today" in test_schedv2 2021-02-20 13:59:07 +10:00
Damien Elmes
2a7945f4be fix __repr__ in collection 2021-02-20 13:57:53 +10:00
Damien Elmes
b13d28cc5b tidy up doc string 2021-02-19 10:04:57 +10:00
abdo
010ebef12e Add docstrings to find_cards() and find_notes() 2021-02-17 17:30:38 +03:00
Henrik Giesel
87febe489e Allow for passing in custom note type and template 2021-02-12 02:12:03 +01:00
Henrik Giesel
270cef63f4 Allow for passing in custom note types for rendering ephemeral cards 2021-02-12 01:53:03 +01:00
Damien Elmes
35840221bb tweak search wording and tidy up API
- SearchTerm -> SearchNode
- Operator -> Joiner; share between messages
- build_search_string() supports specifying AND/OR as a convenience
- group_searches() makes it easier to negate
2021-02-11 19:57:19 +10:00
Damien Elmes
59ccfe5918 more search bikeshedding
While implementing the overdue search, I realised it would be nice to
be able to construct a search string with OR and NOT searches without
having to construct each part individually with build_search_string().

Changes:

- Extends SearchTerm to support a text search, which will be parsed
by the backend. This allows us to do things like wrap text in a group
or NOT node.
- Because SearchTerm->Node conversion can now fail with a parsing error,
it's switched over to TryFrom
- Switch concatenate_searches and replace_search_term to use SearchTerms,
so that they too don't require separate string building steps.
- Remove the unused normalize_search()
- Remove negate_search, as this is now an operation on a Node, and
users can wrap their search in SearchTerm(negated=...)
- Remove the match_any and negate args from build_search_string

Having done all this work, I've just realised that perhaps the original
JSON idea was more feasible than I first thought - if we wrote it out
to a string and re-parsed it, we would be able to leverage the existing
checks that occur at parsing stage.
2021-02-11 17:11:17 +10:00
Damien Elmes
5ab115c145 convert some pylib strings to f-strings with flynt
excluded some changes where readability got noticeably worse
2021-02-11 09:51:09 +10:00
Damien Elmes
bb29ce88f3 minor code cleanups with pyupgrade
- pyupgrade --py38-plus --keep-runtime-typing --keep-percent-format
- third-party mpv and winpaths excluded
2021-02-11 09:43:40 +10:00
Damien Elmes
9ce4b21935 add markdown flag for deck description
Needed so we can display consistently, and gradually transition over
2021-02-09 18:47:19 +10:00
Damien Elmes
a8ddb65e1c add ability to force interval reset
- use trailing ! to force a reset
- use - instead of ..
- tweak i18n messages and error handling
2021-02-08 22:33:27 +10:00
Damien Elmes
b9635ce936 nest NoteWithEmptyCards 2021-02-08 19:11:16 +10:00
Damien Elmes
c23b01978d nest progress messages and remove Python wrapper class
The progress messages are only really intended to be consumed by Anki.
If consumption by add-ons was expected, we'd be better off keeping the
wrapper, as the API for oneofs in Python is quite awkward to use.
2021-02-08 16:40:27 +10:00
Damien Elmes
f434cff36f remember last input for 'set due'; add string config; nest config types 2021-02-08 14:10:05 +10:00
Damien Elmes
b56580a8c0 fix rsbackend compat issues 2021-02-08 09:51:51 +10:00
Damien Elmes
704b5e581a 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 21:57:51 +10:00
Damien Elmes
dfe3c457e5 use top level defs for protobuf enum cases
While mypy can understand nested references like ConfigBool.Key.COLLAPSE_RECENT,
PyCharm doesn't understand the metaclass syntax, and shows the definitions
as invalid.
2021-02-05 19:26:13 +10:00
Damien Elmes
b8d67cdad5 move remaining Filter button items into sidebar
- Closes #976
- Added helper to apply arbitrary colour to an icon.
- Fix #979 - low res icons in night mode.
- The icons and colours are not perfect - please feel free to send
through a PR if you can improve them.
- Convert colors dictionary into module consts, so we can
use code completion.
- Added "Edited Today" and "Due Tomorrow"
- Rename camelCase attribute to snake_case and tweak the wording
of some enum constants. We've already broken compatibility with the
major sidebar add-ons, so we may as well make these changes while we
can.
- Removed Filter button. Currently there is no exposed way to toggle
the Sidebar off - wonder if we still need it?
2021-02-05 18:58:22 +10:00
Damien Elmes
790562cd08 update Rust deps 2021-02-03 20:29:48 +10:00
Damien Elmes
168963460f update to latest mypy_protobuf
The handling of enum types has improved - we no longer need to import
separate types at typechecking time.
2021-02-03 13:31:52 +10:00
Henrik Giesel
22a5db8ace Remove unused imports 2021-02-02 17:13:35 +01:00
Henrik Giesel
2483ef4517 Use new note.ephemeral_card method in clayout 2021-02-02 16:47:25 +01:00
Henrik Giesel
4d119cada2 Add ephemeral card method 2021-02-02 16:38:21 +01:00
Damien Elmes
a50601ed46 add tag drag & drop support 2021-02-02 20:14:04 +10:00
Damien Elmes
dd54c10e71
Merge pull request #968 from abdnh/sidebar-expand-matches
Expand sidebar match trees one level
2021-02-02 19:03:04 +10:00
Damien Elmes
467064f873 collapsed->expanded in other tag uses for consistency 2021-02-02 18:52:57 +10:00
Damien Elmes
8e0f69b71c return tags as a string list directly; we don't need usn or collapse state 2021-02-02 18:52:57 +10:00
Damien Elmes
7fc32db0c9 fix: slowdowns after import; hard to read popup
QTextEdit() will pin the CPU at 100% for seconds to minutes when
fed a large string to display - work around it by switching to
QPlainTextEdit().

Also strip HTML before showing the user - easier to read, and less
text to display. And turn off word wrap, as it makes it easier to skim,
and further reduces the work the widget needs to do.

https://forums.ankiweb.net/t/big-issue-where-anki-gets-slow-when-you-import-this-deck/7050
2021-02-02 15:49:47 +10:00
Damien Elmes
e7483edee7 update mypy and other Python deps
latest mypy_protobuf can no longer be run directly, so we need
to run a wrapper instead
2021-02-01 15:50:04 +10:00
Damien Elmes
25a1a2c89c always quote types in generated hooks 2021-02-01 08:36:33 +10:00
Damien Elmes
1741ce1ed8 add more typing, and enable checks for missing types for most of pylib 2021-01-31 21:38:36 +10:00
Damien Elmes
bb92dde2d7 warn add-ons importing json from anki.utils; use stdout not stderr 2021-01-31 21:05:46 +10:00
Damien Elmes
7fda601aef add some typehints, and remove some unused code 2021-01-31 20:56:21 +10:00
Damien Elmes
5d810dd799 make backend instance on col private 2021-01-31 18:56:16 +10:00
Damien Elmes
6c483bb577 add public wrappers for remaining backend functions 2021-01-31 18:56:16 +10:00
Damien Elmes
c7f92f0737 fix _backend files not getting format checked 2021-01-31 18:56:16 +10:00
Damien Elmes
ea31e8ca3e move the remaining exports from _backend 2021-01-31 18:56:16 +10:00
Damien Elmes
260a270eb0 embed BuiltinSortKind 2021-01-31 18:56:16 +10:00
Damien Elmes
5974163343 embed kind enum in StockNoteType and remove prefix 2021-01-31 18:56:16 +10:00
Damien Elmes
248e067da7 add back basic rsbackend.py for compatibility 2021-01-31 18:55:45 +10:00
Damien Elmes
9815d96461 remove template_legacy.py 2021-01-31 18:55:45 +10:00
Damien Elmes
67cb147493 move rsbridge into _backend 2021-01-31 18:55:45 +10:00
Damien Elmes
9d853bbb03 start work on more clearly defining backend/protobuf boundaries
- anki._backend stores the protobuf files and rsbackend.py code
- pylib modules import protobuf messages directly from the
_pb2 files, and explicitly export any will be returned or consumed
by public pylib functions, so that calling code can import from pylib
- the "rsbackend" no longer imports and re-exports protobuf messages
- pylib can just consume them directly.
- move errors to errors.py

Still todo:

- rsbridge
- finishing the work on rsbackend, and check what we need to add
back to the original file location to avoid breaking add-ons
2021-01-31 18:55:45 +10:00
RumovZ
cd9767be80 Remove unused BackendNoteTypeID 2021-01-31 08:57:10 +01:00
Damien Elmes
cb805cf355 Merge branch 'more-backend-search' into main 2021-01-31 14:21:51 +10:00
Damien Elmes
8410330f94 move drag/drop deck logic to backend 2021-01-31 13:46:31 +10:00
RumovZ
4745b55d27 Revert addition of pb.NoteIDs 2021-01-30 12:59:18 +01:00
RumovZ
80a4a85510 Remove redundant docstring 2021-01-30 10:37:46 +01:00
Damien Elmes
cb6b88da0f simplify nid/nids searches, and ditch helper function
- IdList could be re-used for a cids: search in the future if required.
- Embedding the message means it's easy to access from Python as
an attribute of SearchTerm.
2021-01-30 11:37:00 +10:00
Damien Elmes
1adc9952f4 simplify Dupe message and ditch helper function
Calling code doesn't need to know about the existence of such helpers;
it can just rely on code completion to discover the required arguments.
2021-01-30 11:10:26 +10:00
Damien Elmes
5e6dd54c8e export SearchTerm from collection.py, and avoid exporting embedded items 2021-01-30 11:01:11 +10:00
Damien Elmes
73b897c754 rename FilterToSearchIn in backend to match frontend 2021-01-30 10:54:21 +10:00
RumovZ
c299e271e8 Refactor search_string() and FilterToSearchIn
See #955.
2021-01-29 18:27:33 +01:00
Damien Elmes
5ff7944a26 add getter/setter for boolean config values 2021-01-29 21:03:19 +10:00
RumovZ
349bd9d681 Use proper docstrings 2021-01-29 09:40:21 +01:00
RumovZ
1fb6024454 Rename filters added_in etc. to added_in_days 2021-01-29 09:38:13 +01:00
Damien Elmes
7693879e3c remove unused set_all_config; expose .all_config(). 2021-01-29 16:30:42 +10:00
RumovZ
423d7e5098 Use backend filter for findDupes and handle excep. 2021-01-28 19:49:16 +01:00
RumovZ
d33442f901 Add backend filter for field name 2021-01-28 19:48:01 +01:00
RumovZ
407358ab68 Use backend nid filter in browser 2021-01-28 16:21:56 +01:00
RumovZ
51e1e82a9a Add helper functions for search strings in col 2021-01-28 11:13:57 +01:00
Maksim Abramchuk
0eb653559a Remove unused variable 2021-01-26 21:37:16 +00:00
Damien Elmes
31a3add848 fix finished screen not showing when learning cards due later 2021-01-25 21:12:57 +10:00
Damien Elmes
2a875ffc55
Merge pull request #934 from hgiesel/graphprefs
Add GraphsPreferences API to graphs for setting persistent preferences
2021-01-23 21:24:41 +10:00
Damien Elmes
37ca8afaf6 minor wording tweak: GraphsPreferences -> GraphPreferences 2021-01-23 20:47:45 +10:00
Damien Elmes
10757d563d refresh new/rev counts when fillNew/fillRev() fails
This was the behaviour before, but got lost when ._reset_counts() was
added. Also added the check back to schedv2:fillRev(), which also
appears to have gotten lost in the move to ._reset_counts()

Just a stop-gap fix until this code can get a proper rewrite.
2021-01-23 14:02:05 +10:00
Damien Elmes
ce2315591f remove "invalid current deck"
This should resolve itself when a user clicks on a deck.
2021-01-23 13:04:58 +10:00
Henrik Giesel
bf130d1da0 Change the function name in genbackend.py 2021-01-22 20:05:28 +01:00
Henrik Giesel
665a13e378 Add GraphsPreferences endpoint to backend 2021-01-22 13:13:48 +01:00
abdo
bf0086d565 Use new backend filters in rename_tag() 2021-01-16 18:49:48 +03:00
abdo
e018ea94b6 Merge branch 'master' of https://github.com/ankitects/anki into tagtree 2021-01-15 01:12:01 +03:00
abdo
2ff584c44d Pass escaped name to bulk_update in rename_tag 2021-01-14 18:38:46 +03:00
abdo
9c1d7c522a Refactor code for clearing unused tags and saving collapse state 2021-01-14 07:04:14 +03:00
RumovZ
7b9cc017c4 Use backend to set dupe filter 2021-01-14 10:42:37 +10:00
Damien Elmes
633034b24d add local sync server frontend 2021-01-13 11:42:00 +10:00
abdo
72e8f9d640 Merge branch 'master' of https://github.com/ankitects/anki into tagtree 2021-01-12 23:31:58 +03:00
Damien Elmes
fbd91b22f5 tidy up UTC offset handling/timing calculations
- use the TimestampSecs newtype instead of raw i64s
- use FixedOffset instead of a minutes_west offset
- check localOffset each time the timing is calculated, and set it
if it's stale - even for v1.
- check for and fix missing rollover when calculating timing
- stop explicitly passing localOffset in the sync/start call
2021-01-12 21:32:56 +10:00
Damien Elmes
9bc8434538 remove temporary sync/dbcheck logging 2021-01-12 18:47:08 +10:00
Damien Elmes
1425379d41 drop basicCheck()
It can considerably slow down syncing on large collections
2021-01-12 18:47:08 +10:00
Damien Elmes
401d5dd9cc
Merge pull request #917 from hgiesel/querynozero3
Coerce added/edited:0 to 1, Constrain rated:n to 1-365
2021-01-11 16:24:12 +10:00
Henrik Giesel
250b89be60 Adjust pyblib test_find 2021-01-10 16:25:52 +01:00
RumovZ
942632d579 Also add FilterToSearch to want_release_gil() 2021-01-10 11:31:00 +01:00
RumovZ
b763fc5b2a Use explicit wrapper functions to get filters 2021-01-09 16:48:47 +01:00
abdo
f7f509c70d Move tag collapse method to the backend 2021-01-09 17:10:16 +03:00
abdo
b33267f754 Do not check for missing tag parents at registration time 2021-01-09 17:10:16 +03:00
abdo
b276ce3dd5 Hierarchical tags 2021-01-09 17:10:13 +03:00
RumovZ
b99d9cda74 Prettify frontend filter code 2021-01-09 12:34:46 +01:00
RumovZ
fda2bfdb4e Use backend filters instead of literal searches 2021-01-09 10:51:15 +01:00