-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (27 loc) · 1.32 KB
/
main.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
# Copyright: Ren Tatsumoto <tatsu at autistici.org>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from typing import Optional
from anki.cards import Card
from anki.notes import Note
from anki.utils import html_to_text_line
from aqt import gui_hooks
from aqt.qt import *
from .config import config
def get_fields_text(note: Note) -> str:
return "\n".join(note[field] for field in config.fields if field in note)
def copy_to_clipboard(text: str) -> None:
return QApplication.clipboard().setText(text, mode=QClipboard.Mode.Clipboard)
def copy_content(note: Note) -> None:
if config.activated and (to_copy := get_fields_text(note)):
copy_to_clipboard(html_to_text_line(to_copy))
def on_change(note: Note, state: str) -> None:
if config[state] is False:
return
return copy_content(note)
def setup() -> None:
gui_hooks.reviewer_did_show_question.append(lambda card: on_change(card.note(), "on_show_question"))
gui_hooks.reviewer_did_show_answer.append(lambda card: on_change(card.note(), "on_show_answer"))
gui_hooks.browser_did_change_row.append(
lambda browser: (browser.current_card and on_change(browser.current_card.note(), "on_select_note"))
)
gui_hooks.editor_did_load_note.append(lambda editor: on_change(editor.note, "on_editor_load_note"))