-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPieMenuGui.py
More file actions
124 lines (102 loc) · 3.39 KB
/
PieMenuGui.py
File metadata and controls
124 lines (102 loc) · 3.39 KB
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
# Pie menu for FreeCAD
# Copyright (C) 2015, 2016 (as part of TabBar) triplus @ FreeCAD
# Copyright (C) 2017, 2018, 2019 (as part of CommandPanel) triplus @ FreeCAD
# Copyright (C) 2020 triplus @ FreeCAD
#
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Pie menu for FreeCAD - Gui."""
from PySide import QtGui
from PySide import QtCore
import FreeCAD as App
import FreeCADGui as Gui
import PieMenuCommon as pmc
import PieMenuPreferences as pmp
p = pmc.p
mw = Gui.getMainWindow()
def onWorkbench():
"""Temp"""
pass
def accessoriesMenu():
"""Add pie menu preferences to accessories menu."""
pref = QtGui.QAction(mw)
pref.setText("Pie menu")
pref.setObjectName("PieMenu")
pref.triggered.connect(onPreferences)
try:
import AccessoriesMenu
AccessoriesMenu.addItem("PieMenu")
except ImportError:
a = mw.findChild(QtGui.QAction, "AccessoriesMenu")
if a:
a.menu().addAction(pref)
else:
mb = mw.menuBar()
action = QtGui.QAction(mw)
action.setObjectName("AccessoriesMenu")
action.setIconText("Accessories")
menu = QtGui.QMenu()
action.setMenu(menu)
menu.addAction(pref)
def addMenu():
"""Add accessories menu to the menu bar."""
mb.addAction(action)
action.setVisible(True)
addMenu()
mw.workbenchActivated.connect(addMenu)
def onPreferences():
"""Open the preferences dialog."""
pmp.createWidgets()
dialog = pmp.dialog()
dialog.show()
def onStart():
"""Start pie menu."""
start = False
try:
mw.mainWindowClosed
mw.workbenchActivated
start = True
except AttributeError:
pass
if start:
t.stop()
t.deleteLater()
onWorkbench()
accessoriesMenu()
mw.mainWindowClosed.connect(onClose)
mw.workbenchActivated.connect(onWorkbench)
# a = QtGui.QAction(mw)
# mw.addAction(a)
# a.setText("Invoke pie menu")
# a.setObjectName("InvokePieMenu")
# a.setShortcut(QtGui.QKeySequence("Q"))
# a.triggered.connect(onInvoke)
def onClose():
"""Remove system presets and groups without index on FreeCAD close."""
p.RemGroup("System")
for wb in Gui.listWorkbenches():
base = p.GetGroup("User").GetGroup(wb)
if not pmc.splitIndex(base):
p.GetGroup("User").RemGroup(wb)
def onPreStart():
"""Improve start reliability and maintain FreeCAD 0.16 support."""
if App.Version()[1] < "17":
onStart()
else:
if mw.property("eventLoop"):
onStart()
t = QtCore.QTimer()
t.timeout.connect(onPreStart)
t.start(500)