forked from Asu4ni/Templates-Import-Export-for-Anki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
63 lines (45 loc) · 1.6 KB
/
gui.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
61
62
63
from PyQt5 import QtCore
from aqt import mw as window, utils, qt, addons
import aqt
from . import templates
import os
def _edit_config():
addons.ConfigEditor(window, __name__, window.addonManager.getConfig(__name__))
def _help():
file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "README.md")
if os.path.exists(file):
with open(file, "r", encoding="utf-8") as f:
doc = f.read()
box = aqt.QMessageBox(window)
box.setTextFormat(QtCore.Qt.MarkdownText)
box.setText(doc)
box.exec()
else:
show_error("Help document missing!!")
def init():
# init error dialog
global err
err = aqt.QErrorMessage(window)
# menu items
menu = aqt.QMenu(window.form.menuTools)
menu.setTitle("Import / Export templates")
window.form.menuTools.addAction(menu.menuAction())
actions = [
(qt.QAction("Export to ...", menu), templates.export_tmpls),
(qt.QAction("Import from ...", menu), templates.import_tmpls),
(qt.QAction("Configure", menu), _edit_config),
(qt.QAction("Help / Guide", menu), _help)
]
for action, func in actions:
utils.qconnect(action.triggered, func)
menu.addAction(action)
# editor setup for _edit_config
window.mgr = window.addonManager
def show_error(msg: str, err_type: str = "all"):
err.showMessage(msg, err_type)
def get_dir():
folder = aqt.QFileDialog.getExistingDirectory(window, "Select a Directory")
return folder if len(folder) != 0 else None
def notify(msg: str, time: int = 5000):
utils.tooltip(msg, time)
err = None