hi,
i use win10+anki23.10+fsrs.
previously discussed that to mimic supermemo’s “importance”, in the setup above
i’ll create subdecks of lv1a, lv1b, lv1c, lv1d, … lv2d, then lv3, lv4.
i asked LLMs (mainly C3.5 sonnet thru cursor) to make a addon to create subdecks, and also use pre-existing presets for that.
the code is here:
from aqt import mw
from aqt.qt import QAction, QInputDialog
from aqt.utils import showInfo
from anki.hooks import wrap
from anki.decks import DeckManager
def check_and_create_subdecks(deck_id, level):
# Define the required subdeck names for each level
subdeck_names = {
"lv1": [
"lv1-pri-highest",
"lv1a-pri-highest",
"lv1b-pri-high",
"lv1c-pri-nml",
"lv1d-pri-low"
],
"lv2": [
"lv2-pri-nml",
"lv2a-pri-nml",
"lv2b-pri-low",
"lv2c-pri-lowest",
"lv2d-pri-least"
],
"lv3": ["lv3-pri-lowest"],
"lv4": ["lv4-pri-least"]
}
if level not in subdeck_names:
showInfo("Invalid level selected.")
return
# Get the full name of the selected deck
deck = mw.col.decks.get(deck_id)
parent_deck_name = deck['name']
# Get all existing deck names
existing_decks = mw.col.decks.all_names()
# Get all existing config/preset names
all_configs = mw.col.decks.all_config()
config_dict = {conf['name']: conf['id'] for conf in all_configs}
# Initialize a list to keep track of created subdecks
created_subdecks = []
missing_presets = []
# Check for each required subdeck
for subdeck_name in subdeck_names[level]:
full_subdeck_name = f"{parent_deck_name}::{subdeck_name}"
if full_subdeck_name not in existing_decks:
# Create the new subdeck
new_deck_id = mw.col.decks.id(full_subdeck_name)
# Try to find and assign the matching preset
if subdeck_name in config_dict:
deck = mw.col.decks.get(new_deck_id)
deck['conf'] = config_dict[subdeck_name]
mw.col.decks.update(deck)
created_subdecks.append(subdeck_name)
else:
missing_presets.append(subdeck_name)
created_subdecks.append(f"{subdeck_name} (with default preset)")
if created_subdecks:
mw.col.reset()
message = f"The following subdecks were created under '{parent_deck_name}':\n" + "\n".join(created_subdecks)
if missing_presets:
message += "\n\nWARNING: Could not find matching presets for:\n" + "\n".join(missing_presets)
else:
message = f"All subdecks for {level} already exist under '{parent_deck_name}'."
showInfo(message)
def on_deck_selected():
# Get the currently selected deck ID
deck_id = mw.col.decks.current()['id']
if not deck_id:
showInfo("Please select a deck before running this add-on.")
return
# Prompt the user to select the level
levels = ["lv1", "lv2", "lv3", "lv4"]
level, ok = QInputDialog.getItem(mw, "Select Level", "Choose the level:", levels, 0, False)
if ok and level:
check_and_create_subdecks(deck_id, level)
else:
showInfo("Operation cancelled.")
def add_menu_option():
action = QAction("Check and Create Subdecks", mw)
action.triggered.connect(on_deck_selected)
mw.form.menuTools.addAction(action)
# Initialize the add-on by adding the menu option
add_menu_option()