Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.noteTypeComboBox.addItem('')
self.noteTypeComboBox.addItems(modelNames)
self.noteTypeComboBox.currentIndexChanged.connect(
self._updateFieldLists
)
newButton = QPushButton('New')
newButton.clicked.connect(self._clearQuickKeysTab)
setButton = QPushButton('Set')
setButton.clicked.connect(self._setQuickKey)
unsetButton = QPushButton('Unset')
unsetButton.clicked.connect(self._unsetQuickKey)
tagsLabel = QLabel('Tags')
self.tagsEditBox = TagEdit(mw)
self.tagsEditBox.setCol(mw.col)
tagsLayout = QHBoxLayout()
tagsLayout.addWidget(tagsLabel)
tagsLayout.addWidget(self.tagsEditBox)
buttonLayout = QHBoxLayout()
buttonLayout.addStretch()
buttonLayout.addWidget(newButton)
buttonLayout.addWidget(setButton)
buttonLayout.addWidget(unsetButton)
layout = QVBoxLayout()
layout.addWidget(self.quickKeysComboBox)
layout.addLayout(destDeckLayout)
layout.addLayout(noteTypeLayout)
layout.addLayout(textFieldLayout)
layout.addLayout(sourceFieldLayout)
def syncYoudao(self, result):
name = self.sync_to_lineEdit.text()
deleted = result['deleted']
terms = result['terms']
cardID = []
info_add = '0'
info_delete = '0'
if terms[0] is not None:
deck = mw.col.decks.get(mw.col.decks.id(name))
model = addCustomModel(name, mw.col)
# assign custom model to new deck
mw.col.decks.select(deck["id"])
mw.col.decks.get(deck)["mid"] = model["id"]
mw.col.decks.save(deck)
# assign new deck to custom model
mw.col.models.setCurrent(model)
mw.col.models.current()["did"] = deck["id"]
mw.col.models.save(model)
for term in terms:
note = mw.col.newNote()
note["Front"] = term["term"]
if term['definition'] is None:
term["definition"] = 'NULL'
def deleteNotes(existingNoteIDs):
"""
Deletes notes in Anki that aren't in the passed list of `existingNoteIDs`
"""
notesToDelete = set()
numDeleted = 0
allDecks = mw.col.decks.allNames()
for deck in allDecks:
for cid in mw.col.findNotes("deck:" + deck):
# cid is of type long but existingNoteIDs are string
if str(cid) not in existingNoteIDs:
notesToDelete.add(cid)
numDeleted += 1
mw.col.remNotes(notesToDelete)
return numDeleted
def _getTitle(self, note, did, title, settings):
title, accepted = getText(
'Enter title', title='Extract Text', default=title
)
if accepted:
setField(note, settings['titleField'], title)
note.model()['did'] = did
mw.col.addNote(note)
return accepted
def maobi_hook(html: str, card: Card, context: str) -> str:
# Only show the quiz on the front side, else it can lead to rendering issues
if context not in {"reviewQuestion", "clayoutQuestion", "previewQuestion"}:
return html
# This reads from the config.json in the addon folder
maobi_config = MaobiConfig.load()
# Search the active deck configuration
deck_name = mw.col.decks.current()["name"]
template_name = card.template()["name"]
config = maobi_config.search_active_deck_config(deck_name, template_name)
# Return if we did not find it
if not config:
debug(maobi_config, f"Config not found")
return html
if not config.enabled:
debug(maobi_config, f"Config disabled")
return html
# Get the character to write and the corresponding character data
try:
characters, tones = _get_characters(card, config)
characters_data = [_load_character_data(c) for c in characters]
def test_names():
"""Go through the collection and show possible new names
Search the cards for sounds or images with file names that look
like MD5 hashes, rename the files and change the notes.
"""
test_string = u''
nids = mw.col.db.list("select id from notes")
for nid in progress(nids, "Dehashilating", "This is all wrong!"):
n = mw.col.getNote(nid)
for (name, value) in n.items():
rs = re.search(hash_name_pat, value)
if None == rs:
continue
test_string += u'{0}.{1} → {2}\n'.format(
rs.group(1), rs.group(2),
new_name(rs.group(1), rs.group(2), n))
showText(test_string)
def unnormalize_files():
"""
Fix collection that have issue #500.
Go through the collection and the media files, rename all
"""
mdir = mw.col.media.dir()
try:
# A quirk of certain Pythons is that some os commands give
# different results when you put in a unicode object rather
# than a str.
mdir = unicode(mdir, sys.getfilesystemencoding())
except TypeError:
# Already unicode.
pass
media_in_col = mw.col.media.allMedia()
# Filter the files on disk. Drop all files that do not contain
# combining characters. Those should be no problem. (The Unicode
# web page describes a "quick test", we do an even quicker test.)
problem_files = []
try:
for f in progress(os.listdir(mdir), _(u"Checking files on disk."),
_(u"Stop that!")):
def add_notes(vocab_words: List[chinesevocablist.VocabWord], deck_name: str, tags: List[str]):
# get dict that describes deck
deck = [d for d in mw.col.decks.decks.values() if d['name'] == deck_name][0]
# By using the same ID and name as the existing deck, the notes are added to the existing deck, rather than going
# into a new deck or the default deck.
out_deck = chineseflashcards.ChineseDeck(deck['id'], deck_name)
for vocab_word in vocab_words:
note = out_deck.add_vocab_list_word(vocab_word, tags=tags)
# Temporary hack: suspend everything except the "Simplified" card.
# This should ideally be based on a GUI selector.
for i, c in enumerate(note.cards):
if i == 1:
continue
c.suspend = True
# Write the data to the collection
out_deck.write_to_collection_from_addon()
def fix_review_times():
"""
Fix negative review times
Call the methods described in the google code issue discussion to
fix spurious negative review times in Anki2/AnkiDroid2.
"""
mw.col.db.execute("update revlog set time = 60000 where time < 0")
mw.col.modSchema()
mw.col.setMod()
tooltip(_('Time fix done.'))