Commit graph

134 commits

Author SHA1 Message Date
Damien Elmes
c90ab022c9 add hook to modify browser row content 2021-03-23 19:13:52 +10:00
Damien Elmes
eb761da622 tweak hook names 2021-03-19 19:45:21 +10:00
Damien Elmes
b8bdc5824b 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
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
Damien Elmes
1dec65599d experiment with replacing requireReset with updates on focus-in
- This avoids the need for a separate screen, though we may want to
slightly fade out the display when information is stale.
- Means the browser can delay updates just like the main window does.
2021-03-19 19:45:21 +10:00
Damien Elmes
b9bb9920b5 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
fbcfa48419 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
b6e873b17b 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
9702532fc4 more typing updates 2021-02-02 23:31:55 +10:00
Arthur Milchior
5c7dbdf72b NF: Add a hook to change the default search from reviewer
The goal here is to simplify my add-on which show a single card or the whole deck when the browser open
2021-01-02 19:49:11 +01:00
Damien Elmes
9038015f4f formatting fix 2020-12-18 10:27:32 +10:00
Damien Elmes
b13f6d4931 document ANKI_PROFILE_CODE and add bazel command to run snakeviz 2020-12-17 12:03:24 +10:00
Damien Elmes
7e655614b2 fix remaining _() references; remove unused imports 2020-11-18 12:43:46 +10:00
ianki
28ad68d490 Add hooks for filtering media. 2020-11-09 02:12:23 -08:00
Damien Elmes
ce3b08ac58 initial Bazel conversion
Running and testing should be working on the three platforms, but
there's still a fair bit that needs to be done:

- Wheel building + testing in a venv still needs to be implemented.
- Python requirements still need to be compiled with piptool and pinned;
need to compile on all platforms then merge
- Cargo deps in cargo/ and rslib/ need to be cleaned up, and ideally
unified into one place
- Currently using rustls to work around openssl compilation issues
on Linux, but this will break corporate proxies with custom SSL
authorities; need to conditionally use openssl or use
https://github.com/seanmonstar/reqwest/pull/1058
- Makefiles and docs still need cleaning up
- It may make sense to reparent ts/* to the top level, as we don't
nest the other modules under a specific language.
- rspy and pylib must always be updated in lock-step, so merging
rspy into pylib as a private module would simplify things.
- Merging desktop-ftl and mobile-ftl into the core ftl would make
managing and updating translations easier.
- Obsolete scripts need removing.
- And probably more.
2020-11-01 14:26:58 +10:00
Damien Elmes
874366fce7 formatting fix 2020-10-12 12:37:51 +10:00
Henrik Giesel
0f09258e68 Add fields_did_rename_field and fields_did_remove_field hooks 2020-10-11 19:16:30 +02:00
Henrik Giesel
716f8a103c Add editor_did_init_left_buttons gui_hook 2020-10-04 22:50:02 +02:00
Henrik Giesel
306424455c Add some documentation to sync_did_finish hook 2020-09-14 13:18:16 +02:00
Henrik Giesel
a685272e16 Add sync_will_start and sync_did_finish hook 2020-09-14 12:22:01 +02:00
Damien Elmes
130f99fe44 fix some lints 2020-09-01 10:24:38 +10:00
Damien Elmes
fcf63205b6 add a hook to support extending external .html files 2020-09-01 10:24:38 +10:00
Damien Elmes
2411e944e4 drop the old sass vars and define the properties directly 2020-09-01 10:24:38 +10:00
Damien Elmes
a6aaaf8691 move _vars to outer ts folder
First step in sharing styling with graphs + future .html files
2020-09-01 10:24:38 +10:00
Henrik Giesel
87bcc39a77 Some minor reformatting to satisfy black 2020-08-31 13:50:59 +02:00
Henrik Giesel
31b2d46247 Fix type signature: models is passed because it's a method 2020-08-31 13:35:18 +02:00
Henrik Giesel
2a4f0edfe7 Don't import models in gui_hooks to avoid circular import 2020-08-31 13:35:18 +02:00
Henrik Giesel
6ee503742f Add compiled hook model_did_init_buttons 2020-08-31 13:35:18 +02:00
Henrik Giesel
6d2f2282d2 Add gui_hook models_did_init_buttons 2020-08-31 13:35:01 +02:00
Damien Elmes
8729edffbb update to latest black 2020-08-31 13:29:28 +10:00
Damien Elmes
5adc3eff6f Merge pull request #735 from brownbat/master
Add hook for initializing answer buttons
2020-08-21 12:34:14 +10:00
Thomas B
e7e67e0c87 Fix other docstring to match. 2020-08-20 10:33:46 -04:00
Thomas B
a54135c5ac Fixing type hints
Matched all type hints, changed the original Sequence[] type hint for _answerButtonList() in reviewer.py on mypy's recommendation.
2020-08-19 16:15:49 -04:00
Thomas B
8b95ab5441 Bugfix proposed filter post-testing
Mirrored filter more closely on _ReviewerWillAnswerCardFilter, including taking and returning the value to be modified.
2020-08-18 10:37:45 -04:00
Henrik Giesel
1f4e604e2b Rename to should_require_reset 2020-08-16 18:56:32 +02:00
Henrik Giesel
4f37e6196b Update signature of main_window_will_require_reset hook 2020-08-16 18:56:32 +02:00
Henrik Giesel
28528fc3ec Add main_window_will_require_reset hook 2020-08-16 18:56:32 +02:00
Thomas B
830ab9cedb Add hook for initializing answer buttons 2020-08-14 13:52:20 -04:00
Arthur Milchior
110f4c664f Any removed 2020-08-12 01:37:21 +02:00
Henrik Giesel
7d1d20cbf4 Add editor_will_munge_html hook 2020-08-08 23:27:58 +02:00
ANH
9a768fc198 fix typo 2020-07-31 04:41:49 +03:00
ANH
0eb48d3603 document hooks 2020-07-31 03:06:13 +03:00
ANH
23d0008a6f add reviewer_will_play_question_sounds and reviewer_will_play_answer_sounds hooks 2020-07-30 22:20:19 +03:00
Glutanimate
7056765179 Fix type annotation for old stats dialog class 2020-07-17 03:08:09 +02:00
Glutanimate
b7c8374095 Add a couple of hooks to trigger add-on actions before showing stats 2020-07-16 21:48:46 +02:00
Glutanimate
ee8696cbf3 Add top_toolbar_did_redraw hook
Notifies add-ons of the top toolbar being redrawn
2020-07-10 17:38:40 +02:00
Arthur Milchior
f9b0f6e7b3 hook: history_line
I expect to use this hook to create an add-on which will simply remove
the ",,". By ignoring empty fields I expect to make this easier to
use.
2020-06-08 20:47:01 +02:00
evandrocoan
0ca8cd4e4d Add missing quotes to typecheck-setup.sh for paths with spaces on
the name.
2020-06-02 21:37:58 -03:00
Damien Elmes
86689c5e77 more fixes for bundled Qt types 2020-06-03 09:55:30 +10:00
Damien Elmes
7716e3b17e Switch to PyQt 5.15's (slightly broken) built-in stubs 2020-06-02 17:52:18 +10:00