I followed the instructions from the manual but the “Config” button still remains disabled when I select my add-on in the add-on manager.
My addon’s folder contains the following files:
__init __.py
add-on.py
config.json
config.md
And a user_files folder.
The config.json file contains a dictionary with two entries.
The add-on.py file begins with:
from aqt import editor, gui_hooks, mw
from aqt.addcards import AddCards
from aqt.utils import *
from aqt.forms import addcards
from datetime import datetime, timedelta
from time import *
import math
import sqlite3
import sys
import pathlib
import json
config = mw.addonManager.getConfig(__name__)
How to solve it?
Edit: I tried to implement the example provided in the manual but Anki returns the following error message when I try to open it:
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 ‘addOnFromTheManual’:
Traceback (most recent call last):
File “aqt.addons”, line 244, in loadAddons
File “C:\Users\User\AppData\Roaming\Anki2\addons21\addOnFromTheManual\ __init __.py”, line 1, in
from . import addOnFromTheManual
File “C:\Users\User\AppData\Roaming\Anki2\addons21\addOnFromTheManual\addOnFromTheManual.py”, line 3, in
print(“var is”, config[‘myvar’])
TypeError: ‘NoneType’ object is not subscriptable
P.s. I’m using Anki 2.1.53, Python 3.9.6, Windows 10 and Visual Studio Code 1.68.1.
Works for me. The problem is most likely caused by a malformed config.json. getConfig() in this case returns None. Check your JSON or post the file here.
Looks correct, and I can’t reproduce your issue. The config button works for me with this config. If you can post the full code of the add-on, maybe that will help reveal the issue.
Sure. I’m making the code looks more neat right now (deleting some functions and variables that doesn’t have use anymore and translating the ones I didn’t write in English) and I’ll share it soon.
Meanwhile, here’s the code I used to reproduce the example provided in the add-on docs:
P.s. This add-on also didn’t have the “Config” button enabled and raised the error I described in the original post. The same error was raised when I tried to run the add-on I’m working on.
__init __.py
from . import addOn
addOn.py
from aqt import mw
config = mw.addonManager.getConfig(__name__)
print("var is", config['myvar'])
config.json
{"myvar": 5}
config.md
This is documentation for this add-on's configuration, in *markdown* format.
It just came to my mind that the file was saved with the wrong codification, then I applied the UTF-8 codification instead of UTF-8 with BOM and it worked!
By the way, thank you for spending your time to help me once again.