Adding a menu item to the editor

For an add-on I’m trying to add a menu item / button to the editor that

  • appears at the bottom of the browse window
  • can be opened with the “Edit” button from any card

I found hooks like e.g. gui_hooks.editor_did_load_note.append(foo) which, in the method called (foo here) gives me the editor object. For the editor object, its web attribute (a EditorWebView) seems to be the GUIs area that I’m interested (everything above the Tags text field). But I can’t find a way to add more buttons to the thing. I looked at qt/aqt/editor.py and qt/aqt/webview.py trying to imitate the code there that adds all to buttons. but to no avail.

I’d also be perfectly find with adding a menu item to the context menu I assume triggers gui_hooks.editor_will_show_context_menu.

Thanks in advance for any help.

Found it out myself. If anyone else wonders:

def setupButtons(buttons, editor): 
    [...]
    btn = editor.addButton(icon_path,
                         'foo',
                         your_function,
                         tip='hover etxt')
    buttons.append(btn)

gui_hooks.editor_did_init_buttons.append(setupButtons)
2 Likes