Skip to content

Commit

Permalink
Revert "Do not use deprecated Anki commands (byName, getCard etc..) b…
Browse files Browse the repository at this point in the history
…ut their new counterparts"

This reverts commit c07f6db.
  • Loading branch information
mjuhanne committed Dec 4, 2023
1 parent 4030c7a commit a5e0605
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion addon/card_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def find_card_ids(self):
def upsert_model(self):

# Get or create model
model = aqt.mw.col.models.by_name(self.model_name)
model = aqt.mw.col.models.byName(self.model_name)
if model is None:
model = aqt.mw.col.models.new(self.model_name)

Expand Down
4 changes: 2 additions & 2 deletions addon/convert_notes_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def convert(self):
if box.currentIndex() < 1:
continue
deck_name = ct.deck_name
deck = aqt.mw.col.decks.by_name(deck_name)
deck = aqt.mw.col.decks.byName(deck_name)
if deck is None:
util.error_msg(
self,
Expand Down Expand Up @@ -275,7 +275,7 @@ def show_modal(cls, note_ids, parent=None):

for ct in CardType:
ct_model_name = ct.model_name
ct_model = aqt.mw.col.models.by_name(ct_model_name)
ct_model = aqt.mw.col.models.byName(ct_model_name)
if ct_model["id"] == model_id:
util.error_msg(
parent,
Expand Down
34 changes: 17 additions & 17 deletions addon/kanji.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def recalc_user_cards(self, card_type):
card_ids = aqt.mw.col.find_cards(" AND ".join(find_filter))

for card_id in card_ids:
card = aqt.mw.col.get_card(card_id)
card = aqt.mw.col.getCard(card_id)
note = card.note()
character = clean_character_field(note[entry_field])
character_card_ids[character] = card_id
Expand Down Expand Up @@ -310,7 +310,7 @@ def recalc_user_words(self):
if not check_new:
note_ids_not_new.add(note_id)

note = aqt.mw.col.get_note(note_id)
note = aqt.mw.col.getNote(note_id)
field_value = note[entry_field]
words = text_parser.get_cjk_words(field_value, reading=True)

Expand All @@ -332,7 +332,7 @@ def recalc_user_words(self):

def on_note_update(self, note_id, deck_id, is_new=False):
try:
note = aqt.mw.col.get_note(note_id)
note = aqt.mw.col.getNote(note_id)
except Exception:
# TODO: properly check if this is related to card import/export instead of this mess.
return
Expand All @@ -352,14 +352,14 @@ def on_note_update(self, note_id, deck_id, is_new=False):
wr_deck_name = wr["deck"]
wr_field = wr["field"]

wr_model = aqt.mw.col.models.by_name(wr_note)
wr_model = aqt.mw.col.models.byName(wr_note)
if wr_model is None:
continue
if note.mid != wr_model["id"]:
continue

if wr_deck_name != "All":
wr_deck = aqt.mw.col.decks.by_name(wr_deck_name)
wr_deck = aqt.mw.col.decks.byName(wr_deck_name)
if wr_deck is None:
continue
if deck_id != wr_deck["id"]:
Expand Down Expand Up @@ -393,7 +393,7 @@ def on_note_update(self, note_id, deck_id, is_new=False):
if r:
cid = r[0]
try:
card = aqt.mw.col.get_card(cid)
card = aqt.mw.col.getCard(cid)
except Exception: # anki.errors.NotFoundError for newer versions
continue
if card:
Expand Down Expand Up @@ -430,7 +430,7 @@ def refresh_learn_ahead(self):
deck_name = e["deck"]
max_num = e["num"]

deck = aqt.mw.col.decks.by_name(deck_name)
deck = aqt.mw.col.decks.byName(deck_name)
if deck is None:
continue
deck_id = deck["id"]
Expand All @@ -456,21 +456,21 @@ def new_learn_ahead_kanji(self, card_type, deck_id, max_cards):
kanji = [] # to preserve order

for [nid] in nids:
note = aqt.mw.col.get_note(nid)
note = aqt.mw.col.getNote(nid)

for wr in config.get("word_recognized", []):
wr_note = wr["note"]
wr_deck_name = wr["deck"]
wr_field = wr["field"]

wr_model = aqt.mw.col.models.by_name(wr_note)
wr_model = aqt.mw.col.models.byName(wr_note)
if wr_model is None:
continue
if note.mid != wr_model["id"]:
continue

if wr_deck_name != "All":
wr_deck = aqt.mw.col.decks.by_name(wr_deck_name)
wr_deck = aqt.mw.col.decks.byName(wr_deck_name)
if wr_deck is None:
continue
if deck_id != wr_deck["id"]:
Expand Down Expand Up @@ -573,7 +573,7 @@ def refresh_notes_for_character(self, character):
)

for note_id in note_ids:
note = aqt.mw.col.get_note(note_id)
note = aqt.mw.col.getNote(note_id)
self.refresh_note(note, do_flush=True)

def make_card_unsafe(self, card_type, character):
Expand All @@ -582,12 +582,12 @@ def make_card_unsafe(self, card_type, character):
deck_name = card_type.deck_name
model_name = card_type.model_name

deck = aqt.mw.col.decks.by_name(deck_name)
deck = aqt.mw.col.decks.byName(deck_name)
if deck is None:
raise InvalidDeckError(card_type)
deck_id = deck["id"]

model = aqt.mw.col.models.by_name(model_name)
model = aqt.mw.col.models.byName(model_name)

note = anki.notes.Note(aqt.mw.col, model)
note["Character"] = character
Expand All @@ -607,15 +607,15 @@ def make_cards_from_characters(self, card_type, new_characters, checkpoint=None)
deck_name = card_type.deck_name
model_name = card_type.model_name

deck = aqt.mw.col.decks.by_name(deck_name)
deck = aqt.mw.col.decks.byName(deck_name)
if deck is None:
raise InvalidDeckError(card_type)

if checkpoint is not None:
aqt.mw.checkpoint(checkpoint)

deck_id = deck["id"]
model = aqt.mw.col.models.by_name(model_name)
model = aqt.mw.col.models.byName(model_name)

for c in characters:
note = anki.notes.Note(aqt.mw.col, model)
Expand Down Expand Up @@ -706,7 +706,7 @@ def recalc_all(self, callback=None):
num_notes = len(note_ids)

for i, note_id in enumerate(note_ids):
note = aqt.mw.col.get_note(note_id)
note = aqt.mw.col.getNote(note_id)
self.refresh_note(note, do_flush=True)

if callback and ((i + 1) % 25) == 0:
Expand Down Expand Up @@ -830,7 +830,7 @@ def get_kanji_result_data(
ct_user_data = ""
if ct_card_id:
try:
ct_card = aqt.mw.col.get_card(ct_card_id)
ct_card = aqt.mw.col.getCard(ct_card_id)
ct_user_data = ct_card.note()["UserData"]
except:
pass
Expand Down
4 changes: 2 additions & 2 deletions addon/note_type_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def on_note_change(self):

note_name = note_box.currentText()

cards = [f["name"] for f in aqt.mw.col.models.by_name(note_name)["tmpls"]]
cards = [f["name"] for f in aqt.mw.col.models.byName(note_name)["tmpls"]]
card_box.clear()
card_box.addItems(cards)

fields = [f["name"] for f in aqt.mw.col.models.by_name(note_name)["flds"]]
fields = [f["name"] for f in aqt.mw.col.models.byName(note_name)["flds"]]
field_box.clear()
field_box.addItems(fields)

Expand Down
2 changes: 1 addition & 1 deletion addon/stats_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def refresh(self):
marked_known = True
else:
try:
card = aqt.mw.col.get_card(card_id)
card = aqt.mw.col.getCard(card_id)
ivl_days = card_ival(card)
except (
Exception
Expand Down
6 changes: 3 additions & 3 deletions addon/text_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def __init__(self):

self.mecab_extra_args = {}

if anki.utils.is_lin:
if anki.utils.isLin:
self.mecab_bin += "-linux"
elif anki.utils.is_mac:
elif anki.utils.isMac:
self.mecab_bin += "-macos"
elif anki.utils.isWin:
self.mecab_bin += "-windows.exe"
Expand All @@ -49,7 +49,7 @@ def __init__(self):
def start(self):
self.stop()

if anki.utils.is_lin or anki.utils.is_mac:
if anki.utils.isLin or anki.utils.isMac:
os.chmod(self.mecab_bin, 0o755)

if self.mecab_process is None:
Expand Down

0 comments on commit a5e0605

Please sign in to comment.