Commit graph

3404 commits

Author SHA1 Message Date
Ben Nguyen
931e1d80f2
Enable strict_optional in aqt/. and aqt/browser (#3486)
* Boolean naming convention

* Rename no_strict_optional -> strict_optional

* Update CONTRIBUTORS

* Enable strict optional for aqt module

* Fix errors

* Enable strict optional for aqt browser

* Fix layout.py errors

* Fix find_duplicates.py errors

* Fix browser.py errors

* Revert a0 a1 names

* Fix tree.py errors

* Fix previewer.py errors

* Fix model.py errors

* Fix find_and_replace.py errors

* Fix item.py errors

* Fix toolbar.py errors

* Fix table/__init__.py errors

* Fix model.py errors

* Fix state.py errors

* Fix table.py errors

* Fix errors in card_info.py

* Fix searchbar.py errors

* Fix name

* Fix assert in browser.py

* Formatting

* Fix assert vh

* assert is not None instead of truthy

* Split _move_current() up to correct type signature (dae)

We want either index or direction, but not both.
2024-10-11 23:12:48 +10:00
a.r
8af63f81eb
typeanswer: NFC fix & cleanup (#3482)
* typeanswer: cleanup

* DiffNonCombining's new() used String where plain Vec is appropriate
* get rid of normalize_typed for DiffTrait again by pulling code into DiffNonCombining's new()
* two DiffNonCombining testcases

* typeanswer: return to NFC & typos
2024-10-11 20:33:08 +10:00
Arthur Milchior
18889239d2
NF: Improve typing of AnkiWebView action (#3475)
There are only two types of actions. The code does not seems to
consider this to be extandable, and the changed variable is private,
so I would expect it relatively acceptable to change the way it
work. This would improve the typing.

If this is rejected, at least, the callback should be noted as
optional, so that the IDE does not complain that `if cb` can not be
false.
2024-10-11 20:16:20 +10:00
Damien Elmes
79a6a4dc53 Pretend mw is set from the start
https://github.com/ankitects/anki/pull/3476#issuecomment-2395281774

Closes #3476
2024-10-10 22:17:58 +10:00
Hikaru Y.
407e2dc43b
Fix issues with 'Discard changes' confirmation dialog (#3478)
* Prevent memory leak

* Fix deck option changes not detected until focus is lost

* Accurately determine if there are any pending changes

This makes it so that the confirmation dialog appears when it should,
and not when it shouldn't.
2024-10-06 14:21:00 +10:00
Damien Elmes
378c955905 Revert "Fix ease button alignment (#3404)"
This reverts commit a262e02f9d.

Due to regression:
https://forums.ankiweb.net/t/anki-24-10-beta/49989/119
2024-10-04 22:38:50 +10:00
user1823
de3b1754fa
Add "open image" option to editor (#3431)
* Add "open image" option to editor

* Update qt/aqt/editor.py

Co-authored-by: Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>

* Update editor.py

* Remove unused import

* Fix "show in folder"

* Fix 'show in folder' on macOS

* Revert "Fix "show in folder""

This reverts commit cf2b33ee9422bcaf8d9e20bd4cce74e5061c13cf.

* Reimplement show_in_folder for Windows (dae)

- Avoid reusing call(), as the startupinfo we were passing in was
breaking the explorer invocation
- Attempt to bring explorer to the front after the window has been show,
as it otherwise appears under Anki (at least when running from source)

---------

Co-authored-by: Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2024-10-04 20:51:55 +10:00
박현우
761fb76ba7
Allow addon page URL on AddonsDialog (#3467)
* Allow users to just copy&paste addon page URL to addon 'code' field.

https://forums.ankiweb.net/t/get-addons-allow-url-on-code-section/36370
2024-10-04 15:02:29 +10:00
Shirish Pokhrel
2ac27585b2
Fix editor loses focus when toggling list and copy selects wrong target deck for filtered decks (#3465)
* fix copy selects wrong target deck for filtered decks
2024-10-02 18:42:41 +10:00
Taylor Obyen
d6aa95950d
Fix occlusion drift again (#3443)
* Fix occlusion drift

* Fix image editor occasionally not loading fully

* Fix occlusion disassociation when browsing

* Address oversights

* Fix translucent modifier applies to newly created shapes incorrectly

* Fix i-text turns yellow upon immediate note change

* Fix image occlusion hot keys not disabled when typing

* Improve text label creation experience

* Remove redundant functions

* Fix error when adding occlusion (dae)
2024-10-02 17:19:52 +10:00
Voczi
343a304257
Fix error when closing deck options (#3454) 2024-09-30 23:44:20 +10:00
a.r
e2124cd790
typeanswer: [type:nc] – ignores combining characters (#3422)
* typeanswer: fix cleanup

Fix: Add prepare_expected back in for the 'nothing typed' & 'correctly typed' cases. This also makes expected_original redundant again.

Style: %s/provided/typed/g

Style: rename one ch → c

Testcase: whitespace_is_trimmed: added a check for the "correctly typed" path and renamed it to tags_removed (there's no whitespace?)

Testcase: empty_input_shows_as_code: changed to also check that tags get trimmed

* [type:nc] – ignores combining characters

Adds a comparison variant to [type] which ignores when combining characters of the expected field are missing from the provided input. It still shows these characters in the 'expected' line for reference.

It's useful for languages with e.g. diacritics that are required for reference (such as in dictionaries), but rarely actually learned or used in everyday writing. Among these languages: Arabic, Hebrew, Persian, Urdu.

The bool 'combining' controls it as new final parameter of both relevant compare_answer functions. On the Python side, it's set to true by default.

Use on the note templates: [type:nc:field] (only the front needs to include :nc)

This also removes the need to have both variants of words/sentences present as separate fields, to show them redundantly, etc.

* typeanswer: simplify by using nfkd throughout

Requires adjusting two testcases, but both render exactly the same in Anki itself.

On NFC vs. NKFD: https://stackoverflow.com/a/77432079

* typeanswer: 'simplify' by removing normalize_typed (requiring a bool parameter)

I'd prefer to keep this extra method.

* typeanswer: micro-optimize vectors

Should get rid of most relocations, at the expense of over-allocating.

On Vec's (String's) behavior: https://stackoverflow.com/a/72787776

* Mark `combining` as private

typeCorrect is not marked as private either, but we can at least do
the right thing for newly-added code.

* Revert "typeanswer: micro-optimize vectors"

This reverts commit 9fbacbfd19.

* Revert "typeanswer: 'simplify' by removing normalize_typed (requiring a bool parameter)"

This reverts commit df2dd3394e.
2024-09-30 23:11:51 +10:00
Damien Elmes
7fb261c90b Backup warning needs a new string
We need a new key, as we've introduced a variable. Missed this in
the PR review.
2024-09-27 19:36:58 +10:00
Damien Elmes
f3b0afcc62 Revert "Fix pasting from the primary selection (#3413)"
This reverts commit 0a879bd2ed.

Closes #3435
2024-09-25 20:59:10 +10:00
Taylor Obyen
df127b1af7
Add revert to backup option to file menu (#3434)
* Add revert to backup context item

* Fix contributors a new way

* Change relative time to filename

* Update ftl/qt/qt-accel.ftl (dae)
2024-09-25 20:21:59 +10:00
Damien Elmes
5dfef8aae2 Fix formatting 2024-09-22 18:36:01 +10:00
Ben Nguyen
c2f3e63b90
Bug with “A 100 day interval will become X days.” (#3432)
* add name to about page

* use two decimal retention for calculations

* Update CONTRIBUTORS

* format

* Update CONTRIBUTORS

* Update CONTRIBUTORS

* Update CONTRIBUTORS
2024-09-22 18:24:32 +10:00
Arthur Milchior
b08e454f57
If deck options are modified, ask before closing (#3410)
* If deck options are modified, ask before closing

This imitates the way the note editor behaves. If a user assumes by
error that chanhges are automatically saved, it ensures they won't
lose them.

Also, this will eventually allows to have the same feature on
AnkiDroid. While, currently, we always ask the user whether they want
to close the deck options, even when there are no modification, which
seems to regularly frustate users (including myself).

I'm new to Svelte, please let me know whether there is a better way to
obtain the information from Svelte state that I missed.

Note that I ensured that only a boolean can be obtained. I didn't
cause the whole state to be accessible. May be useful for some
add-ons, I guess, but risks breaking too much things.

Regarding the deckoptions.py, I tried to imitate addcards.py way to
check whether the add card view can be closed. Reusing the same
function and variable name when possible.

* Update qt/aqt/deckoptions.py (dae)
2024-09-22 18:07:24 +10:00
Kris Cherven
163c10191f
Fix Qt desktop file name warning (#3419)
* Fix Qt desktop file name warning

* Update CONTRIBUTORS
2024-09-22 18:02:35 +10:00
Taylor Obyen
90661c4bfc
Track Current Deck Context from Browser (#3385)
* Update current deck from browser

* Update contributors

* Fix formatting

* Allow Add window to be opened with parameters

* Add explicit return

* Fix formatting

* Accomplish context in a more simple fashion

* Implement context menu add

* Fix contributors

* Add additional context

* Removed uneeded logic and inlined redundant funcs

* Resolve contributors conflict

* Update qt/aqt/deckbrowser.py

* Update qt/aqt/deckbrowser.py
2024-09-22 18:02:17 +10:00
user1823
02d2566998
Add an option to show image from editor in folder (#3412)
* Add "Show in folder" option to images in editor

Credits: @abdnh's Reveal in File Manager add-on (https://github.com/abdnh/anki-misc/tree/master/reveal_in_file_manager)

* Refactor
2024-09-20 21:38:44 +10:00
Abdo
5bd66db3c6
Call the profile_did_open() hook earlier (#3421) 2024-09-20 21:22:27 +10:00
Kris Cherven
0a879bd2ed
Fix pasting from the primary selection (#3413)
* Fix clipboard pasting from the primary selection

* Small renaming

* Fix submodules

* Fix pylint false positive
2024-09-20 21:00:12 +10:00
Ben Nguyen
77fb0fb708
Possible to show “last” subdeck name in Browser? (#3387)
* elide middle of deck names

* Update CONTRIBUTORS

* made elide mode enum

* add elide mode field

* fix enum number

* remove dataclass decorator

* Update CONTRIBUTORS

* format rust code

* Update CONTRIBUTORS

* formatting

* Update CONTRIBUTORS

* fix type hint

* Update CONTRIBUTORS
2024-09-20 20:33:28 +10:00
Taylor Obyen
a262e02f9d
Fix ease button alignment (#3404)
* Fix ease button alignment

* Fix contributors part 2
2024-09-11 02:44:11 +07:00
Abdo
9223b35aa0
Stop automatically adding Image Occlusion type in Add screen (#3408) 2024-09-11 02:21:37 +07:00
Gregory
f496411da8
Updated error message to provide help for import if 'Legacy Import/Export' is enabled (#3399)
* Updated error message to provide additional guidance for file import issues if Legacy Import/Export is enabled

Enhanced the error message from "Unable to read file. It probably requires a newer version of Anki to import." 
  to include a suggestion for users to try unchecking 'Legacy import/export Handling' under Preferences > Editing > 
  Import/Export if they encounter the issue.

* Update CONTRIBUTORS
2024-09-11 02:06:35 +07:00
Abdo
40bcbe44bf
Fix field focus lost when pressing alt in the editor (#3378) 2024-08-29 17:32:24 +07:00
Themis Demetriades
0f44796b36
Fix imports of decks with file paths using special URL characters (#3377) 2024-08-29 17:19:27 +07:00
David Culley
b35b69a2d3
mypy: fix type checking error (#3365)
* refactor: fix type checking error

error: Argument 1 to "_answerCard" of "Reviewer" has incompatible type "int"; expected "Literal[1, 2, 3, 4]"  [arg-type]

* refactor: remove check that `ease` is correct number

* refactor: rename variable

* refactor: add type hint for generator function

* refactor: revise import of `functools.partial`

* refactor: invert logic of if-construct

to avoid nesting.

* refactor: properly check for `None`

* Update qt/aqt/reviewer.py
2024-08-29 17:07:06 +07:00
Damien Elmes
be2f013cb7 Add Eros to about
A reminder that anyone who has contributed help is welcome to add themselves
in a PR.
2024-08-28 23:25:00 +07:00
Abdo
83f044491b
Ensure profile name is treated in a case-insensitive manner (#3372) 2024-08-22 17:35:48 +07:00
David Culley
a6d5c94997
python: add missing type annotations for None values (#3364)
* refactor: explicitly add NoneType to type hints

If variable can be `None`, don't be implicit. Be explicit.
2024-08-22 16:03:44 +07:00
Jarrett Ye
8ed9f49bdc
Feat/FSRS Simulator (#3257)
* test using existed cards

* plot new and review

* convert learning cards & use line chart

* allow draw multiple simulations in the same chart

* support hide simulation

* convert x axis to Date

* convert y from second to minute

* support clear last simulation

* remove unused import

* rename

* add hover/tooltip

* fallback to default parameters

* update default value and maximum of deckSize

* add "processing..."

* fix mistake
2024-08-22 15:34:19 +07:00
bpnguyen107
f2adf5d9ad
Hide right click copy option in deck list (#3363)
* hide copy if nothing selected

* Update CONTRIBUTORS

* type hint

* Update CONTRIBUTORS
2024-08-17 13:18:46 +07:00
bpnguyen107
c99b50c82f
Right click context menu on images not useful (#3362)
* right click and copy on image works

* renamed helper fn

* separated functionality of copy and copy image

* Update CONTRIBUTORS

* snake case

* Update CONTRIBUTORS
2024-08-17 13:18:07 +07:00
Abdo
520564da11
Integrate AnkiHub Sign-in (#3232)
* Add AnkiHub section to preferences screen

* Add short intro for AnkiWeb and AnkiHub to syncing section

* Add AnkiHub login screen

* Implement login methods in backend

* Set minimum dialog width

* Add missing colon

* Respect the ANKIHUB_APP_URL env var

This is used by the add-on.

* Simplify login error reporting

* Fix from_prefs_screen not passed to subcall

* Add missing ankihub_pb2 import

* Install AnkiHub add-on after sign-in

* Avoid .exec()

* Update ftl/core/sync.ftl

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* Split translation string

* Support login by username/email

* Fix entered username/email not being passed back to on_done

* Remove unused import

* Move to 'Third-party services' section

* Tweak login dialog's heading

* Remove 'third-party' from intro text

* Tweak copy

* Prefix profile keys

* Tweak strings

* Remove description from login dialog

* Remove signup links

* Clear credentials in ankihub_logout()

* Call .adjustSize()

* Title Case

* Add padding to third-party services, and fix tab order from other PR
2024-08-17 10:58:23 +07:00
David Culley
4fb6fa81ac
refactor: use not in and is not as recommended (#3351)
- https://docs.astral.sh/ruff/rules/not-is-test/
- https://docs.astral.sh/ruff/rules/not-in-test/
2024-08-10 17:55:26 +07:00
Voczi
1065941767
Add option for toggling update checks (#3346) 2024-08-10 17:46:49 +07:00
David Culley
70a063a3b9
Fix error if regex can't find the filename (#3285)
* fix: treat error if regex doesn't match

* refactor: use assertion to avoid error message
2024-08-07 16:17:37 +07:00
Asuka Minato
e851d0d281
Update about.py (#3330)
* Update about.py

* Update CONTRIBUTORS
2024-08-05 15:56:04 +07:00
cdonat2
b1bf1c3141
Add maximize hint for models.py (#3151) (#3328)
Co-authored-by: Christian Donat <cdonat@tu-berlin.de>
2024-08-05 15:21:18 +07:00
David Culley
bab83ffce0
fix: add proper imports (#3296)
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2024-08-05 11:34:46 +07:00
David Culley
44380dd62a
Specify Python version for auto-formatters (#3325)
* chore(isort): specify Python version to be assumed

https://pycqa.github.io/isort/docs/configuration/options#python-version

Default is to assume _any_ Python 3 version could be the target.

* chore(black): specify Python target versions

https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#t-target-version

* chore(ruff): specify Python version to be assumed

https://docs.astral.sh/ruff/settings/#target-version

* chore: exclude directories from auto-formatting
2024-08-04 20:54:14 +07:00
David Culley
37a3f4708a
Refactor _addButton method of editor (#3294)
* refactor: simplify f-string

* refactor: use more readable names

* style: separate if-else-clauses by empty lines

* fix: add missing import

Properly `import os`.

* refactor: simplify variable assignment

* refactor: rename variables

* refactor: use f-string

* refactor: reorder variables

* refactor: simplify if-clause with de morgan's laws

* refactor: simplify if-else-construct

* fixup! refactor: rename variables

* Revert "refactor: use f-string"

This reverts commit 1dcb58bdab.

* Revert "fixup! refactor: rename variables"

This reverts commit 813130ba6a.
2024-08-04 20:51:45 +07:00
David Culley
c0349ea9da
Improve exception handling (#3290)
* fix: except only non-system-exiting exceptions

see https://youtu.be/zrVfY9SuO64

* chore: add myself to CONTRIBUTORS file

* refactor: explicitly specify possible exceptions

If an exception is not an Exception, there are only three options left.
see https://docs.python.org/3/library/exceptions.html#exception-hierarchy

* refactor: use BaseException for fallback

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* chore: add myself to contributors
2024-08-04 20:51:13 +07:00
David Culley
a5a39c9302
Fix 'NoneType object is not subscriptable' error (#3286)
* fix: ensure none of the returned values is None

Fixes TypeError 'NoneType' object is not subscriptable

* refactor: reduce code duplication using a function

* refactor: prefer KeyError over None for dicts

If the key is not in the dictionary, we want to raise a KeyError rather
than returning None. That way, we can distinguish between whether the
value was None or the key was not found.

* chore: add myself to CONTRIBUTORS file

* refactor: simplify the code
2024-08-04 20:49:45 +07:00
Damien Elmes
1910b9609e Drop non-working tiff support
https://forums.ankiweb.net/t/anki-fails-to-attach-tif-images-to-cards/47609
2024-08-01 12:19:35 +07:00
David Culley
0743e6e40e
Update type annotations to use | operator (#3323)
* refactor: update to `|` operator

* refactor: add missing type hint

* refactor: enable `|` operator for older versions

* refactor: remove obsolete import
2024-07-26 18:15:39 +07:00
David Culley
363a52526e
Update type annotations (#3322)
* refactor: update Callable type hint

* refactor: update type annotations for hooks
2024-07-26 17:57:25 +07:00