Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def clickSync(self, sig=None):
if sig is None:
self.Option = "syncFromWordBook"
else:
self.Option = sig
settings = self.getSettingsFromUI(self)
self.settings = settings
if settings[0] == '' or settings[1] == '':
self.tabWidget.setCurrentIndex(1)
showInfo('\n\nPlease enter your Username and Password!')
elif settings[2] == '':
showInfo('\n\nPlease enter Deckname!')
elif askUser('Sync Now?'):
# [0username, 1password, 2deckname, 3uk, 4us, 5phrase, 6phraseExplain]
self.saveSettings(settings[0], settings[1], settings[2], settings[3], settings[4], settings[5], settings[6])
self.tabWidget.setEnabled(False)
self.sync.setText("Wait")
# stop the previous thread first
if self.thread is not None:
self.thread.terminate()
# download the data!
self.thread = YoudaoDownloader(self)
self.thread.start()
while not self.thread.isFinished():
mw.app.processEvents()
self.thread.wait(50)
def _moveUp(self):
selected = self._getSelected()
if not selected:
showInfo('Please select one or several items.')
return
if self.cardListWidget.row(selected[0]) == 0:
return
for item in selected:
row = self.cardListWidget.row(item)
self.cardListWidget.takeItem(row)
self.cardListWidget.insertItem(row - 1, item)
item.setSelected(True)
self.cardListWidget.scrollToItem(item)
def __loadKanjiDict(self):
self.kanjiDict = dict()
if self.profile.kanjiLoadDefaultValuesForNonExistingValues:
# first load the default DB, so the Values from the custom DB
# overwrite/update the default values
self.kanjiDict = self.__loadDefaultKanjiDB()
if self.profile.kanjiCustomProfileEnabled:
try:
customKanjiDict = self.__createCustomDeck()
self.kanjiDict.update(customKanjiDict)
except Exception as e:
showInfo("Kanji Overlay Error: User defined Database could not be loaded." +
" please check your settings. \nusing default Database instead")
self.kanjiDict = self.__loadDefaultKanjiDB()
if (self.__DEBUG__ShowExceptions):
raise (e)
return
else:
self.kanjiDict = self.__loadDefaultKanjiDB()
buttons.append(both_button)
if DEDICATED_INDIVIDUAL_BUTTONS:
buttons.append(define_button)
buttons.append(pronounce_button)
buttons.append(phonetic_transcription_button)
return buttons
addHook("setupEditorButtons", setup_buttons)
if getattr(mw.addonManager, "getConfig", None):
config = mw.addonManager.getConfig(__name__)
if '1 required' in config and 'MERRIAM_WEBSTER_API_KEY' in config['1 required']:
MERRIAM_WEBSTER_API_KEY = config['1 required']['MERRIAM_WEBSTER_API_KEY']
else:
showInfo("AutoDefine: The schema of the configuration has changed in a backwards-incompatible way.\n"
"Please remove and re-download the AutoDefine Add-on.")
if '2 extra' in config:
extra = config['2 extra']
if 'DEDICATED_INDIVIDUAL_BUTTONS' in extra:
DEDICATED_INDIVIDUAL_BUTTONS = extra['DEDICATED_INDIVIDUAL_BUTTONS']
if 'DEFINITION_FIELD' in extra:
DEFINITION_FIELD = extra['DEFINITION_FIELD']
if 'IGNORE_ARCHAIC' in extra:
IGNORE_ARCHAIC = extra['IGNORE_ARCHAIC']
if 'MERRIAM_WEBSTER_MEDICAL_API_KEY' in extra:
MERRIAM_WEBSTER_MEDICAL_API_KEY = extra['MERRIAM_WEBSTER_MEDICAL_API_KEY']
if 'OPEN_IMAGES_IN_BROWSER' in extra:
OPEN_IMAGES_IN_BROWSER = extra['OPEN_IMAGES_IN_BROWSER']
if 'PREFERRED_DICTIONARY' in extra:
PREFERRED_DICTIONARY = extra['PREFERRED_DICTIONARY']
'access_token': self.accessToken,
'contentType': 'article',
'count': 30,
'detailType': 'complete',
'sort': 'newest',
},
headers=self.headers,
)
if response.json()['list']:
return [
{'text': a['resolved_title'], 'data': a}
for a in response.json()['list'].values()
]
showInfo('You have no unread articles remaining.')
return []
def _show_update_result(self, data):
if data['result'] == 'ok':
version = data['version']
if version > VERSION:
showInfo(Template.new_version.format(version=version))
elif version == VERSION:
showInfo(Template.latest_version)
else:
showInfo(Template.abnormal_version)
else:
showInfo(Template.check_failure.format(msg=data['msg']))
if PREFERRED_DICTIONARY == "MEDICAL" and MERRIAM_WEBSTER_MEDICAL_API_KEY == "YOUR_KEY_HERE":
message = "The preferred dictionary was set to MEDICAL, but no API key was provided.\n" \
"Please register for one at www.dictionaryapi.com."
showInfo(message)
webbrowser.open("https://www.dictionaryapi.com/", 0, False)
return
if MERRIAM_WEBSTER_API_KEY == "YOUR_KEY_HERE":
message = "AutoDefine requires use of Merriam-Webster's Collegiate Dictionary with Audio API. " \
"To get functionality working:\n" \
"1. Go to www.dictionaryapi.com and sign up for an account, requesting access to " \
"the Collegiate dictionary. You may also register for the Medical dictionary.\n" \
"2. In Anki, go to Tools > Add-Ons. Select AutoDefine, click \"Config\" on the right-hand side " \
"and replace YOUR_KEY_HERE with your unique API key.\n"
showInfo(message)
webbrowser.open("https://www.dictionaryapi.com/", 0, False)
return
def promot_choose_css():
for local_service in service_manager.local_services:
try:
missed_css = local_service.missed_css.pop()
showInfo(Template.miss_css.format(
dict=local_service.title, css=missed_css))
filepath = QFileDialog.getOpenFileName(
caption=u'Choose css file', filter=u'CSS (*.css)')[0]
if filepath:
shutil.copy(filepath, u'_' + missed_css)
wrap_css(u'_' + missed_css)
local_service.missed_css.clear()
except KeyError as e:
pass
def save_file(self, filepath_in_mdx, savepath=None):
basename = os.path.basename(filepath_in_mdx.replace('\\', os.path.sep))
if savepath is None:
savepath = '_' + basename
try:
bytes_list = self.builder.mdd_lookup(filepath_in_mdx)
if bytes_list and not os.path.exists(savepath):
with open(savepath, 'wb') as f:
f.write(bytes_list[0])
return savepath
except sqlite3.OperationalError as e:
showInfo(str(e))
def get_duolingo_model(mw):
m = mw.col.models.byName(_model_name)
if not m:
showInfo("Duolingo Sync note type not found. Creating.")
m = create_model(mw)
# Add new fields if they don't exist yet
fields_to_add = [field_name for field_name in _field_names if field_name not in mw.col.models.fieldNames(m)]
if fields_to_add:
showInfo("""
<p>The Duolingo Sync plugin has recently been upgraded to include the following attributes: {}</p>
<p>This change will require a full-sync of your card database to your Anki-Web account.</p>
""".format(", ".join(fields_to_add)))
for field_name in fields_to_add:
pass
fm = mw.col.models.newField(_(field_name))
mw.col.models.addField(m, fm)
mw.col.models.save(m)
return m