Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to new function names #79

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cloze_overlapper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/cloze_overlapper/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ 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
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?
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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+)::(.*?)(::(.*?))?\}\}"
Expand All @@ -252,10 +252,10 @@ 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_()
options.exec()


@editorSaveThen
Expand Down
6 changes: 3 additions & 3 deletions src/cloze_overlapper/libaddon/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/cloze_overlapper/overlapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cloze_overlapper/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/cloze_overlapper/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)