Liresol / anki-custom-shortcuts

Custom Keyboard Shortcuts for Anki 2.1
MIT License
62 stars 14 forks source link

Addon throws an error at launch on QT6 beta of Anki #140

Closed ELLIOTTCABLE closed 2 years ago

ELLIOTTCABLE commented 2 years ago

Problem description

Dae's posted a QT6 beta of Anki. Most of my addons work fine, but unfortunately, that doesn't include Custom Shortcuts.

Information about your Anki set-up

    Anki 2.1.50 (abd671d4) Python 3.9.7 Qt 6.2.0 PyQt 6.2.0
    Platform: Mac 12.0.1
    Flags: frz=True ao=True sv=3
    Add-ons, last update check: 2021-12-02 08:37:14

    ===Add-ons (active)===
    (add-on provided name [Add-on folder, installed at, version, is config changed])

    ===IDs of active AnkiWeb add-ons===

    ===Add-ons (inactive)===
    (add-on provided name [Add-on folder, installed at, version, is config changed])

Error message (if any)

An add-on you installed failed to load. If problems persist, please go to the Tools>Add-ons menu, and disable or delete the add-on.

When loading '⁨Customize Keyboard Shortcuts⁩':
⁨Traceback (most recent call last):
  File "aqt.addons", line 239, in loadAddons
  File "/Users/ec/Library/Application Support/Anki2/addons21/24411424/__init__.py", line 1, in <module>
    from . import custom_shortcuts
  File "/Users/ec/Library/Application Support/Anki2/addons21/24411424/custom_shortcuts.py", line 665, in <module>
    cs_main_setupShortcuts()
  File "/Users/ec/Library/Application Support/Anki2/addons21/24411424/custom_shortcuts.py", line 101, in cs_main_setupShortcuts
    if scut.id() in id_main_config:
AttributeError: 'QShortcut' object has no attribute 'id'
Liresol commented 2 years ago

Hello, I just pushed out an update to fix this issue. It works for me on 2.1.50beta1 but if you are encountering any issues, let me know and I will look into it further.

ELLIOTTCABLE commented 2 years ago

Hm. I installed from the Anki Addon Store — there's no more crashes, but the addon doesn't seem to … have any effect. For instance, I've modified the following:

{
    "reviewer choice 1": "a",
    "reviewer choice 2": "r",
    "reviewer choice 3": "s",
    "reviewer choice 4": "t",
}

And only the second line, "reviewer choice 2": "r",, is … working.

Worse, it does seem to unbind the existing keys (1, 2, 3, 4 don't work).

Liresol commented 2 years ago

Ok, I think I managed to work this one out as well. I think based on how Anki checks for updates you might need to check for updates manually for this patch, but let me know if any issues persist or if there are other problems with 2.1.50.

ELLIOTTCABLE commented 2 years ago

Hm. I'm not sure what you meant by manually updating — I tried uninstalling and re-installing via the Anki code, but no luck: the above snippet still has no effect, except for the key "r"; it also still disables the 1, 2, 3, 4 keys.

Any debugging steps I could take? I'm a fairly competent programmer, although not one that uses Python …

Liresol commented 2 years ago

The addon tab has a "Check for Updates" button on the top right which you usually never need to use since Anki checks for updates every 24 hours or so. The shortcut patch came out very soon after the initial fix, so Anki might not automatically tell you the patch existed at the time. The main cause of the shortcut issue is that A, S, and T are all shortcuts used on the main menu and on the reviewer, so what you were experiencing before was an annoying interaction between main shortcuts and reviewer shortcuts (which was my fault).

If you have two functions with the same shortcuts (e.g. you have the default "main add": "a" and "reviewer choice 1": "a" then both shortcuts stop functioning). Actually, since you reinstalled the shortcuts, it possible that the main shortcuts got reset to the defaults (and weren't set to what you had before), which would cause an identical behavior to what was happening before.

ELLIOTTCABLE commented 2 years ago

Ah, that's frustrating!

For now, switching all the main-window bindings to be behind Alt fixed my issue — arst now function as I need them to.

Okay, I checked for updates, and it insisted none were available — unless I misunderstand, then, the "main-and-reviewer" behaviour is unavoidable / intended, right now? Because it's definitely still occurring, even though "check for updates" yielded no further changes.

If it is unavoidable, a programmatic check-for-conflicts and an error-message to present to the user might be a great enhancement; but may not be worth the time if I was the only user stupid enough to miss that. 🤣

Liresol commented 2 years ago

Yeah the issue with collisions is inherent to the way Anki is built, which does the weird non-functioning shortcut thing if you try to make a shortcut do more than one thing at once.

The conflict detection feature actually exists, but it happened to miss this because it normally catches shortcut collisions within a single context (and I actually didn't realize the main-reviewer interaction existed until you found it here). I'm going to see if I can add a warning for this, because it's definitely annoying to have shortcuts disappear on you.