It looks like pyqt5 is playing dirty and checking the number of args of
functions before calling them. When using hooks.wrap, pyqt5 thinks it
can pass any amount of arguments (because *args) and you get exceptions
like this inside the wrap function, when calling the 'old' function:
>TypeError: onFindDupes() takes 1 positional argument but 2 were given
This commit fixes it by preserving the signature of the wrapped method,
by adding an optional dependency on the "decorator" module.
Making it an optional dependency is probably not the wisest idea but
since this is a small edge case it might be smoother to start like this.
I also added functools.wraps() as a fallback, which won't help much but
is slightly more correct.
See this article for details: https://hynek.me/articles/decorators/
on windows webengine seems to install a permanent ctrl+z handler that is
active even when an editing area is not selected, so our shortcut is
never triggered when the webengineview is focused.
we can't use an event filter on the top level webview, because it
ignores the return value of the filter and leads to Anki thinking
keys have been pressed twice
and if we use an event filter on the focusProxy(), the
keypress/release events are sent even when a text field is currently
focused, leading to shortcuts being triggered when typing in the answer
to solve this, we move away from handling the key press events
directly, and instead install shortcuts for the events we want to
trigger. in addition to the global shortcuts, each state can install
its own shortcuts, which we remove when transitioning to a new state
also remove the unused canFocus argument to ankiwebview, and accept a parent
argument as required by the code in forms/
- key presses while a webview is focused no longer make it to the
main window's keyPressEvent() routine, so AnkiWebView now uses its
event filter to pass the key events to the main window
- move the shared key handling out of keyPressEvent into
globalKeyHandler()
- make sure all key handling routines return true or false to
indicate if an event was handled or not
- remove focus when esc hit in the main window, to retain old
behaviour of allowing esc to clear focus from the type answer box