diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index 0fb778f61..8bceb7346 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -5,7 +5,6 @@ from __future__ import annotations import copy import json -import operator import unicodedata from typing import Any, Dict, List, Optional, Set, Tuple, Union @@ -298,6 +297,10 @@ class DeckManager: def _basename(self, name: str) -> Any: return self._path(name)[-1] + @classmethod + def key(cls, deck: Dict[str, Any]) -> List[str]: + return cls._path(deck["name"]) + def _ensureParents(self, name: str) -> Any: "Ensure parents exist, and return name with case matching parents." s = "" @@ -455,7 +458,7 @@ class DeckManager: def _checkDeckTree(self) -> None: decks = self.col.decks.all() - decks.sort(key=operator.itemgetter("name")) + decks.sort(key=self.key) names: Set[str] = set() for deck in decks: @@ -571,7 +574,7 @@ class DeckManager: childMap = {} # go through all decks, sorted by name - for deck in sorted(self.all(), key=operator.itemgetter("name")): + for deck in sorted(self.all(), key=self.key): node: Dict[int, Any] = {} childMap[deck["id"]] = node diff --git a/qt/aqt/studydeck.py b/qt/aqt/studydeck.py index 1a024b7c4..00538a880 100644 --- a/qt/aqt/studydeck.py +++ b/qt/aqt/studydeck.py @@ -3,6 +3,7 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import aqt +from anki.decks import DeckManager from anki.lang import _ from aqt import gui_hooks from aqt.qt import * @@ -51,7 +52,10 @@ class StudyDeck(QDialog): if title: self.setWindowTitle(title) if not names: - names = sorted(self.mw.col.decks.allNames(dyn=dyn, force_default=False)) + names = sorted( + self.mw.col.decks.allNames(dyn=dyn, force_default=False), + key=DeckManager._path, + ) self.nameFunc = None self.origNames = names else: