-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGlassGui.py
224 lines (188 loc) · 5.76 KB
/
GlassGui.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Glass module for FreeCAD
# Copyright (C) 2018, 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
"""Glass module for FreeCAD - Gui."""
import FreeCADGui as Gui
import FreeCAD
from PySide import QtGui
from PySide import QtCore
mode = 0
wid = QtGui.QWidget()
mw = Gui.getMainWindow()
p = FreeCAD.ParamGet("User parameter:BaseApp/Glass")
try:
mw.setDockOptions(mw.dockOptions() | mw.GroupedDragging)
except AttributeError:
pass
def firstRun():
"""Setup defaults on the first run."""
pTree = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/DockWindows/TreeView")
pTree.SetBool("Enabled", True)
pStyle = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/MainWindow")
pStyle.SetString("StyleSheet", "Dark-blue.qss")
pView = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
pView.SetUnsigned("BackgroundColor2", 1852731135)
pView.SetUnsigned("BackgroundColor3", 2829625599)
pView.SetUnsigned("BackgroundColor4", 1852731135)
def findDock():
"""Find combo view widget."""
global dock
dock = mw.findChild(QtGui.QDockWidget, "Tree view")
def createActions():
"""Create actions."""
a1 = QtGui.QAction(mw)
a1.setParent(mw)
a1.setText("Glass toggle dock mode")
a1.setObjectName("GlassToggleMode")
a1.setShortcut(QtGui.QKeySequence("Q, 1"))
a1.triggered.connect(setMode)
mw.addAction(a1)
a2 = QtGui.QAction(mw)
a2.setParent(mw)
a2.setText("Glass toggle dock visibility")
a2.setObjectName("GlassToggleVisibility")
a2.setShortcut(QtGui.QKeySequence("Q, 2"))
a2.triggered.connect(setVisibility)
mw.addAction(a2)
def applyGlass(boolean, widget):
"""Apply or remove glass."""
try:
if boolean:
widget.setWindowFlags(QtCore.Qt.FramelessWindowHint)
else:
widget.setWindowFlags(dock.windowFlags() & ~QtCore.
Qt.
FramelessWindowHint)
except:
pass
try:
widget.setAttribute(QtCore.Qt.WA_NoSystemBackground, boolean)
except:
pass
try:
widget.setAttribute(QtCore.Qt.WA_TranslucentBackground, boolean)
except:
pass
try:
if boolean:
widget.setStyleSheet("background:transparent; border:none; color:white;")
else:
widget.setStyleSheet("")
except:
pass
try:
widget.setAutoFillBackground(boolean)
except:
pass
try:
if boolean:
widget.setVerticalScrollBarPolicy((QtCore.Qt.ScrollBarAlwaysOff))
else:
widget.setVerticalScrollBarPolicy((QtCore.Qt.ScrollBarAsNeeded))
except:
pass
try:
if boolean:
widget.setHorizontalScrollBarPolicy((QtCore.Qt.ScrollBarAlwaysOff))
else:
widget.setHorizontalScrollBarPolicy((QtCore.Qt.ScrollBarAsNeeded))
except:
pass
try:
widget.setDocumentMode(boolean)
except:
pass
try:
widget.tabBar().setDrawBase(False)
except:
pass
try:
if boolean:
widget.header().hide()
else:
widget.header().show()
except:
pass
def widgetList(boolean):
"""List of child widgets."""
children = []
children.append(dock)
child = True
while child:
child = False
for i in children:
if i.children():
for c in i.children():
if c not in children:
children.append(c)
child = True
for child in children:
applyGlass(boolean, child)
def setMode():
"""Set dock or overlay widget mode."""
global mode
mdi = mw.findChild(QtGui.QMdiArea)
if mode == 0:
dock.setParent(mdi)
dock.setTitleBarWidget(wid)
wid.hide()
dock.show()
widgetList(True)
mode = 1
else:
dock.setParent(mw)
dock.setTitleBarWidget(None)
mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock)
dock.show()
widgetList(False)
mode = 0
onResize()
def setVisibility():
"""Toggle visibility."""
dock.toggleViewAction().trigger()
def onResize():
"""Resize dock."""
mdi = mw.findChild(QtGui.QMdiArea)
if mode == 1:
x = 0
y = 0
w = mdi.geometry().width() / 100 * 20
h = (mdi.geometry().height() -
mdi.findChild(QtGui.QTabBar).geometry().height())
dock.setGeometry(x, y, w, h)
if str(Gui.activeView()) == "View3DInventor":
dock.show()
else:
dock.hide()
def onStart():
"""Start the glass module."""
if mw.property("eventLoop"):
timer.stop()
timer.timeout.disconnect(onStart)
findDock()
createActions()
if p.GetBool("glassAuto", 1):
setMode() # activate Glass mode
timer.timeout.connect(onResize)
timer.start(2000)
if p.GetBool("FirstRun", 1):
"""Setup defaults on the first run."""
firstRun()
p.SetBool("FirstRun", 0)
timer = QtCore.QTimer()
timer.timeout.connect(onStart)
timer.start(500)