Editor_did_init_left_buttons hook is not working?

I try to use a gui_hooks named editor_did_init_left_buttons. The code for the addon below will be triggered whenever we click the Add new card button.

from aqt import gui_hooks
from aqt.utils import showWarning

def button(btn, editor):
    showWarning(str(btn))
    showWarning(str(editor))

gui_hooks.editor_did_init_buttons.append(button)

The problem is, when I try to print out the content of the first parameter btn, all I got is an empty list.
I search through the code to figure out where does the hook got triggered and I saw it’s in aqt.editor.

In the screenshot above, we can see the first argument that is passed to the hook is lefttopbtns.

But why the addon I wrote is returning an empty list?

It seems the editor code in your screenshot is outdated. You can see here that lefttopbtns is an empty list now: anki/editor.py at c9bd39c6a212dc5f4a2484da4a0690225bd6d923 · ankitects/anki · GitHub

This was changed in this commit: Add RawButton and hook old python hooks up to it · ankitects/anki@920b740 · GitHub

@abdo thanks for the insight.

Just saw the anki package in my machine is 2.3.7.

I tried to upgrade it to 2.1.49 but I keep getting the error saying requirement not satisfied.

I am runnig python 3.10, Windows 10 64-bit.

I would suggest trying with Python 3.9, as 3.10 is not fully supported yet.

1 Like