-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
48 lines (33 loc) · 1.17 KB
/
utils.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
import shutil
from PyQt5.QtWidgets import QAction
from aqt import mw, QKeySequence, QMenu
from .settings import settings
def clean_up_user_files():
shutil.rmtree(settings.user_files_folder, ignore_errors=True)
def addMenu(name):
if not hasattr(mw, 'customMenus'):
mw.customMenus = {}
if name not in mw.customMenus:
menu = QMenu('&' + name, mw)
mw.customMenus[name] = menu
mw.form.menubar.insertMenu(mw.form.menuTools.menuAction(),
mw.customMenus[name])
def addMenuSeparator(menuName):
mw.customMenus[menuName].addSeparator()
def addMenuItem(menuName, text, function, keys=None):
action = QAction(text, mw)
if keys:
action.setShortcut(QKeySequence(keys))
action.triggered.connect(function)
if menuName == 'File':
mw.form.menuCol.addAction(action)
elif menuName == 'Edit':
mw.form.menuEdit.addAction(action)
elif menuName == 'Tools':
mw.form.menuTools.addAction(action)
elif menuName == 'Help':
mw.form.menuHelp.addAction(action)
else:
addMenu(menuName)
mw.customMenus[menuName].addAction(action)
return action