本文整理汇总了Python中aqt.utils.askUser方法的典型用法代码示例。如果您正苦于以下问题:Python utils.askUser方法的具体用法?Python utils.askUser怎么用?Python utils.askUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aqt.utils
的用法示例。
在下文中一共展示了utils.askUser方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onOrganizeTask
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def onOrganizeTask():
"""Main function. Invoked on clicking menu entry"""
conf = mw.col.conf
today = mw.col.sched.today # today in days since col creation time
if WARN_ON_MULTIPLE_EXECUTIONS:
# check if we've already performed tasks today:
last = conf.get("deckOrgLast", None)
if last and last == today:
q = ("You have already performed this task today."
" Are you sure you want to proceed?")
ret = askUser(q)
if not ret:
return False
performDeckOrgActions()
conf["deckOrgLast"] = today
mw.col.setMod()
# Menu / Hooks
示例2: bulk_fill_all
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def bulk_fill_all():
prompt = (
'<div>This will update <i>all</i> non-audio fields in the current deck.</div>'
'<div>Please back up your Anki collection first!</div>'
'<div><b>Continue?</b></div>'
)
if not askUser(prompt):
return
note_ids = Finder(mw.col).findNotes('deck:current')
mw.progress.start(immediate=True, min=0, max=len(note_ids))
n_updated = 0
n_failed = 0 # FIXME
exclude = config.get_fields(['sound', 'mandarinSound', 'cantoneseSound'])
for i, nid in enumerate(note_ids):
note = mw.col.getNote(nid)
fields = [
f
for f in mw.col.models.fieldNames(note.model())
if f not in exclude
]
n_updated += update_fields(note, 'Hanzi', fields)
msg = PROGRESS_TEMPLATE % {
'hanzi': get_hanzi(dict(note)),
'n_processed': i,
'n_updated': n_updated,
'n_failed': n_failed,
}
mw.progress.update(label=msg, value=i)
note.flush()
mw.progress.finish()
showInfo(
'<b>Bulk filling complete</b><br>'
'<b>Processed:</b> {}<br>'.format(len(note_ids))
)
示例3: bulk_fill_silhouette
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def bulk_fill_silhouette():
prompt = PROMPT_TEMPLATE.format(
field_names='<i>silhouette</i>', extra_info=''
)
if not askUser(prompt):
return
d_has_fields = 0
n_updated = 0
note_ids = Finder(mw.col).findNotes('deck:current')
mw.progress.start(immediate=True, min=0, max=len(note_ids))
for i, nid in enumerate(note_ids):
note = mw.col.getNote(nid)
copy = dict(note)
if has_any_field(config['fields']['silhouette'], copy):
d_has_fields += 1
msg = '''
<b>Processing:</b> %(hanzi)s<br>
<b>Updated:</b> %(filled)d''' % {
'hanzi': get_hanzi(copy),
'filled': n_updated,
}
mw.progress.update(label=msg, value=i)
hanzi = get_first(config['fields']['hanzi'], copy)
fill_silhouette(hanzi, copy)
n_updated = save_note(note, copy)
msg = '''
<b>Update complete!</b> %(hanzi)s<br>
<b>Updated:</b> %(filled)d notes''' % {
'hanzi': get_hanzi(copy),
'filled': n_updated,
}
mw.progress.finish()
showInfo(msg)
示例4: deleteColumn
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def deleteColumn(self, colpos):
if not askUser(_("""Are you sure you wish to delete this column ?""")):
return
colpos = int(colpos)
print("They are sure.")
columns = getUserOption("columns")
column = columns[colpos]
column["present"] = False
writeConfig()
self.show()
示例5: _authenticate
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def _authenticate(self):
response = post(
'https://getpocket.com/v3/oauth/request',
json={
'consumer_key': self.consumerKey,
'redirect_uri': self.redirectURI,
},
headers=self.headers,
)
requestToken = response.json()['code']
authUrl = 'https://getpocket.com/auth/authorize?'
authParams = {
'request_token': requestToken,
'redirect_uri': self.redirectURI,
}
openLink(authUrl + urlencode(authParams))
if not askUser('I have authenticated with Pocket.'):
return None
response = post(
'https://getpocket.com/v3/oauth/authorize',
json={'consumer_key': self.consumerKey, 'code': requestToken},
headers=self.headers,
)
try:
return response.json()['access_token']
except JSONDecodeError:
return None
示例6: onFieldToTags
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def onFieldToTags(self, _):
"""Main function"""
nids = self.selectedNotes()
count = len(nids)
if not nids:
tooltip("Please select some cards.")
return
fields = sorted(find.fieldNames(self.col, downcase=False))
if not fields:
tooltip("No fields found."
"Something might be wrong with your collection")
return
field = getField(self, fields)
if not field:
return
q = ("Are you sure you want to convert the <b>'{}'</b> field "
"to tags in <b>{}</b> selected notes?".format(field, count))
ret = askUser(q, parent=self, title="Please confirm your choice")
if not ret:
return
self.mw.checkpoint("Find and Replace")
self.mw.progress.start()
self.model.beginReset()
edited = self.fieldToTags(nids, field)
self.model.endReset()
self.mw.progress.finish()
tooltip("{} out of {} notes updated.".format(edited, count))
# Hooks
示例7: clickSync
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
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)
# error with fetching data
if self.thread.error is 1:
showInfo("authenticate failed!")
elif self.thread.error is 2:
showInfo("Can not fetch data!")
else:
result = json.loads(self.thread.results)
self.debug.appendPlainText('414: Loaded downloader results')
# save data to Anki Card
self.syncYoudao(result, settings[2])
self.setupHistoryList()
self.thread.terminate()
self.thread = None
self.sync.setText('Sync')
self.tabWidget.setEnabled(True)
示例8: bulk_fill_transcript
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def bulk_fill_transcript():
prompt = PROMPT_TEMPLATE.format(
field_names='<i>transcription</i> and <i>ruby</i>', extra_info=''
)
fields = config.get_fields(
['pinyin', 'pinyinTaiwan', 'cantonese', 'bopomofo']
)
if not askUser(prompt):
return
d_has_fields = 0
d_added_pinyin = 0
n_updated = 0
note_ids = Finder(mw.col).findNotes('deck:current')
mw.progress.start(immediate=True, min=0, max=len(note_ids))
for i, nid in enumerate(note_ids):
note = mw.col.getNote(nid)
copy = dict(note)
if has_any_field(copy, fields) and has_any_field(
config['fields']['hanzi'], copy
):
d_has_fields += 1
msg = '''
<b>Processing:</b> %(hanzi)s<br>
<b>Filled pinyin:</b> %(pinyin)d notes<br>
<b>Updated: </b>%(updated)d fields''' % {
'hanzi': get_hanzi(copy),
'pinyin': d_added_pinyin,
'updated': n_updated,
}
mw.progress.update(label=msg, value=i)
hanzi = get_first(config['fields']['hanzi'], copy)
results = fill_transcript(hanzi, copy)
if results > 0:
d_added_pinyin += 1
fill_all_rubies(hanzi, copy)
save_note(note, copy)
mw.progress.finish()
msg = '''
<b>Processed:</b> %(hanzi)s<br>
<b>Filled pinyin:</b> %(pinyin)d notes<br>
<b>Updated: </b>%(updated)d fields''' % {
'hanzi': get_hanzi(copy),
'pinyin': d_added_pinyin,
'updated': n_updated,
}
showInfo(msg)
示例9: bulk_fill_classifiers
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def bulk_fill_classifiers():
prompt = PROMPT_TEMPLATE.format(
field_names='<i>classifier</i>', extra_info=''
)
fields = config.get_fields(['classifier'])
if not askUser(prompt):
return
n_processed = 0
n_updated = 0
n_failed = 0
note_ids = Finder(mw.col).findNotes('deck:current')
mw.progress.start(immediate=True, min=0, max=len(note_ids))
for i, nid in enumerate(note_ids):
note = mw.col.getNote(nid)
copy = dict(note)
hanzi = get_hanzi(copy)
if has_any_field(copy, fields) and hanzi:
n_processed += 1
if all_fields_empty(copy, fields):
if fill_classifier(hanzi, copy):
n_updated += 1
else:
n_failed += 1
msg = PROGRESS_TEMPLATE % {
'hanzi': hanzi,
'n_processed': n_processed,
'n_updated': n_updated,
'n_failed': n_failed,
}
mw.progress.update(label=msg, value=i)
save_note(note, copy)
mw.progress.finish()
showInfo(
END_TEMPLATE
% {'has_fields': n_processed, 'filled': n_updated, 'failed': n_failed}
)
示例10: bulk_fill_hanzi
# 需要导入模块: from aqt import utils [as 别名]
# 或者: from aqt.utils import askUser [as 别名]
def bulk_fill_hanzi():
prompt = PROMPT_TEMPLATE.format(field_names='<i>hanzi</i>', extra_info='')
fields = config.get_fields(['traditional', 'simplified'])
if not askUser(prompt):
return
d_has_fields = 0
n_updated = 0
note_ids = Finder(mw.col).findNotes('deck:current')
mw.progress.start(immediate=True, min=0, max=len(note_ids))
for i, nid in enumerate(note_ids):
note = mw.col.getNote(nid)
copy = dict(note)
if has_any_field(copy, fields) and has_any_field(
config['fields']['hanzi'], copy
):
d_has_fields += 1
msg = '''
<b>Processing:</b> %(hanzi)s<br>
<b>Updated:</b> %(filled)d''' % {
'hanzi': get_hanzi(copy),
'filled': n_updated,
}
mw.progress.update(label=msg, value=i)
hanzi = get_first(config['fields']['hanzi'], copy)
fill_simp(hanzi, copy)
fill_trad(hanzi, copy)
fill_color(hanzi, copy)
n_updated = save_note(note, copy)
msg = '''
<b>Update complete!</b> %(hanzi)s<br>
<b>Updated:</b> %(filled)d notes''' % {
'hanzi': get_hanzi(copy),
'filled': n_updated,
}
mw.progress.finish()
showInfo(msg)