-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bulk_Copy_Field.py
60 lines (47 loc) · 1.81 KB
/
Bulk_Copy_Field.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
# Copyright: Chris Langewisch <[email protected]>
# License: GNU GPL, version 3 or later; https://www.gnu.org/copyleft/gpl.html
# Based on japanese.reading by Damien Elmes <[email protected]>
# Bulk copy data in one field to another.
##########################################################################
# each field name must be exact!
srcField = 'Front'
##########################################################################
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from anki.hooks import addHook
from aqt import mw, utils
from Dictionaries import DictionaryParser,Google
from GoogleTTS import GetExamples
import traceback
import warnings
def bulkCopy(nids):
mw.progress.start(immediate=True)
for nid in nids:
note = mw.col.getNote(nid)
word = note[srcField]
try :
with warnings.catch_warnings():
warnings.simplefilter("error")
mw.progress.update(label=word)
GetExamples(word)
g = Google()
g.write(word)
dp = DictionaryParser(word)
dp.format()
except :
# mw.progress.clear()
# utils.showInfo("Exception " + word)
txt = "<h3>" + word + "</h3>"
txt += "<div style='white-space: pre-wrap'>" + traceback.format_exc() + "</div>"
utils.showText(txt, type="html")
pass
mw.progress.finish()
def setupMenu(browser):
a = QAction("Bulk-Copy Field Data", browser)
browser.connect(a, SIGNAL("triggered()"), lambda e=browser: onBulkCopy(e))
browser.form.menuEdit.addSeparator()
browser.form.menuEdit.addAction(a)
def onBulkCopy(browser):
bulkCopy(browser.selectedNotes())
addHook("browser.setupMenus", setupMenu)