This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bulkreading.py
59 lines (45 loc) · 1.88 KB
/
bulkreading.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
# Japanese support add-on for Anki 2.1
# Copyright (C) 2021 Ren Tatsumoto. <tatsu at autistici.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Any modifications to this file must keep this entire header intact.
from typing import Sequence
from aqt import mw
from aqt.browser import Browser
from aqt.qt import *
from .helpers import *
from .reading import fill_destination
ACTION_NAME = "Bulk-add furigana"
# Bulk updates
##########################################################################
def bulk_add_furigana(nids: Sequence):
mw.checkpoint(ACTION_NAME)
mw.progress.start()
for note in (note for nid in nids if is_supported_notetype(note := mw.col.getNote(nid))):
if any([fill_destination(note, src_field, dst_field) for src_field, dst_field in iter_fields()]):
note.flush()
mw.progress.finish()
mw.reset()
def setup_menu(browser: Browser):
action = QAction(ACTION_NAME, browser)
qconnect(action.triggered, lambda: bulk_add_furigana(browser.selectedNotes()))
browser.form.menuEdit.addAction(action)
def init():
if ANKI21_VERSION < 45:
from anki.hooks import addHook
addHook("browser.setupMenus", setup_menu)
else:
from aqt import gui_hooks
gui_hooks.browser_menus_did_init.append(setup_menu)