forked from HakanSeven12/Modern-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateMenu.py
126 lines (110 loc) · 5.33 KB
/
CreateMenu.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# ***********************************************************************
# * *
# * Copyright (c) 2019 Hakan Seven <hakanseven12@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify*
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307*
# * USA *
# * *
# ***********************************************************************
"""
from PySide2 import QtCore, QtGui, QtWidgets
mv = FreeCADGui.getMainWindow()
modernMenu = mv.findChild(QtWidgets.QWidget, "Modern Menu")
"""
import FreeCADGui
from menu.ModernMenu import QModernMenu
from PySide2 import QtCore, QtGui, QtWidgets
import Preferences
mw = FreeCADGui.getMainWindow()
class MenuDock(QtWidgets.QDockWidget):
def __init__(self):
super(MenuDock, self).__init__(mw, QtCore.Qt.FramelessWindowHint)
self.setObjectName("Modern Menu")
self.setWindowTitle("Modern Menu")
self.setTitleBarWidget(QtWidgets.QWidget())
self.setWidget(ModernMenu())
class ModernMenu(QModernMenu):
actions = {}
Enabled = {}
def __init__(self):
icon = QtGui.QIcon(":/icons/freecad")
super(ModernMenu, self).__init__(icon, 'FreeCAD')
self._tabBar.currentChanged.connect(self.selectWorkbench)
self.createModernMenu()
self.createFileMenu()
self.show()
def createModernMenu(self):
EnabledList = Preferences.enabled
WBList = FreeCADGui.listWorkbenches()
for Enabled in EnabledList:
if Enabled == 'NoneWorkbench': continue
Icon = self.getWBIcon(WBList[Enabled].Icon)
Name = WBList[Enabled].MenuText
self.actions[Name] = Enabled
self.Enabled[Name] = False
self.addTab(Icon, Name)
def createFileMenu(self):
fileMenu = ['File', 'Macro']
for toolbar in fileMenu:
TB = mw.findChildren(QtWidgets.QToolBar, toolbar)
for button in TB[0].findChildren(QtWidgets.QToolButton):
if button.text() == '': continue
self._QFileMenu.addButton(
icon=button.icon(), title=button.text(), handler=button.defaultAction().triggered,
shortcut=button.shortcut(), statusTip=button.statusTip())
self._QFileMenu.addButton(
title='Modern Settings',handler=Preferences.showPreferences)
def selectWorkbench(self):
Defaults = ['File', 'Workbench', 'Macro', 'View', 'Structure']
index = self._tabBar.currentIndex()
tabName = self._tabBar.tabText(index)
if tabName == 'FreeCAD': return
FreeCADGui.activateWorkbench(self.actions[tabName])
workbench = FreeCADGui.activeWorkbench()
for tbb in mw.findChildren(QtWidgets.QToolBar):
tbb.hide()
if self.Enabled[tabName]: return
tab = self._tabs[index]
for toolbar in workbench.listToolbars():
if toolbar in Defaults: continue
section = tab.addSection(toolbar)
TB = mw.findChildren(QtWidgets.QToolBar, toolbar)
for button in TB[0].findChildren(QtWidgets.QToolButton):
if button.text() == '': continue
section.addButton(
full=False, icon=button.icon(), title=button.text()+' ', handler=button.defaultAction().triggered,
shortcut=button.shortcut(), statusTip=button.statusTip(), menu=button.menu())
self.Enabled[tabName] = True
def getWBIcon(self, icon):
"""
Return workbench icon
"""
if str(icon.find("XPM")) != "-1":
Icon = []
for a in ((((icon
.split('{', 1)[1])
.rsplit('}', 1)[0])
.strip())
.split("\n")):
Icon.append((a
.split('"', 1)[1])
.rsplit('"', 1)[0])
Icon = QtGui.QIcon(QtGui.QPixmap(icon))
else:
Icon = QtGui.QIcon(QtGui.QPixmap(icon))
if Icon.isNull():
Icon = QtGui.QIcon(":/icons/freecad")
return Icon