19
"""Navigation indicator for FreeCAD."""
23
import FreeCADGui as Gui
24
from PySide import QtGui
25
from PySide import QtCore
27
mw = Gui.getMainWindow()
28
statusBar = mw.statusBar()
29
p = App.ParamGet("User parameter:Tux/NavigationIndicator")
30
pView = App.ParamGet("User parameter:BaseApp/Preferences/View")
31
pMWin = App.ParamGet("User parameter:BaseApp/Preferences/MainWindow")
34
_encoding = QtGui.QApplication.UnicodeUTF8
36
def translate(context, text):
37
"convenience function for Qt 4 translator"
38
return QtGui.QApplication.translate(context, text, None, _encoding)
42
def translate(context, text):
43
"convenience function for Qt 5 translator"
44
return QtGui.QApplication.translate(context, text, None)
47
class IndicatorButton(QtGui.QPushButton):
48
"""Detect language change events."""
50
def __init__(self, parent=None):
51
super(IndicatorButton, self).__init__()
53
def changeEvent(self, event):
55
if event.type() == QtCore.QEvent.LanguageChange:
59
return super(IndicatorButton, self).changeEvent(event)
61
def onChange(self, paramGrp, param):
62
if param == "NavigationStyle":
65
def mousePressEvent(self, event):
67
return super(IndicatorButton, self).mousePressEvent(event)
71
curStyleSheet = pMWin.GetString("StyleSheet")
72
if "dark" in curStyleSheet.lower():
73
StyleSheetType = "light"
75
StyleSheetType = "dark"
77
a1.setIcon(QtGui.QIcon(":/icons/NavigationBlender_" + StyleSheetType + ".svg"))
78
a2.setIcon(QtGui.QIcon(":/icons/NavigationCAD_" + StyleSheetType + ".svg"))
79
a3.setIcon(QtGui.QIcon(":/icons/NavigationGesture_" + StyleSheetType + ".svg"))
80
a4.setIcon(QtGui.QIcon(":/icons/NavigationMayaGesture_" + StyleSheetType + ".svg"))
81
a5.setIcon(QtGui.QIcon(":/icons/NavigationOpenCascade_" + StyleSheetType + ".svg"))
82
a6.setIcon(QtGui.QIcon(":/icons/NavigationOpenInventor_" + StyleSheetType + ".svg"))
83
a7.setIcon(QtGui.QIcon(":/icons/NavigationOpenSCAD_" + StyleSheetType + ".svg"))
84
a8.setIcon(QtGui.QIcon(":/icons/NavigationRevit_" + StyleSheetType + ".svg"))
85
a9.setIcon(QtGui.QIcon(":/icons/NavigationTinkerCAD_" + StyleSheetType + ".svg"))
86
a10.setIcon(QtGui.QIcon(":/icons/NavigationTouchpad_" + StyleSheetType + ".svg"))
90
"""Retranslate navigation indicator on language change"""
92
text01 = translate("NavigationIndicator", "Select")
93
text02 = translate("NavigationIndicator", "Zoom")
94
text03 = translate("NavigationIndicator", "Rotate")
95
text04 = translate("NavigationIndicator", "Pan")
96
text05 = translate("NavigationIndicator", "Tilt")
97
text06 = translate("NavigationIndicator", "Navigation style")
98
text07 = translate("NavigationIndicator", "Page Up or Page Down key.")
99
text08 = translate("NavigationIndicator", "Rotation focus")
100
text09 = translate("NavigationIndicator", "Middle mouse button or H key.")
101
text10 = translate("NavigationIndicator", "Middle mouse button.")
104
t0 = translate("NavigationIndicator", "Navigation style not recognized.")
108
"<p align='center'><b>Blender</b> "
130
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
131
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
132
<td align='center'><img src=':/icons/Navigation_Mouse_Middle.svg'></td>
133
<td align='center'><img src=':/icons/Navigation_Mouse_ShiftMiddle.svg'></td>
134
<td align='center'><img src=':/icons/Navigation_Mouse_LeftRight.svg'></td>
146
"<p align='center'><b>CAD</b> "
168
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
169
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
170
<td align='center'><img src=':/icons/Navigation_Mouse_MiddleLeft.svg'></td>
171
<td align='center'><img src=':/icons/Navigation_Mouse_MiddleRight.svg'></td>
172
<td align='center'><img src=':/icons/Navigation_Mouse_Middle.svg'></td>
184
"<p align='center'><b>Gesture</b> "
209
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
210
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
211
<td align='center'><img src=':/icons/Navigation_Mouse_LeftMove.svg'></td>
212
<td align='center'><img src=':/icons/Navigation_Mouse_AltLeft.svg'></td>
213
<td align='center'><img src=':/icons/Navigation_Mouse_Right.svg'></td>
214
<td align='center'><img src=':/icons/Navigation_Mouse_LeftRight.svg'></td>
237
<td align='center'><img src=':/icons/Navigation_Gesture_SelectTouch.svg'></td>
238
<td align='center'><img src=':/icons/Navigation_Gesture_ZoomTouch.svg'></td>
239
<td align='center'><img src=':/icons/Navigation_Gesture_RotateTouch.svg'></td>
240
<td align='center'><img src=':/icons/Navigation_Gesture_PanTouch.svg'></td>
241
<td align='center'><img src=':/icons/Navigation_Gesture_PanTouchAlt.svg'></td>
242
<td align='center'><img src=':/icons/Navigation_Gesture_TiltTouch.svg'></td>
259
"<p align='center'><b>MayaGesture</b> "
284
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
285
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
286
<td align='center'><img src=':/icons/Navigation_Mouse_AltRight.svg'></td>
287
<td align='center'><img src=':/icons/Navigation_Mouse_AltLeft.svg'></td>
288
<td align='center'><img src=':/icons/Navigation_Mouse_AltMiddle.svg'></td>
289
<td align='center'><img src=':/icons/Navigation_Mouse_AltLeftRight.svg'></td>
312
<td align='center'><img src=':/icons/Navigation_Gesture_SelectTouch.svg'></td>
313
<td align='center'><img src=':/icons/Navigation_Gesture_ZoomTouch.svg'></td>
314
<td align='center'><img src=':/icons/Navigation_Gesture_RotateTouch.svg'></td>
315
<td align='center'><img src=':/icons/Navigation_Gesture_PanTouch.svg'></td>
316
<td align='center'><img src=':/icons/Navigation_Gesture_PanTouchAlt.svg'></td>
317
<td align='center'><img src=':/icons/Navigation_Gesture_TiltTouch.svg'></td>
334
"<p align='center'><b>OpenCascade</b> "
359
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
360
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
361
<td align='center'><img src=':/icons/Navigation_Mouse_CtrlLeft.svg'></td>
362
<td align='center'><img src=':/icons/Navigation_Mouse_CtrlRight.svg'></td>
363
<td align='center'><img src=':/icons/Navigation_Mouse_CtrlMiddle.svg'></td>
364
<td align='center'><img src=':/icons/Navigation_Mouse_Middle.svg'></td>
371
"<p align='center'><b>OpenInventor</b> "
393
<td align='center'><img src=':/icons/Navigation_Mouse_ShiftLeft.svg'></td>
394
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
395
<td align='center'><img src=':/icons/Navigation_Mouse_MiddleLeft.svg'></td>
396
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
397
<td align='center'><img src=':/icons/Navigation_Mouse_Middle.svg'></td>
409
"<p align='center'><b>OpenSCAD</b> "
434
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
435
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
436
<td align='center'><img src=':/icons/Navigation_Mouse_Middle.svg'></td>
437
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
438
<td align='center'><img src=':/icons/Navigation_Mouse_MiddleRight.svg'></td>
439
<td align='center'><img src=':/icons/Navigation_Mouse_Right.svg'></td>
446
"<p align='center'><b>Revit</b> "
468
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
469
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
470
<td align='center'><img src=':/icons/Navigation_Mouse_ShiftMiddle.svg'></td>
471
<td align='center'><img src=':/icons/Navigation_Mouse_Middle.svg'></td>
472
<td align='center'><img src=':/icons/Navigation_Mouse_LeftRight.svg'></td>
484
"<p align='center'><b>TinkerCAD</b> "
503
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
504
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
505
<td align='center'><img src=':/icons/Navigation_Mouse_Right.svg'></td>
506
<td align='center'><img src=':/icons/Navigation_Mouse_Middle.svg'></td>
513
"<p align='center'><b>Touchpad</b> "
538
<td align='center'><img src=':/icons/Navigation_Mouse_Left.svg'></td>
539
<td align='center'><img src=':/icons/Navigation_Mouse_Scroll.svg'></td>
540
<td align='center'><img src=':/icons/Navigation_Mouse_ShiftCtrlMove.svg'></td>
541
<td align='center'><img src=':/icons/Navigation_Mouse_AltMove.svg'></td>
542
<td align='center'><img src=':/icons/Navigation_Mouse_ShiftLeft.svg'></td>
543
<td align='center'><img src=':/icons/Navigation_Mouse_ShiftMove.svg'></td>
563
<td align='center'><img src=':/icons/Navigation_Touchpad_Left.svg'></td>
564
<td align='center'><img src=':/icons/Navigation_Touchpad_ShiftCtrlTouch.svg'></td>
565
<td align='center'><img src=':/icons/Navigation_Touchpad_AltTouch.svg'></td>
566
<td align='center'><img src=':/icons/Navigation_Touchpad_ShiftLeftTouch.svg'></td>
567
<td align='center'><img src=':/icons/Navigation_Touchpad_ShiftTouch.svg'></td>
577
menuSettings.setTitle(translate("NavigationIndicator", "Settings"))
578
menuOrbit.setTitle(translate("NavigationIndicator", "Orbit style"))
579
aCompact.setText(translate("NavigationIndicator", "Compact"))
580
aTooltip.setText(translate("NavigationIndicator", "Tooltip"))
581
aTurntable.setText(translate("NavigationIndicator", "Turntable"))
582
aFreeTurntable.setText(translate("NavigationIndicator", "Free Turntable"))
583
aTrackball.setText(translate("NavigationIndicator", "Trackball"))
584
a0.setText(translate("NavigationIndicator", "Undefined"))
587
indicator = IndicatorButton(statusBar)
588
indicator.setFlat(True)
589
indicator.adjustSize()
590
indicator.setObjectName("NavigationIndicator")
592
menu = QtGui.QMenu(indicator)
593
indicator.setMenu(menu)
595
menuSettings = QtGui.QMenu(menu)
596
menuOrbit = QtGui.QMenu(menu)
598
aCompact = QtGui.QAction(menuSettings)
599
aCompact.setCheckable(True)
600
aTooltip = QtGui.QAction(menuSettings)
601
aTooltip.setCheckable(True)
603
gOrbit = QtGui.QActionGroup(menuSettings)
605
aTurntable = QtGui.QAction(gOrbit)
606
aTurntable.setObjectName("NavigationIndicator_Turntable")
607
aTurntable.setCheckable(True)
608
aTrackball = QtGui.QAction(gOrbit)
609
aTrackball.setObjectName("NavigationIndicator_Trackball")
610
aTrackball.setCheckable(True)
611
aFreeTurntable = QtGui.QAction(gOrbit)
612
aFreeTurntable.setObjectName("NavigationIndicator_FreeTurntable")
613
aFreeTurntable.setCheckable(True)
615
menuOrbit.addAction(aTurntable)
616
menuOrbit.addAction(aTrackball)
617
menuOrbit.addAction(aFreeTurntable)
619
menuSettings.addMenu(menuOrbit)
620
menuSettings.addSeparator()
621
menuSettings.addAction(aCompact)
622
menuSettings.addAction(aTooltip)
624
gStyle = QtGui.QActionGroup(menu)
626
a0 = QtGui.QAction(gStyle)
627
a0.setIcon(QtGui.QIcon(":/icons/NavigationUndefined.svg"))
628
a0.setData("Undefined ")
629
a0.setObjectName("Indicator_NavigationUndefined")
631
a1 = QtGui.QAction(gStyle)
632
a1.setText("Blender ")
633
a1.setData("Gui::BlenderNavigationStyle")
634
a1.setObjectName("Indicator_NavigationBlender")
636
a2 = QtGui.QAction(gStyle)
638
a2.setData("Gui::CADNavigationStyle")
639
a2.setObjectName("Indicator_NavigationCAD")
641
a3 = QtGui.QAction(gStyle)
642
a3.setText("Gesture ")
643
a3.setData("Gui::GestureNavigationStyle")
644
a3.setObjectName("Indicator_NavigationGesture")
646
a4 = QtGui.QAction(gStyle)
647
a4.setText("MayaGesture ")
648
a4.setData("Gui::MayaGestureNavigationStyle")
649
a4.setObjectName("Indicator_NavigationMayaGesture")
651
a5 = QtGui.QAction(gStyle)
652
a5.setText("OpenCascade ")
653
a5.setData("Gui::OpenCascadeNavigationStyle")
654
a5.setObjectName("Indicator_NavigationOpenCascade")
656
a6 = QtGui.QAction(gStyle)
657
a6.setText("OpenInventor ")
658
a6.setData("Gui::InventorNavigationStyle")
659
a6.setObjectName("Indicator_NavigationOpenInventor")
661
a7 = QtGui.QAction(gStyle)
662
a7.setText("OpenSCAD ")
663
a7.setData("Gui::OpenSCADNavigationStyle")
664
a7.setObjectName("Indicator_NavigationOpenSCAD")
666
a8 = QtGui.QAction(gStyle)
668
a8.setData("Gui::RevitNavigationStyle")
669
a8.setObjectName("Indicator_NavigationRevit")
671
a9 = QtGui.QAction(gStyle)
672
a9.setText("TinkerCAD ")
673
a9.setData("Gui::TinkerCADNavigationStyle")
674
a9.setObjectName("Indicator_NavigationTinkerCAD")
676
a10 = QtGui.QAction(gStyle)
677
a10.setText("Touchpad ")
678
a10.setData("Gui::TouchpadNavigationStyle")
679
a10.setObjectName("Indicator_NavigationTouchpad")
683
menu.addMenu(menuSettings)
697
pView.Attach(indicator)
701
"""Enable or disable compact mode."""
703
if aCompact.isChecked():
704
p.SetBool("Compact", 1)
706
p.SetBool("Compact", 0)
711
def setCompact(action):
712
"""Set compact mode."""
714
if p.GetBool("Compact", 0):
715
indicator.setText("")
717
indicator.setText(action.text())
718
indicator.adjustSize()
722
"""Enable or disable verbose tooltips."""
724
if aTooltip.isChecked():
736
p.SetBool("Tooltip", 1)
738
for i in gStyle.actions():
740
p.SetBool("Tooltip", 0)
746
"""Use turntable or trackball orbit style."""
748
if aTurntable.isChecked():
749
pView.SetInt("OrbitStyle", 0)
750
elif aTrackball.isChecked():
751
pView.SetInt("OrbitStyle", 1)
752
elif aFreeTurntable.isChecked():
753
pView.SetInt("OrbitStyle", 2)
757
"""Set turntable or trackball orbit style."""
759
OrbitStyle = pView.GetInt("OrbitStyle", 0)
760
gOrbit.blockSignals(True)
762
aTurntable.setChecked(True)
763
elif OrbitStyle == 1:
764
aTrackball.setChecked(True)
765
elif OrbitStyle == 2:
766
aFreeTurntable.setChecked(True)
767
gOrbit.blockSignals(False)
771
"""Set navigation style on selection."""
772
pView.SetString("NavigationStyle", action.data())
776
"""Set navigation style on start and on interval."""
777
gStyle.blockSignals(True)
780
actions = gStyle.actions()
781
current = pView.GetString("NavigationStyle")
783
if current and current != "Undefined":
785
if i.data() == current:
788
menu.setDefaultAction(i)
789
indicator.setIcon(i.icon())
790
indicator.setToolTip(i.toolTip())
795
pView.SetString("NavigationStyle", a2.data())
803
menu.setDefaultAction(a0)
804
indicator.setIcon(a0.icon())
805
indicator.setToolTip(a0.toolTip())
807
gStyle.blockSignals(False)
810
if p.GetBool("Compact", 0):
811
aCompact.setChecked(True)
813
if p.GetBool("Tooltip", 1):
814
aTooltip.setChecked(True)
820
label = statusBar.children()[2]
821
statusBar.removeWidget(label)
822
statusBar.addPermanentWidget(indicator)
823
statusBar.addPermanentWidget(label)
828
gStyle.triggered.connect(onMenu)
829
gOrbit.triggered.connect(onOrbit)
830
aCompact.triggered.connect(onCompact)
831
aTooltip.triggered.connect(onTooltip)
832
menuOrbit.aboutToShow.connect(onOrbitShow)
833
menu.aboutToHide.connect(indicator.clearFocus)