Commit graph

100 commits

Author SHA1 Message Date
Damien Elmes
d80ed5ff3b support undo of filtered deck build/empty 2021-03-24 12:56:06 +10:00
Damien Elmes
15c76c1a09 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
fafe30f4b4 use perform_op() for deck creation 2021-03-22 23:17:07 +10:00
Damien Elmes
12e1ca0c2f deck rename with perform_op() 2021-03-22 20:38:51 +10:00
Damien Elmes
42d007d94d use perform_op() for deck drag&drop 2021-03-22 18:23:56 +10:00
Damien Elmes
42e20461c0 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
RumovZ
b093d62f5a Merge branch 'master' into sidebar-tools 2021-03-11 12:08:32 +01:00
RumovZ
7d4f830322 Annotate decks.rem as deprecated 2021-03-11 11:26:35 +01:00
Damien Elmes
f09c1d027c add a separate 'rename deck' method 2021-03-11 19:24:54 +10:00
RumovZ
193e7cc2aa Remove deck remove prompt but show card count 2021-03-11 09:52:11 +01:00
RumovZ
c018c31985 Merge branch 'master' into sidebar-tools 2021-03-10 10:34:36 +01:00
Damien Elmes
ade12fe2fb 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
RumovZ
47d96a32e6 Add support for multi deck deletion in python 2021-02-26 19:52:34 +01:00
RumovZ
c4a2a212ec Catch DeckIsFilteredError directly on frontend 2021-02-26 11:32:40 +01:00
Damien Elmes
92bdc90b44 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
bf7528d90a 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
5114fde01c add more typing, and enable checks for missing types for most of pylib 2021-01-31 21:38:36 +10:00
Damien Elmes
01fb95719f make backend instance on col private 2021-01-31 18:56:16 +10:00
Damien Elmes
a6be0f493b 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
Damien Elmes
5710e4bbd0 move drag/drop deck logic to backend 2021-01-31 13:46:31 +10:00
RumovZ
b4fa13aa0e Fix deck check and thus blue snyc arrow bug
Cast col.decks.selected() to int so the return type fits the annotation.
Thus, fix the comparison in col.decks.select() which was leading to
a superfluous db modification and in turn to a false indication of a
necessary sync right after another one in certain cases.
2020-12-29 00:29:36 +01:00
Damien Elmes
407b7f7410 tweak naming and move method into col.decks 2020-12-20 10:26:16 +10:00
Damien Elmes
1781e83252 merge pylib references 2020-11-17 19:23:06 +10:00
Damien Elmes
bc60d233e5 rebuild_filtered_deck() and new_filtered() 2020-09-03 18:02:47 +10:00
Damien Elmes
8729edffbb update to latest black 2020-08-31 13:29:28 +10:00
Damien Elmes
204db71586 fix new pylint raise-missing-from lint 2020-08-31 12:04:14 +10:00
Arthur Milchior
110f4c664f Any removed 2020-08-12 01:37:21 +02:00
Arthur Milchior
a74601a0f0 NF: childMapNode 2020-08-12 00:42:42 +02:00
Damien Elmes
3a75161778 fix deck tree with a day delta, and support arbitrary timestamps 2020-07-06 19:16:03 +10:00
Damien Elmes
55f8b87548 support generating a due tree for a different date 2020-06-05 09:38:31 +10:00
Damien Elmes
854c524ecf fix mtime being bumped in .reset() 2020-06-01 13:57:10 +10:00
evandrocoan
3d2dcc8cec Added super().__repr__() to new __repr__() calls 2020-05-31 19:39:19 -03:00
evandrocoan
45cb996cc9 Added __repr__ functions to common objects 2020-05-31 19:39:19 -03:00
Damien Elmes
e9fea26d1c use keyword args for calls with more than one argument 2020-05-24 09:12:47 +10:00
Damien Elmes
35489d5fa7 add some more newtypes to the RPC defs 2020-05-23 16:58:01 +10:00
Damien Elmes
32a071cf79 migrate decks and dconf methods 2020-05-23 15:09:16 +10:00
Damien Elmes
927ed25b02 more methods 2020-05-23 14:01:36 +10:00
Damien Elmes
d57ded706f migrate more methods to service 2020-05-22 22:09:33 +10:00
Damien Elmes
7676748e6c fix deletion of decks; allow deleting cards from default
https://anki.tenderapp.com/discussions/beta-testing/1967-2126-189-g7384df8f-crash-at-note-types-fields-save#comment_48353232
2020-05-22 11:24:56 +10:00
Damien Elmes
d31f2d8c23 move deck/notetype update hooks to gui
We need to migrate away from firing hooks in libanki, since libanki
methods may be running on a background thread, and hook consumers
typically expect the code to run in the main thread. We could document
it, but it would frequently be forgotten about, and could lead to
crashes.

https://anki.tenderapp.com/discussions/ankidesktop/41748-qobject-cannot-create-children-for-a-parent-that-is-in-a-different-thread-when-hitting-the-save-button-on-clayoutpy-window
2020-05-22 10:47:14 +10:00
Damien Elmes
068cc43095 storage->collection 2020-05-20 17:58:28 +10:00
Damien Elmes
94722c4fbb minor tidyups in decks.py 2020-05-17 20:13:29 +10:00
Damien Elmes
b676522e5c fix renaming corner cases and decks.update()
- .update() should update a single deck and preserve usn by default,
as that's what existing code expects
- decks are automatically renamed when they conflict with an existing
name
2020-05-17 19:07:15 +10:00
Damien Elmes
2c19e171ed handle deletion of default deck in backend; use + instead of _ 2020-05-17 15:22:19 +10:00
Damien Elmes
6728da62c5 fix shared deck conf warning 2020-05-17 14:37:59 +10:00
Damien Elmes
336349d8d1 update before_upload() 2020-05-17 14:13:21 +10:00
Damien Elmes
8a42896fb8 speed up children() and add deck_and_child_ids() 2020-05-16 15:40:07 +10:00
Damien Elmes
c138917773 formatting 2020-05-16 14:59:47 +10:00
Damien Elmes
b3205e5d5d only update active when selecting deck/resetting
We were previously doing this every time a card was answered.
2020-05-16 14:57:46 +10:00
Damien Elmes
f76b82d8ae add find_deck_in_tree() 2020-05-16 13:05:20 +10:00