Commit Graph

1153 Commits

Author SHA1 Message Date
Damien Elmes
f6ef553ba5 move strip_av_refs() into anki.sound 2020-01-24 15:48:40 +10:00
Damien Elmes
f900f24f60 more changes to the template code
- _renderQA() has moved to template.py:render_card()
- dropped QAData in favour of a properly typed dict
- render_card() returns a TemplateRenderOutput struct instead of a dict
- card_did_render now takes that output as the first arg, and can
mutate it
- TemplateRenderContext now stores the original card, so it can return
a card even in the add screen case

The old mungeFields and mungeQA hook have been removed as part of this
change. mungeQA can be replaced with the card_did_render hook.
In the mungeFields case, please switch to using field_filter instead.
2020-01-24 13:44:13 +10:00
Damien Elmes
836213e587 renderQA() wasn't used in the codebase 2020-01-24 11:09:38 +10:00
Damien Elmes
17ebdfc099 extract and flag AV tags as part of the render process
We can now show replay buttons for the audio contained in {{FrontSide}}
without having to play it again when the answer is shown.

The template code now always defers FrontSide rendering, as it wasn't
a big saving, and meant the logic had to be implemented twice.
2020-01-24 11:06:11 +10:00
Damien Elmes
406c58a109 inject legacy funcs referencing aqt in GUI load 2020-01-23 18:20:19 +10:00
Damien Elmes
7bb7d5391b fix lint 2020-01-23 18:12:57 +10:00
Damien Elmes
9548df1c0f update reqs test to reflect new behaviour 2020-01-23 17:32:17 +10:00
Damien Elmes
7dcbc7efec basic night mode support
Forces the Fusion theme when running night mode, so we don't need
to work around platform themes that don't respond to the defined
palette.

Feedback/suggestions on the chosen colours welcome - _vars.scss is the
file to change if you want to experiment with adjustments.
2020-01-23 17:27:07 +10:00
Yngve Høiseth
82fdce32f2 Type hint RemoteServer._run 2020-01-22 23:33:37 +01:00
Damien Elmes
cc02e95049 fix pylib checks failing when aqt unavailable 2020-01-22 16:11:40 +10:00
Damien Elmes
4fb227ca4c added flag_av_tags() for replay button support 2020-01-21 14:44:27 +10:00
Damien Elmes
c713683f63 add rank handling to TTS; parse TTS args in get_av_tags() 2020-01-21 12:41:37 +10:00
Damien Elmes
707ac587ec rework the audio player API and add a simpler player implementation
- the new API operates on AVTags so it can support TTS as well as
audio files
- added a simple "run for each file" implementation for mpv and mplayer.
- will need to test handling of unicode filenames on Windows
- the old mpv and mplayer code is currently not active
2020-01-20 20:07:11 +10:00
Damien Elmes
0942ffbff6 add a simple TTS field filter
This simply wraps the field in extra text that the frontend will
deal with. Also added some helpers for extracting and stripping
audio and TTS tags from the rendered text.
2020-01-20 19:16:24 +10:00
Damien Elmes
17dae51b29 hasSound not used by anki code or add-ons 2020-01-20 09:31:28 +10:00
Damien Elmes
a9c93d933c fix incorrectly logged repeat step
https://anki.tenderapp.com/discussions/ankidesktop/38130-anki-21-scheduler-misleads-on-hard-button-for-learning-cards
2020-01-19 15:41:58 +10:00
Damien Elmes
66714260a3 automatically disable add-ons that have been marked as incompatible 2020-01-19 13:37:55 +10:00
Damien Elmes
ef8bb61fc3 AnkiRequestsClient -> HttpClient 2020-01-19 11:33:27 +10:00
Damien Elmes
67fb3438f3 add type alias for httpclient callback 2020-01-19 10:06:54 +10:00
Damien Elmes
3287e8c057 pass in a progress callback instead of http_data_did_[send|receive]
If a request is happening on a background thread, the GUI code
receiving requests on that thread can lead to a crash

Add-on downloading still to do.
2020-01-18 17:49:59 +10:00
Damien Elmes
0d1a25eb5b move AnkiRequestsClient into its own file
It should still be accessible via anki.sync as well.
2020-01-18 15:45:14 +10:00
Damien Elmes
bead03e858 drop plus_one test 2020-01-17 18:54:38 -07:00
Damien Elmes
12c60f20fe _localOffsetForDate() was broken
It was including the elapsed time of day when calculating
the offset, leading to incorrect results
2020-01-17 18:52:36 -07:00
Damien Elmes
b1c2d271d3 comment out the unused legacy code 2020-01-17 10:51:36 +10:00
Damien Elmes
d3cc63efb0 move types.py into the files responsible for each type 2020-01-17 10:17:33 +10:00
Damien Elmes
06833f7301 remove unused legacy requirements code 2020-01-17 09:33:33 +10:00
Damien Elmes
2a0b480103 add context to card rendering, and rework related hooks
- the context exists for the lifecycle of one card's render,
and caches calls to things like .card() to avoid add-ons needing to
do their own cache management.
- add-ons can optionally add extra data to the context if they need
it across multiple filters
- removed card_will_render. the legacy hook is still available for
now
- card_did_render is now called only once, with both front and back
text
2020-01-17 09:30:42 +10:00
Damien Elmes
d2865235df i18n 2020-01-16 21:05:29 +10:00
Damien Elmes
a63eccb3dd need to strip sounds when FrontSide rendering deferred 2020-01-16 19:49:43 +10:00
Damien Elmes
912a49a2e3 fix empty cloze message not appearing 2020-01-16 18:47:21 +10:00
Damien Elmes
b56c9591c0 more useful template error message 2020-01-16 18:47:21 +10:00
Damien Elmes
81f7e634d1
Merge pull request #423 from Arthur-Milchior/fixReorder
Order by creation of note
2020-01-16 18:47:12 +10:00
Arthur Milchior
d9b5a1da89 Order by creation of note
This commit solve a problem I actually have for some strange
reason. Here is how to reproduce the problem

1. Create a note of type Basic (and reversed card) in a deck D with front "First"
and no back
2. Wait a day (or install an add-on which show hour and minutes of
creation time in browser)
3. create a second note, with front "Last" and no back
4. In first note, add in back field "First" and delete the front field
5. Use "Empty card".
6. In the setting of the deck D, set in random order, and then back in
the "order added"
7. Review deck D. You'll see card 1 of the second note. (Don't review
it)
8. Open the browser. Show the column "due" and created. You'll see
that the first card (first) have due value 2, while it was created
before according to the created date. The card "last" have due value
1.

This is due to the fact that the value "created" is linked to note
creation, while the order is linked to the card creation time, and
card may be created after other note
2020-01-15 23:42:54 -08:00
Damien Elmes
69a7ee430d type hints 2020-01-16 09:19:53 +10:00
Damien Elmes
cc9a36c11a simplify previewCards() and use existing card ids where possible
The type arg is no longer used, as neither type 0 nor 1 appears to
have been used in the codebase.

By using the existing card ids, it allows add-ons that gather
information about a card to work properly in the card template screen
without extra hacks.
2020-01-16 09:19:41 +10:00
Damien Elmes
6d9baaf052 check_untyped_defs in mypy for pylib 2020-01-16 08:10:49 +10:00
Damien Elmes
8cb980bacc fix checkLeech hint 2020-01-16 07:59:57 +10:00
Damien Elmes
b09e7e8247 more tweaks for readability/consistency 2020-01-15 17:45:35 +10:00
Damien Elmes
237c0791f8 more hook tweaks, and merge the pre-render field and template hooks 2020-01-15 17:18:11 +10:00
Damien Elmes
cab572b63c remove _hook/_filter suffix 2020-01-15 16:53:24 +10:00
Damien Elmes
b2f756f1b7 tweak the hook names in anki/
still a work in progress
2020-01-15 16:43:22 +10:00
Damien Elmes
eb6723a2ee fix stdmodels type hint 2020-01-15 15:30:40 +10:00
Damien Elmes
26cb9851b4 idempotent hook removal
This matches remHook()'s behaviour
2020-01-15 13:16:43 +10:00
Damien Elmes
f021d616dd add optional docstring to hooks 2020-01-15 12:14:32 +10:00
Damien Elmes
dbca596b41 clean stale build folders before build
setuptools will bundle up files from that folder even if they're
no longer in the source tree.
2020-01-15 10:07:39 +10:00
Damien Elmes
c67aefa3ea move hook gen code out of anki/
It's not needed at runtime, and this allows hooks to be updated
even when the code is broken.
2020-01-15 09:11:20 +10:00
Damien Elmes
cb14963066 add _ prefix to generated classes to improve code completion 2020-01-15 08:58:27 +10:00
Damien Elmes
2fa662f7ae add some more hooks; stringify fully qualified types
To avoid circular imports, types that contain a '.' are automatically
converted to strings.
2020-01-15 08:56:56 +10:00
Damien Elmes
2921037c7b remove some comments that are no longer relevant 2020-01-14 20:45:18 +10:00
Damien Elmes
2fb5ff5d9c fix broken answer displaying 2020-01-14 09:00:52 +10:00
Damien Elmes
662eb53e6a switch to classes for hooks
This allows us to add a docstring to .append() so users can see
the names of the arguments that are being passed, and means we
don't have to remember to prepend run_ when calling a hook.
2020-01-14 08:54:07 +10:00
Damien Elmes
33bf4c204b add hook to modify template prior to rendering 2020-01-13 21:57:15 +10:00
Damien Elmes
8946ad5483 include py.typed for mypy
these builds are now available on
https://github.com/ankitects/anki-typecheck

The add-on docs will be updated shortly to provide info on
using the new hooks and type checking.
2020-01-13 21:18:03 +10:00
Damien Elmes
125d6f9d1d add license to wheels and option to skip bundling extra files 2020-01-13 20:04:23 +10:00
Damien Elmes
d266dcd076 add a flag to handle the legacy hook missing args case
And update a few more hooks.
2020-01-13 18:37:08 +10:00
Damien Elmes
b86ae31907 update the rest of the anki/ hooks/filters 2020-01-13 17:59:52 +10:00
Damien Elmes
f379167648 run black on generated hooks 2020-01-13 17:55:58 +10:00
Damien Elmes
402a594c7b buildinfo required to generate hooks 2020-01-13 14:55:32 +10:00
Damien Elmes
4bb3d7a958 add separate file for gui hooks 2020-01-13 14:38:05 +10:00
Damien Elmes
dd61389319 New type-safe approach to hooks/filters
Still todo:
- Add separate module for GUI hooks
- Update the remaining runHook/runFilter() calls
- Document the changes, including defensive registration
2020-01-13 13:57:51 +10:00
Damien Elmes
b42912e639 mark anki and aqt modules as having typing info
This means once they're installed via develop or a wheel, add-ons
will be able to more easily typecheck their code against the Anki
code.
2020-01-13 13:03:37 +10:00
Damien Elmes
9bb0348fdd more template rendering tweaks
- The front and back are rendered in one call now. If the front
side contains no custom filters, we can bake {{FrontSide}} into the
rear side. If it did contain custom filters, we return the partially
complete rear template instead, and the calling code can inject
the FrontSide in after it has been fully rendered.

- Instead of modifying "cloze" into something like "cq-2", the card
ordinal and whether we're rendering the question or answer are now
passed in to the rendering filters as context.

- The Rust code doesn't need to support filter names split on '-'
anymore.

- Drop the "Show" part of hint descriptions so i18n support can be
deferred.

- Ignore blank filter names caused by user using two colons instead
of one.

- Fixed hint field and text transposition.
2020-01-12 21:34:07 +10:00
Damien Elmes
a51a4e4d31 drop pystache and move legacy code into separate file 2020-01-11 19:38:30 +10:00
Damien Elmes
dc8b854ada drop pystache comparison 2020-01-11 18:15:13 +10:00
Damien Elmes
3f724e5c98 replace fields and apply standard filters in rslib
The filters still need to be implemented.
2020-01-10 18:02:26 +10:00
Damien Elmes
f7ff0d1c17 flatten->render; pass field content in
This is paving the way to move the standard filters into Rust.

Non-empty fields are now determined in Rust, using a single regex
instead of the overkill stripHTMLMedia(). The old implementation
has been moved into the Pystache code for now.
2020-01-10 14:59:29 +10:00
Damien Elmes
a5613523ee rework new timezone code
We now store the UTC offset that was in effect at creation time,
and use that to determine the starting date.
2020-01-09 16:58:27 +10:00
Damien Elmes
5a9af48178 fix type:cloze, and remove misleading comments 2020-01-09 08:05:49 +10:00
Damien Elmes
02720ec604 fix CI failing
unsure why this doesn't fail locally, using the same mypy version
2020-01-08 20:49:40 +10:00
Damien Elmes
c0a69587f3 fix type answer filter 2020-01-08 20:29:15 +10:00
Damien Elmes
0087eee6d9 handle conditional replacement in Rust
This extends the existing Rust code to handle conditional
replacement. The replacement of field names and filters to text
remains in Python, so that add-ons can still define their own
field modifiers.

The code is currently running the old Pystache rendering and the
new implementation in parallel, and will print a message to the
console if they don't match. If you notice any problems, please
let me know.
2020-01-08 20:28:04 +10:00
Damien Elmes
031c4e814f move filter reversal into pystache 2020-01-08 18:59:05 +10:00
Damien Elmes
b014822253 use hooks for the built in filters as well
To support cloze deletions, we add back support for 'extra', but
using a simpler one character split instead of parens.
2020-01-08 18:08:24 +10:00
Damien Elmes
1f2e00690f move the rest of Anki's code out of pystache
In the process of factoring out the field filtering, the "extra"
and "fullname" args are just passed in as a blank string now.
Extra was functionality that allowed a field modifier to be defined
as "filtername(arg1,arg2):field", and fullname was the name of the
field including any provided field modifiers. From grepping through
the add-ons on AnkiWeb, neither appears to have been used.
2020-01-08 17:15:46 +10:00
Damien Elmes
5ce964e91d remove cloze handling in conditionals
As far as I can tell, this was not functional, as "{{#cloze:Text}}"
becomes cq-1:Text, which doesn't match the regex
2020-01-08 16:10:19 +10:00
Damien Elmes
83f0e15213 show stdout/stderr when running tests 2020-01-08 15:52:51 +10:00
Damien Elmes
29e476f482 no longer try fields with : in their names
it's not supported by the card generation code, and the card
layout screen will automatically fix note types
2020-01-08 14:42:54 +10:00
Damien Elmes
706ed225ca move furigana/hint filters into template2 2020-01-08 12:30:08 +10:00
Damien Elmes
4bca26161b clean up _renderQA(), and split rendering part out 2020-01-08 12:07:44 +10:00
Damien Elmes
e7ea121196 use 3.7 annotations 2020-01-07 18:43:20 +10:00
Damien Elmes
8b94d69abc bump minimum python version from 3.6 to 3.7 2020-01-07 18:34:36 +10:00
Damien Elmes
844e90fc80 don't need to rerun checks each time buildhash changes 2020-01-06 19:30:54 +10:00
Damien Elmes
947d35dfca add tests and setup.py to checks; fix warnings 2020-01-06 15:27:59 +10:00
Damien Elmes
fad2a66bc0 fix import order 2020-01-06 13:15:02 +10:00
Damien Elmes
99141d9dfb add a partial Python implementation of the backend 2020-01-06 12:24:47 +10:00
Damien Elmes
88e83ddae5 wheel deps should be checked at install time, not build time 2020-01-05 07:34:36 +10:00
Damien Elmes
f8df688648 don't reference missing readme in setup.py 2020-01-04 12:21:58 +10:00
Damien Elmes
1dd1acdffe quieten wheel build 2020-01-04 12:21:58 +10:00
Damien Elmes
0bfc90f52f update readme, remove submodule readmes 2020-01-04 12:21:58 +10:00
Damien Elmes
1c1fbde733 move top level scripts into makefile 2020-01-04 12:21:58 +10:00
Damien Elmes
06f219ce33 add default value to ServerData 2020-01-04 07:53:20 +10:00
Erez Volk
e481cce816 Merge remote-tracking branch 'upstream/master' into add-tags-on-update 2020-01-03 08:13:04 +02:00
Damien Elmes
a898f61ddd formatting fix 2020-01-03 15:21:36 +10:00
Damien Elmes
0aa01605d7 add buildhash to rspy and aqt, and check all three modules match 2020-01-03 15:15:18 +10:00
Damien Elmes
c25e106f88 use proper version number in build outputs 2020-01-03 14:36:14 +10:00
Damien Elmes
e2ede3af0e output into dist/ 2020-01-03 14:32:26 +10:00
Damien Elmes
253d429a8b drop 'extra' from default cloze note type
Too many users get confused about where they should be placing the
cloze deletions.
2020-01-03 13:40:50 +10:00
Damien Elmes
ab6247f8d9 fix invalid escape warning 2020-01-03 13:38:23 +10:00
Damien Elmes
0f4f3ab2c1 speed up two tests
the regular test run is now faster than the old parallel one was
2020-01-03 09:05:04 +10:00
Damien Elmes
9abeeac73a report slowest test 2020-01-03 09:03:39 +10:00
Damien Elmes
1070c866f3 switch from nose2 to pytest
pytest will show what differs in simple assert statements

concurrent mode is supported with a plugin, but like nose2, concurrent
mode hides the cause of import errors, so I've left it off for now.
2020-01-03 08:52:10 +10:00
Damien Elmes
c9da813622 don't reformat buildhash 2020-01-03 08:25:12 +10:00
Damien Elmes
5876866565 tweaking the folder names again
hopefully that's the last of it
2020-01-03 07:48:38 +10:00