-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.py
37 lines (27 loc) · 904 Bytes
/
action.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
import os
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
here = os.path.dirname(os.path.abspath(__file__))
def new_action(parent, text, slot=None, shortcut=None, icon=None):
a = QAction(text, parent)
if icon is not None:
icon_path = os.path.join(here, "icons", icon)
a.setIconText(text.replace(" ", "\n"))
a.setIcon(QIcon(icon_path))
if shortcut is not None:
if isinstance(shortcut, (list, tuple)):
a.setShortcuts(shortcut)
else:
a.setShortcut(shortcut)
if slot is not None:
a.triggered.connect(slot)
return a
def add_actions(widget: QWidget, actions):
for action in actions:
if action is None:
widget.addSeparator()
elif isinstance(action, QMenu):
widget.addMenu(action)
else:
widget.addAction(action)