From e28e8f335c35a60f77ac90afbf5f6fda92657335 Mon Sep 17 00:00:00 2001 From: zjosua Date: Wed, 29 Dec 2021 20:35:52 +0100 Subject: [PATCH 1/6] Update to new function names --- src/cloze_overlapper/config.py | 4 ++-- src/cloze_overlapper/libaddon/platform.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cloze_overlapper/config.py b/src/cloze_overlapper/config.py index 37f704a..0a35fae 100644 --- a/src/cloze_overlapper/config.py +++ b/src/cloze_overlapper/config.py @@ -37,7 +37,7 @@ print_function, unicode_literals) from aqt import mw -from anki.utils import stripHTML +from anki.utils import strip_html from .libaddon.anki.configmanager import ConfigManager @@ -48,7 +48,7 @@ def parseNoteSettings(html): """Return note settings. Fall back to defaults if necessary.""" options, settings, opts, sets = None, None, None, None dflt_set, dflt_opt = config["synced"]["dflts"], config["synced"]["dflto"] - field = stripHTML(html) + field = strip_html(html) lines = field.replace(" ", "").split("|") if not lines: diff --git a/src/cloze_overlapper/libaddon/platform.py b/src/cloze_overlapper/libaddon/platform.py index a48aec2..5dc014a 100644 --- a/src/cloze_overlapper/libaddon/platform.py +++ b/src/cloze_overlapper/libaddon/platform.py @@ -41,7 +41,7 @@ from aqt import mw from anki import version as anki_version -from anki.utils import isMac, isWin +from anki.utils import is_mac, is_win __all__ = ["PYTHON3", "ANKI20", "SYS_ENCODING", "MODULE_ADDON", "MODULE_LIBADDON", "DIRECTORY_ADDONS", "JSPY_BRIDGE", @@ -66,9 +66,9 @@ PATH_ADDON = os.path.join(DIRECTORY_ADDONS, MODULE_ADDON) PATH_USERFILES = os.path.join(PATH_ADDON, "user_files") -if isMac: +if is_mac: PLATFORM = "mac" -elif isWin: +elif is_win: PLATFORM = "win" else: PLATFORM = "lin" From a36306554aa1d912a79348f94b5be9dfa7547724 Mon Sep 17 00:00:00 2001 From: zjosua Date: Wed, 29 Dec 2021 20:55:42 +0100 Subject: [PATCH 2/6] Rename Note.model to Note.note_type --- src/cloze_overlapper/editor.py | 8 ++++---- src/cloze_overlapper/overlapper.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cloze_overlapper/editor.py b/src/cloze_overlapper/editor.py index ff25bff..c542742 100644 --- a/src/cloze_overlapper/editor.py +++ b/src/cloze_overlapper/editor.py @@ -187,7 +187,7 @@ def refreshEditor(editor): def onInsertCloze(self, _old): """Handles cloze-wraps when the add-on model is active""" - if not checkModel(self.note.model(), fields=False, notify=False): + if not checkModel(self.note.note_type(), fields=False, notify=False): return _old(self) # find the highest existing cloze highest = 0 @@ -206,7 +206,7 @@ def onInsertCloze(self, _old): @editorSaveThen def onInsertMultipleClozes(self): """Wraps each line in a separate cloze""" - model = self.note.model() + model = self.note.note_type() # check that the model is set up for cloze deletion if not re.search('{{(.*:)*cloze:', model['tmpls'][0]['qfmt']): if self.addMode: @@ -242,7 +242,7 @@ def onInsertMultipleClozes(self): @editorSaveThen def onRemoveClozes(self): """Remove cloze markers and hints from selected text""" - if checkModel(self.note.model(), fields=False, notify=False): + if checkModel(self.note.note_type(), fields=False, notify=False): cloze_re = r"\[\[oc(\d+)::(.*?)(::(.*?))?\]\]" else: cloze_re = r"\{\{c(\d+)::(.*?)(::(.*?))?\}\}" @@ -252,7 +252,7 @@ def onRemoveClozes(self): @editorSaveThen def onOlOptionsButton(self): """Invoke note-specific options dialog""" - if not checkModel(self.note.model()): + if not checkModel(self.note.note_type()): return False options = OlcOptionsNote(self.parentWindow) options.exec_() diff --git a/src/cloze_overlapper/overlapper.py b/src/cloze_overlapper/overlapper.py index f4a522d..bd4d350 100644 --- a/src/cloze_overlapper/overlapper.py +++ b/src/cloze_overlapper/overlapper.py @@ -59,7 +59,7 @@ class ClozeOverlapper(object): def __init__(self, note, markup=False, silent=False, parent=None): self.note = note - self.model = self.note.model() + self.model = self.note.note_type() self.flds = config["synced"]["flds"] self.markup = markup self.silent = silent From f18c4a27c2c1c2824df1e12de1f0bc15a263e0f8 Mon Sep 17 00:00:00 2001 From: zjosua Date: Wed, 29 Dec 2021 21:00:31 +0100 Subject: [PATCH 3/6] Use OlcOptionsNote.exec instead of OlcOptionsNote.exec_ --- src/cloze_overlapper/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloze_overlapper/editor.py b/src/cloze_overlapper/editor.py index c542742..3f7a62c 100644 --- a/src/cloze_overlapper/editor.py +++ b/src/cloze_overlapper/editor.py @@ -255,7 +255,7 @@ def onOlOptionsButton(self): if not checkModel(self.note.note_type()): return False options = OlcOptionsNote(self.parentWindow) - options.exec_() + options.exec() @editorSaveThen From d3c6c576004cb09d5825131059f3e10259e698a2 Mon Sep 17 00:00:00 2001 From: zjosua Date: Wed, 29 Dec 2021 21:07:17 +0100 Subject: [PATCH 4/6] Use int_time instead of deprecated intTime --- src/cloze_overlapper/sched.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cloze_overlapper/sched.py b/src/cloze_overlapper/sched.py index 81dc47a..8b769b8 100644 --- a/src/cloze_overlapper/sched.py +++ b/src/cloze_overlapper/sched.py @@ -46,7 +46,7 @@ from anki.schedv2 import Scheduler as SchedulerV2 SCHEDULERS = (SchedulerV1, SchedulerV2) -from anki.utils import ids2str, intTime +from anki.utils import ids2str, int_time from anki.hooks import wrap from aqt import mw @@ -104,7 +104,7 @@ def myBurySiblings(self, card, _old): self.col.db.execute( "update cards set queue=-2,mod=?,usn=? where id in " + ids2str(toBury), - intTime(), self.col.usn()) + int_time(), self.col.usn()) self.col.log(toBury) elif mw.col.schedVer() == 2: self.buryCards(toBury, manual=False) From 6a6f560d3e7900c4c819f18d90582ef98a80b916 Mon Sep 17 00:00:00 2001 From: zjosua Date: Wed, 29 Dec 2021 21:22:16 +0100 Subject: [PATCH 5/6] Use raw strings for regular expressions Backslashes for anything other than escape sequences are deprecated in literal strings. --- src/cloze_overlapper/editor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cloze_overlapper/editor.py b/src/cloze_overlapper/editor.py index 3f7a62c..cd72a60 100644 --- a/src/cloze_overlapper/editor.py +++ b/src/cloze_overlapper/editor.py @@ -192,7 +192,7 @@ def onInsertCloze(self, _old): # find the highest existing cloze highest = 0 for name, val in self.note.items(): - m = re.findall("\[\[oc(\d+)::", val) + m = re.findall(r"\[\[oc(\d+)::", val) if m: highest = max(highest, sorted([int(x) for x in m])[-1]) # reuse last? @@ -218,10 +218,10 @@ def onInsertMultipleClozes(self): to a cloze type first, via Edit>Change Note Type.""") return if checkModel(model, fields=False, notify=False): - cloze_re = "\[\[oc(\d+)::" + cloze_re = r"\[\[oc(\d+)::" wrap_pre, wrap_post = "[[oc", "]]" else: - cloze_re = "\{\{c(\d+)::" + cloze_re = r"\{\{c(\d+)::" wrap_pre, wrap_post = "{{c", "}}" # find the highest existing cloze highest = 0 From eb2d5040d2bfd444c2947aeb7dcce6c3047408d0 Mon Sep 17 00:00:00 2001 From: zjosua Date: Thu, 30 Dec 2021 07:48:53 +0100 Subject: [PATCH 6/6] Use by_name instad of deprecated byName --- src/cloze_overlapper/template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cloze_overlapper/template.py b/src/cloze_overlapper/template.py index 321a6bd..900c8a4 100644 --- a/src/cloze_overlapper/template.py +++ b/src/cloze_overlapper/template.py @@ -407,7 +407,7 @@ def addModel(col): def updateTemplate(col): """Update add-on card templates""" print("Updating %s card template".format(OLC_MODEL)) - model = col.models.byName(OLC_MODEL) + model = col.models.by_name(OLC_MODEL) template = model['tmpls'][0] template['qfmt'] = card_front template['afmt'] = card_back @@ -417,6 +417,6 @@ def updateTemplate(col): def initializeModels(): - model = mw.col.models.byName(OLC_MODEL) + model = mw.col.models.by_name(OLC_MODEL) if not model: model = addModel(mw.col)