forked from triplus/PieMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitGui.py
2443 lines (1831 loc) · 71.9 KB
/
InitGui.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# PieMenu widget for FreeCAD
#
# Copyright (C) 2022, 2023 mdkus @ FreeCAD
# Copyright (C) 2016, 2017 triplus @ FreeCAD
# Copyright (C) 2015,2016 looo @ FreeCAD
# Copyright (C) 2015 microelly <microelly2@freecadbuch.de>
#
#
# 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
# Attribution:
# http://forum.freecadweb.org/
# http://www.freecadweb.org/wiki/index.php?title=Code_snippets
global PIE_MENU_VERSION
PIE_MENU_VERSION = "1.2.7"
def pieMenuStart():
import math
import operator
import platform
import FreeCAD as App
import FreeCADGui as Gui
from PySide import QtCore
from PySide import QtGui
import PieMenuLocator as locator
path = locator.path()
respath = path + "/Resources/icons/"
# global status variables
selectionTriggered = False
contextPhase = False
def remObsoleteParams():
"""Remove obsolete parameters from older versions."""
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
paramGet.RemBool("ContextPhase")
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."""
onControl()
styleButton = ("""
QToolButton {
background-color: lightGray;
border: 1px outset silver;
}
QToolButton:disabled {
background-color: darkGray;
}
QToolButton:hover {
background-color: lightBlue;
}
QToolButton:checked {
background-color: lightGreen;
}
QToolButton::menu-indicator {
subcontrol-origin: padding;
subcontrol-position: center center;
}
""")
styleMenuClose = ("""
QToolButton {
background-color: rgba(60,60,60,255);
color: silver;
border: 1px solid #1e1e1e;
}
QToolButton::menu-indicator {
image: none;
}
""")
styleContainer = ("QMenu{background: transparent}")
styleCombo = ("""
QComboBox {
background: transparent;
border: 1px solid transparent;
}
""")
styleQuickMenu = ("padding: 5px 10px 5px 10px")
styleQuickMenuItem = ("""
QMenu::item {
padding: 5px 20px 5px 20px;
}
""")
iconClose = respath + "PieMenuClose.svg"
iconMenu = respath + "PieMenuQuickMenu.svg"
iconUp = respath + "PieMenuUp.svg"
iconDown = respath + "PieMenuDown.svg"
iconAdd = respath + "PieMenuAdd.svg"
iconRemove = respath + "PieMenuRemove.svg"
iconRename = respath + "PieMenuRename.svg"
iconCopy = respath + "PieMenuCopy.svg"
iconRemoveCommand = respath + "PieMenuRemoveCommand.svg"
def radiusSize(buttonSize):
radius = str(math.trunc(buttonSize / 2))
return "QToolButton {border-radius: " + radius + "px}"
def iconSize(buttonSize):
icon = buttonSize / 3 * 2
return icon
def closeButton(buttonSize=32):
icon = iconSize(buttonSize)
radius = radiusSize(buttonSize)
button = QtGui.QToolButton()
button.setProperty("ButtonX", 0)
button.setProperty("ButtonY", 0)
button.setGeometry(0, 0, buttonSize, buttonSize)
button.setIconSize(QtCore.QSize(icon, icon))
button.setIcon(QtGui.QIcon(iconClose))
button.setStyleSheet(styleMenuClose + radius)
button.setAttribute(QtCore.Qt.WA_TranslucentBackground)
def onButton():
PieMenuInstance.hide()
button.clicked.connect(onButton)
return button
def quickMenu(buttonSize=20):
icon = iconSize(buttonSize)
radius = radiusSize(buttonSize)
menu = QtGui.QMenu(mw)
menu.setStyleSheet(styleQuickMenu)
button = QtGui.QToolButton()
button.setMenu(menu)
button.setProperty("ButtonX", 0)
button.setProperty("ButtonY", 32)
button.setGeometry(0, 0, buttonSize, buttonSize)
button.setStyleSheet(styleMenuClose + radius)
button.setIconSize(QtCore.QSize(icon, icon))
button.setIcon(QtGui.QIcon(iconMenu))
button.setAttribute(QtCore.Qt.WA_TranslucentBackground)
button.setPopupMode(QtGui.QToolButton
.ToolButtonPopupMode.InstantPopup)
menuMode = QtGui.QMenu()
menuMode.setTitle("Trigger")
modeGroup = QtGui.QActionGroup(menuMode)
modeGroup.setExclusive(True)
actionPress = QtGui.QAction(modeGroup)
actionPress.setText("Press")
actionPress.setData("Press")
actionPress.setCheckable(True)
actionHover = QtGui.QAction(modeGroup)
actionHover.setText("Hover")
actionHover.setData("Hover")
actionHover.setCheckable(True)
menuMode.addAction(actionPress)
menuMode.addAction(actionHover)
actionContext = QtGui.QAction(menu)
actionContext.setText("Context")
actionContext.setCheckable(True)
menuPieMenu = QtGui.QMenu()
menuPieMenu.setTitle("PieMenu")
pieGroup = QtGui.QActionGroup(menu)
pieGroup.setExclusive(True)
menuToolBar = QtGui.QMenu()
menuToolBar.setTitle("ToolBar")
menuToolBar.setStyleSheet(styleQuickMenuItem)
toolbarGroup = QtGui.QMenu()
toolbarGroupOps = QtGui.QActionGroup(toolbarGroup)
toolbarGroupOps.setExclusive(True)
prefAction = QtGui.QAction(menu)
prefAction.setIconText("Preferences")
prefButton = QtGui.QToolButton()
prefButton.setDefaultAction(prefAction)
prefButtonWidgetAction = QtGui.QWidgetAction(menu)
prefButtonWidgetAction.setDefaultWidget(prefButton)
def setChecked():
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
if paramGet.GetString("TriggerMode") == "Hover":
actionHover.setChecked(True)
else:
actionPress.setChecked(True)
if paramGet.GetBool("EnableContext"):
actionContext.setChecked(True)
else:
pass
setChecked()
def onModeGroup():
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
text = modeGroup.checkedAction().data()
paramGet.SetString("TriggerMode", text)
PieMenuInstance.hide()
PieMenuInstance.showAtMouse(notKeyTriggered=True)
modeGroup.triggered.connect(onModeGroup)
def onActionContext():
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
if actionContext.isChecked():
paramGet.SetBool("EnableContext", True)
contextList()
else:
paramGet.SetBool("EnableContext", False)
addObserver()
actionContext.triggered.connect(onActionContext)
def pieList():
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
paramIndexGet = App.ParamGet("User parameter:BaseApp/PieMenu/Index")
indexList = paramIndexGet.GetString("IndexList")
menuPieMenu.clear()
if indexList:
indexList = indexList.split(".,.")
temp = []
for i in indexList:
temp.append(int(i))
indexList = temp
else:
indexList = []
pieList = []
for i in indexList:
a = str(i)
try:
pieName = paramIndexGet.GetString(a).decode("UTF-8")
except AttributeError:
pieName = paramIndexGet.GetString(a)
pieList.append(pieName)
if not paramGet.GetBool("ToolBar"):
try:
text = paramGet.GetString("CurrentPie").decode("UTF-8")
except AttributeError:
text = paramGet.GetString("CurrentPie")
else:
text = None
for i in pieList:
action = QtGui.QAction(pieGroup)
action.setText(i)
action.setCheckable(True)
if i == text:
action.setChecked(True)
else:
pass
menuPieMenu.addAction(action)
menuPieMenu.aboutToShow.connect(pieList)
def onPieGroup():
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
paramGet.SetBool("ToolBar", False)
paramGet.RemString("ToolBar")
try:
text = pieGroup.checkedAction().text().encode("UTF-8")
paramGet.SetString("CurrentPie", text)
except TypeError:
text = pieGroup.checkedAction().text()
paramGet.SetString("CurrentPie", text)
PieMenuInstance.hide()
PieMenuInstance.showAtMouse(notKeyTriggered=True)
pieGroup.triggered.connect(onPieGroup)
def onMenuToolBar():
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
menuToolBar.clear()
if paramGet.GetBool("ToolBar"):
text = paramGet.GetString("ToolBar")
if ": " in text:
toolbar_desc = text.split(": ")
text = toolbar_desc[1]
else:
pass
else:
text = None
for i in mw.findChildren(QtGui.QToolBar):
commands = []
for a in i.findChildren(QtGui.QToolButton):
try:
if not a.defaultAction().isSeparator():
commands.append(a.defaultAction())
else:
pass
except AttributeError:
pass
if len(commands) != 0:
menu = QtGui.QMenu(i.windowTitle())
menu.aboutToShow.connect(lambda sender=menu: onMenuToolbarGroup(sender))
menuToolBar.addMenu(menu)
else:
pass
menuToolBar.aboutToShow.connect(onMenuToolBar)
def isActualPie(text):
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
if paramGet.GetBool("ToolBar"):
entry = paramGet.GetString("ToolBar")
if ": " in entry:
toolbar_desc = entry.split(": ")
idMenu = toolbar_desc[1]
else:
idMenu = entry
if idMenu == text:
return True;
return False
def onMenuToolbarGroup(sender):
if not sender.actions():
action = QtGui.QAction(sender)
action.setText("Show")
action.setData(sender.title())
action.setCheckable(True)
if isActualPie(sender.title()):
action.setChecked(True)
sender.addAction(action)
action = QtGui.QAction(sender)
action.setText("Save")
action.setData(sender.title())
sender.addAction(action)
sender.triggered.connect(lambda sender: onToolbarGroup(sender))
def onToolbarGroup(sender):
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
if sender.text() == "Show":
paramGet.SetBool("ToolBar", True)
elif sender.text() == "Save":
newPieGroup = createPie(sender.data())
else:
return
workbenches = []
commands = []
if sender.text() == "Save":
# write persistent commands
getGuiToolButtonData(sender.data(), None, commands, None)
newPieGroup.SetString("ToolList", ".,.".join(commands))
elif sender.text() == "Show":
# write persistent toolbar and its workbenches
getGuiToolButtonData(sender.data(), None, None, workbenches)
toolbar_desc = ", ".join(workbenches)
toolbar_desc = toolbar_desc + ': ' + sender.data()
paramGet.SetString("ToolBar", toolbar_desc)
PieMenuInstance.hide()
PieMenuInstance.showAtMouse(notKeyTriggered=True)
toolbarGroup.triggered.connect(onToolbarGroup)
def onPrefButton():
PieMenuInstance.hide()
onControl()
prefButton.clicked.connect(onPrefButton)
menu.addMenu(menuMode)
menu.addAction(actionContext)
menu.addSeparator()
menu.addMenu(menuPieMenu)
menu.addMenu(menuToolBar)
menu.addSeparator()
menu.addAction(prefButtonWidgetAction)
return button
class HoverButton(QtGui.QToolButton):
def __init__(self, parent=None):
super(HoverButton, self).__init__()
def enterEvent(self, event):
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
mode = paramGet.GetString("TriggerMode")
if self.defaultAction().isEnabled() and mode == "Hover":
PieMenuInstance.hide()
self.defaultAction().trigger()
else:
pass
def mouseReleaseEvent(self, event):
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
mode = paramGet.GetString("TriggerMode")
if self.defaultAction().isEnabled():
PieMenuInstance.hide()
self.defaultAction().trigger()
else:
pass
class PieMenu:
def __init__(self):
self.radius = 100
self.buttons = []
self.buttonSize = 32
self.menu = QtGui.QMenu(mw)
self.menuSize = 0
self.menu.setStyleSheet(styleContainer)
self.menu.setWindowFlags(self.menu.windowFlags() | QtCore.Qt.FramelessWindowHint)
self.menu.setAttribute(QtCore.Qt.WA_TranslucentBackground)
if compositingManager:
pass
else:
self.menu.setAttribute(QtCore.Qt.WA_PaintOnScreen)
def add_commands(self, commands, context=False):
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
for i in self.buttons:
i.deleteLater()
self.buttons = []
if context:
group = getGroup(mode=2)
else:
group = getGroup(mode=1)
if len(commands) == 0:
commandNumber = 1
else:
commandNumber = len(commands)
valueRadius = group.GetInt("Radius")
valueButton = group.GetInt("Button")
if paramGet.GetBool("ToolBar"):
valueRadius = 100
valueButton = 32
if valueRadius:
self.radius = valueRadius
else:
self.radius = 100
if valueButton:
self.buttonSize = valueButton
else:
self.buttonSize = 32
if commandNumber == 1:
angle = 0
buttonSize = self.buttonSize
else:
angle = 2 * math.pi / commandNumber
buttonRadius = math.sin(angle / 2) * self.radius
buttonSize = math.trunc(2 * buttonRadius / math.sqrt(2))
angleStart = 3 * math.pi / 2 - angle
if buttonSize > self.buttonSize:
buttonSize = self.buttonSize
else:
pass
radius = radiusSize(buttonSize)
icon = iconSize(buttonSize)
if windowShadow:
pass
else:
self.menuSize = valueRadius * 2 + buttonSize + 4
if self.menuSize < 90:
self.menuSize = 90
else:
pass
self.menu.setMinimumWidth(self.menuSize)
self.menu.setMinimumHeight(self.menuSize)
num = 1
for i in commands:
button = HoverButton()
button.setParent(self.menu)
button.setAttribute(QtCore.Qt.WA_Hover)
button.setStyleSheet(styleButton + radius)
button.setAttribute(QtCore.Qt.WA_TranslucentBackground)
button.setDefaultAction(commands[commands.index(i)])
button.setGeometry(0, 0, buttonSize, buttonSize)
button.setIconSize(QtCore.QSize(icon, icon))
button.setProperty("ButtonX", self.radius *
(math.cos(angle * num + angleStart)))
button.setProperty("ButtonY", self.radius *
(math.sin(angle * num + angleStart)))
self.buttons.append(button)
num = num + 1
buttonQuickMenu = quickMenu()
buttonQuickMenu.setParent(self.menu)
self.buttons.append(buttonQuickMenu)
buttonClose = closeButton()
buttonClose.setParent(self.menu)
self.buttons.append(buttonClose)
if compositingManager:
pass
else:
for i in self.buttons:
i.setAttribute(QtCore.Qt.WA_PaintOnScreen)
def hide(self):
for i in self.buttons:
i.hide()
self.menu.hide()
def showAtMouse(self, notKeyTriggered=False):
nonlocal selectionTriggered
nonlocal contextPhase
global lastPosX
global lastPosY
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
enableContext = paramGet.GetBool("EnableContext")
if contextPhase:
sel = Gui.Selection.getSelectionEx()
if not sel:
self.hide()
contextPhase = False
updateCommands()
elif not enableContext:
self.hide()
updateCommands()
else:
updateCommands(context=True)
else:
updateCommands()
if self.menu.isVisible():
self.hide()
else:
if windowShadow:
pos = mw.mapFromGlobal(QtGui.QCursor.pos())
if notKeyTriggered:
if contextPhase:
# special case treatment
if selectionTriggered:
selectionTriggered = False
else:
pos.setX(lastPosX)
pos.setY(lastPosY)
lastPosX = pos.x()
lastPosY = pos.y()
else:
pos.setX(lastPosX)
pos.setY(lastPosY)
else:
lastPosX = pos.x()
lastPosY = pos.y()
self.menu.popup(QtCore.QPoint(mw.pos()))
self.menu.setGeometry(mw.geometry())
for i in self.buttons:
i.move(i.property("ButtonX") + pos.x() - i.width() / 2,
i.property("ButtonY") + pos.y() - i.height() / 2)
i.setVisible(True)
for i in self.buttons:
i.repaint()
else:
pos = QtGui.QCursor.pos()
if notKeyTriggered:
if contextPhase:
# special case treatment
if selectionTriggered:
selectionTriggered = False
else:
pos.setX(lastPosX)
pos.setY(lastPosY)
lastPosX = pos.x()
lastPosY = pos.y()
else:
pos.setX(lastPosX)
pos.setY(lastPosY)
else:
lastPosX = pos.x()
lastPosY = pos.y()
for i in self.buttons:
i.move(i.property("ButtonX") + (self.menuSize - i.size().width()) / 2,
i.property("ButtonY") + (self.menuSize - i.size().height()) / 2)
i.setVisible(True)
self.menu.popup(QtCore.QPoint(pos.x() - self.menuSize / 2, pos.y() - self.menuSize / 2))
sign = {
"<": operator.lt,
"<=": operator.le,
"==": operator.eq,
"!=": operator.ne,
">": operator.gt,
">=": operator.ge,
}
def contextList():
paramIndexGet = App.ParamGet("User parameter:BaseApp/PieMenu/Index")
indexList = paramIndexGet.GetString("IndexList")
contextAll.clear()
if indexList:
indexList = indexList.split(".,.")
temp = []
for i in indexList:
temp.append(int(i))
indexList = temp
else:
indexList = []
for i in indexList:
a = str(i)
group = paramIndexGet.GetGroup(a)
groupContext = group.GetGroup("Context")
if groupContext.GetBool("Enabled"):
current = {}
current["Index"] = a
current["VertexSign"] = groupContext.GetString("VertexSign")
current["VertexValue"] = groupContext.GetInt("VertexValue")
current["EdgeSign"] = groupContext.GetString("EdgeSign")
current["EdgeValue"] = groupContext.GetInt("EdgeValue")
current["FaceSign"] = groupContext.GetString("FaceSign")
current["FaceValue"] = groupContext.GetInt("FaceValue")
current["ObjectSign"] = groupContext.GetString("ObjectSign")
current["ObjectValue"] = groupContext.GetInt("ObjectValue")
contextAll[i] = current
else:
pass
def getContextPie(v, e, f, o):
global globalContextPie
global globalIndexPie
globalContextPie = False
globalIndexPie = None
for i in contextAll:
current = contextAll[i]
def vertex():
if sign[current["VertexSign"]](v, current["VertexValue"]):
edge()
else:
pass
def edge():
if sign[current["EdgeSign"]](e, current["EdgeValue"]):
face()
else:
pass
def face():
if sign[current["FaceSign"]](f, current["FaceValue"]):
obj()
else:
pass
def obj():
if sign[current["ObjectSign"]](o, current["ObjectValue"]):
global globalContextPie
global globalIndexPie
globalContextPie = "True"
globalIndexPie = current["Index"]
else:
pass
vertex()
if globalContextPie == "True":
return globalIndexPie
else:
return None
def listTopo():
nonlocal selectionTriggered
nonlocal contextPhase
sel = Gui.Selection.getSelectionEx()
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
paramIndexGet = App.ParamGet("User parameter:BaseApp/PieMenu/Index")
vertexes = 0
edges = 0
faces = 0
objects = 0
allList = []
for i in sel:
if not i.SubElementNames:
objects = objects + 1
else:
for a in i.SubElementNames:
allList.append(a)
for i in allList:
if i.startswith('Vertex'):
vertexes = vertexes + 1
elif i.startswith('Edge'):
edges = edges + 1
elif i.startswith('Face'):
faces = faces + 1
else:
pass
pieIndex = getContextPie(vertexes,
edges,
faces,
objects)
if pieIndex:
try:
pieName = paramIndexGet.GetString(pieIndex).decode("UTF-8")
except AttributeError:
pieName = paramIndexGet.GetString(pieIndex)
try:
paramGet.SetString("ContextPie", pieName.encode("UTF-8"))
except TypeError:
paramGet.SetString("ContextPie", pieName)
contextPhase = True
updateCommands(context=True)
PieMenuInstance.hide()
selectionTriggered = True
PieMenuInstance.showAtMouse(notKeyTriggered=True)
else:
pass
class SelObserver:
def addSelection(self, doc, obj, sub, pnt):
listTopo()
def removeSelection(self, doc, obj, sub):
listTopo()
def addObserver():
paramGet = App.ParamGet("User parameter:BaseApp/PieMenu")
if paramGet.GetBool("EnableContext"):
Gui.Selection.addObserver(selObserver)
else:
Gui.Selection.removeObserver(selObserver)
def getGuiActionMapAll():
actions = {}
duplicates = []
for i in mw.findChildren(QtGui.QAction):
if i.objectName() is not None:
if i.objectName() != "" and i.icon():
if i.objectName() in actions:
if i.objectName() not in duplicates:
duplicates.append(i.objectName())
else:
pass
else:
actions[i.objectName()] = i
else:
pass
else:
pass
for d in duplicates:
del actions[d]
return actions
def extractWorkbench(command):
cmd_parts = command.split("_")
if cmd_parts[0] == "":
workbench = "None"
else:
workbench = cmd_parts[0]
return workbench
def getActionData(action, actions, commands, workbenches):
if not action.icon():
return
if actions is not None:
if action in actions:
pass
else:
actions.append(action)
if commands is None and workbenches is None:
return
command = action.objectName()
if len(command) == 0:
workbench = "None"
else:
if commands is not None:
if command in commands:
pass
else:
commands.append(command)
workbench = extractWorkbench(command)
if workbenches is not None:
if not workbench in workbenches:
workbenches.append(workbench)
def getGuiToolButtonData(idToolBar, actions, commands, workbenches):
actionMapAll = getGuiActionMapAll()
for i in actionMapAll:
action = actionMapAll[i]
for widgets in action.associatedWidgets():
if widgets.objectName() == idToolBar:
getActionData(action, actions, commands, workbenches)
def actualizeWorkbenchActions(actions, toolList, actionMap):
for i in toolList:
# rule out special case: there has to be an entry
if i == "":
pass
elif i in actionMap:
if not actionMap[i] in actions:
actions.append(actionMap[i])
else:
cmd_parts = i.split("_")
# rule out special case: unknown Std action
if cmd_parts[0] == "Std":
pass
else:
# match special cases
# Fem workbench
if cmd_parts[0] == "FEM":
cmd_parts[0] = "Fem"
# Sheet Metal workbench
if cmd_parts[0][:2] == "SM":
cmd_parts[0] = cmd_parts[0][:2]
cmdWb = cmd_parts[0] + "Workbench"
# after workbench activation actionMap has to be actualized
Gui.activateWorkbench(cmdWb)
return True