-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfmenubar.py
66 lines (59 loc) · 2.16 KB
/
fmenubar.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
64
65
66
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
class FMenuBar(QMenuBar):
def __init__(self, parent=None):
super(FMenuBar, self).__init__(parent)
self.qactions = {}
self.menuItems = []
self.creatMenus(self.menuItems)
def creatMenus(self, menusettings):
for menu in menusettings['menus']:
setattr(
self,
'%smenu' % menu['trigger'],
self.addMenu(u'%s' % menu['name'])
)
submenu = getattr(self, '%smenu' % menu['trigger'])
for menuaction in menu['actions']:
if 'type' in menuaction and menuaction['type'] == "submenu":
self.createSubAction(menu['trigger'], menuaction)
else:
self.creatAction(submenu, menuaction)
def createSubAction(self, pmenu_name, menu):
childmenu = getattr(self, '%smenu' % pmenu_name)
submenu = childmenu.addMenu(u'%s' % menu['name'])
setattr(
self,
'%smenu' % menu['trigger'],
submenu)
for menuaction in menu['actions']:
self.creatAction(submenu, menuaction)
def creatAction(self, submenu, menuaction):
if 'checkable' in menuaction:
setattr(
self,
'%sAction' % menuaction['trigger'],
QAction(
QIcon(QPixmap(menuaction['icon'])),
u'%s' % menuaction['name'],
self,
checkable=menuaction['checkable']
)
)
else:
setattr(
self,
'%sAction' % menuaction['trigger'],
QAction(
QIcon(QPixmap(menuaction['icon'])),
u'%s' % menuaction['name'],
self,
)
)
action = getattr(self, '%sAction' % menuaction['trigger'])
action.setShortcut(QKeySequence(menuaction['shortcut']))
submenu.addAction(action)
self.qactions.update({menuaction['trigger']: action})