Add-on required to interchange the "Add" and "Close" buttons

I’m over 80, so I now rely on Anki as my major alternate hippopotamus (-campus ?)

I would be most grateful if someone could write an app to interchange the “Add” and “Close” buttons on the “Add” dialog (which is presented for adding/editing a card).

In the current configuration, I spend 98.37% of my Anki time reading the “Discard current input?” dialog.

I might not be alone:

"AI Overview
Learn more

Primary & Secondary Action Buttons | by Nick Babich | UX Planet
The desired action button in a dialog box should generally be placed on the right side. This is because it follows the natural reading pattern from left to right, and aligns with the user’s expectation of progressing forward."

Thanks

1 Like

You can try the following:

__init__.py

from aqt.addcards import AddCards
from aqt.gui_hooks import add_cards_did_init
from aqt.qt import QHBoxLayout


def on_add_cards_did_init(addcards: AddCards) -> None:
    bbox = addcards.form.buttonBox
    for btn in bbox.buttons():
        bbox.removeButton(btn)
    addcards.form.verticalLayout_3.removeWidget(bbox)

    hbox = QHBoxLayout()
    hbox.addStretch()

    # You can rearrange the buttons by changing the order of these lines.
    hbox.addWidget(addcards.historyButton)
    hbox.addWidget(addcards.helpButton)
    hbox.addWidget(addcards.closeButton)
    hbox.addWidget(addcards.addButton)

    addcards.form.verticalLayout_3.addLayout(hbox)


add_cards_did_init.append(on_add_cards_did_init)
5 Likes

I’ve logged this on Use platform-native button ordering · Issue #3720 · ankitects/anki · GitHub

2 Likes

.
@hkr:

Many thanks for the code.

Unfortunately, I get the following error:

Anki 24.11 (87ccd24e) (ao)
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
Platform: Windows-10-10.0.22631

When loading Switch_Add_Close_buttons:
Traceback (most recent call last):
File “aqt.addons”, line 250, in loadAddons
File “C:\Users<me>\AppData\Roaming\Anki2\addons21\Switch_Add_Close_buttons_init_.py”, line 1, in
init.py
NameError: name ‘init’ is not defined

Please advise.

Thanks
.

Sorry for the confusion.

__init__.py refers to the filename, not part of the code itself. The actual first line of the add-on code is:
from aqt.addcards import AddCards

Please make sure to name the file __init__.py, as this is required. For more details about the folder structure specifications for add-ons, please refer to this link.

1 Like

I took the liberty to put it in the proper anki addon format. simply download and execute this file and it will install the code of hkr. All credits to him, I haven’t tested it or changed anything.

Feel free to edit the source code afterwards in your addons folder (you can find the source in addons21/button_switcher/__init__.py

hope this helps.

4 Likes

.
@CravingCrates:

Great job. Thanks.

I bullied the UI as much as possible - but failed to break it.

Thanks also to @hkr and @dae
.

1 Like