From 4fc531a8644bba7d516714277c726feaa033f21c Mon Sep 17 00:00:00 2001 From: triplus Date: Tue, 9 Jan 2018 21:01:18 +0100 Subject: [PATCH] Navigation indicator enable translations --- src/Mod/Tux/NavigationIndicatorGui.py | 435 ++++++++++++++------------ 1 file changed, 233 insertions(+), 202 deletions(-) diff --git a/src/Mod/Tux/NavigationIndicatorGui.py b/src/Mod/Tux/NavigationIndicatorGui.py index 7210971400..adcf5a7e6e 100644 --- a/src/Mod/Tux/NavigationIndicatorGui.py +++ b/src/Mod/Tux/NavigationIndicatorGui.py @@ -1,5 +1,5 @@ # Navigation indicator for FreeCAD -# Copyright (C) 2016, 2017 triplus @ FreeCAD +# Copyright (C) 2016, 2017, 2018 triplus @ FreeCAD # # # This library is free software; you can redistribute it and/or @@ -30,6 +30,7 @@ statusBar = mw.statusBar() p = App.ParamGet("User parameter:Tux/NavigationIndicator") pView = App.ParamGet("User parameter:BaseApp/Preferences/View") + try: _encoding = QtGui.QApplication.UnicodeUTF8 @@ -41,233 +42,263 @@ except AttributeError: "convenience function for Qt 5 translator" return QtGui.QApplication.translate(context, text, None) -text01 = translate("NavigationIndicator", "Select") -text02 = translate("NavigationIndicator", "Zoom") -text03 = translate("NavigationIndicator", "Rotate") -text04 = translate("NavigationIndicator", "Pan") -text05 = translate("NavigationIndicator", "Tilt") -text06 = translate("NavigationIndicator", "Navigation style") -text07 = translate("NavigationIndicator", "Page Up or Page Down key.") -text08 = translate("NavigationIndicator", "Rotation focus") -text09 = translate("NavigationIndicator", "Middle mouse button or key H.") -text10 = translate("NavigationIndicator", "Middle mouse button.") -t0 = translate("NavigationIndicator", "Navigation style not recognized.") +class IndicatorButton(QtGui.QPushButton): + """Detect language change events.""" + def __init__(self, parent=None): + super(IndicatorButton, self).__init__() -t1 = "

OpenInventor " + text06 + """

- - - - - - - - - - - - - - - -
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text04 + """
-""" + text08 + ": " + text10 + "

" + def changeEvent(self, event): + """Change events.""" + if event.type() == QtCore.QEvent.LanguageChange: + retranslateUi() + onTooltip() + return super(IndicatorButton, self).changeEvent(event) -t2 = "

CAD " + text06 + """

- - - - - - - - - - - - - - - -
""" + text01 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """
-""" + text08 + ": " + text10 + "

" -t3 = "

Blender " + text06 + """

- - - - - - - - - - - - - - - -
""" + text01 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """
-""" + text08 + ": " + text10 + "

" +def retranslateUi(): + """Retranslate navigation indicator on language change""" -t4 = "

MayaGesture " + text06 + """

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text05 + """
""" + text01 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """""" + text05 + """
-

""" + text02 + ": " + text07 + """
-""" + text08 + ": " + text09 + "

" + text01 = translate("NavigationIndicator", "Select") + text02 = translate("NavigationIndicator", "Zoom") + text03 = translate("NavigationIndicator", "Rotate") + text04 = translate("NavigationIndicator", "Pan") + text05 = translate("NavigationIndicator", "Tilt") + text06 = translate("NavigationIndicator", "Navigation style") + text07 = translate("NavigationIndicator", "Page Up or Page Down key.") + text08 = translate("NavigationIndicator", "Rotation focus") + text09 = translate("NavigationIndicator", "Middle mouse button or key H.") + text10 = translate("NavigationIndicator", "Middle mouse button.") -t5 = "

Touchpad " + text06 + """

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """
""" + text01 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """
-

""" + text02 + ": " + text07 + "

" + global t0 + t0 = translate("NavigationIndicator", "Navigation style not recognized.") -t6 = "

Gesture " + text06 + """

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
""" + text01 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """""" + text05 + """
""" + text01 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """""" + text05 + """
-

""" + text02 + ": " + text07 + """
-""" + text08 + ": " + text09 + "

" + global t1 + t1 = "

OpenInventor " + text06 + """

+ + + + + + + + + + + + + + + +
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text04 + """
+ """ + text08 + ": " + text10 + "

" -t7 = "

OpenCascade " + text06 + """

- - - - - - - - - - - - - - - - - -
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """
""" + global t2 + t2 = "

CAD " + text06 + """

+ + + + + + + + + + + + + + + +
""" + text01 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """
+ """ + text08 + ": " + text10 + "

" -indicator = QtGui.QPushButton(statusBar) + global t3 + t3 = "

Blender " + text06 + """

+ + + + + + + + + + + + + + + +
""" + text01 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """
+ """ + text08 + ": " + text10 + "

" + + global t4 + t4 = "

MayaGesture " + text06 + """

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text05 + """
""" + text01 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """""" + text05 + """
+

""" + text02 + ": " + text07 + """
+ """ + text08 + ": " + text09 + "

" + + global t5 + t5 = "

Touchpad " + text06 + """

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """
""" + text01 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """
+

""" + text02 + ": " + text07 + "

" + + global t6 + t6 = "

Gesture " + text06 + """

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
""" + text01 + """""" + text02 + """""" + text03 + """""" + text03 + """""" + text04 + """""" + text05 + """
""" + text01 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """""" + text05 + """
+

""" + text02 + ": " + text07 + """
+ """ + text08 + ": " + text09 + "

" + + global t7 + t7 = "

OpenCascade " + text06 + """

+ + + + + + + + + + + + + + + + + +
""" + text01 + """""" + text02 + """""" + text02 + """""" + text03 + """""" + text04 + """""" + text04 + """
""" + + menuSettings.setTitle(translate("NavigationIndicator", "Settings")) + menuOrbit.setTitle(translate("NavigationIndicator", "Orbit style")) + aCompact.setText(translate("NavigationIndicator", "Compact")) + aTooltip.setText(translate("NavigationIndicator", "Tooltip")) + aTurntable.setText(translate("NavigationIndicator", "Turntable")) + aTrackball.setText(translate("NavigationIndicator", "Trackball")) + a0.setText(translate("NavigationIndicator", "Undefined")) + + +indicator = IndicatorButton(statusBar) indicator.setFlat(True) indicator.setObjectName("NavigationIndicator") menu = QtGui.QMenu(indicator) indicator.setMenu(menu) -menuSettings = QtGui.QMenu(translate("NavigationIndicator", "Settings"), menu) -menuOrbit = QtGui.QMenu(translate("NavigationIndicator", "Orbit style"), menu) +menuSettings = QtGui.QMenu(menu) +menuOrbit = QtGui.QMenu(menu) aCompact = QtGui.QAction(menuSettings) -aCompact.setText(translate("NavigationIndicator", "Compact")) aCompact.setCheckable(True) aTooltip = QtGui.QAction(menuSettings) -aTooltip.setText(translate("NavigationIndicator", "Tooltip")) aTooltip.setCheckable(True) gOrbit = QtGui.QActionGroup(menuSettings) aTurntable = QtGui.QAction(gOrbit) aTurntable.setObjectName("NavigationIndicator_Turntable") -aTurntable.setText(translate("NavigationIndicator", "Turntable")) aTurntable.setCheckable(True) aTrackball = QtGui.QAction(gOrbit) aTrackball.setObjectName("NavigationIndicator_Trackball") -aTrackball.setText(translate("NavigationIndicator", "Trackball")) aTrackball.setCheckable(True) menuOrbit.addAction(aTurntable) @@ -282,7 +313,6 @@ gStyle = QtGui.QActionGroup(menu) a0 = QtGui.QAction(gStyle) a0.setIcon(QtGui.QIcon(":/icons/NavigationUndefined.svg")) -a0.setText(translate("NavigationIndicator", "Undefined")) a0.setData("Undefined") a0.setObjectName("Indicator_NavigationUndefined") @@ -429,7 +459,6 @@ def onMenu(action): def setCurrent(): """Set navigation style on start and on interval.""" - gStyle.blockSignals(True) s = False @@ -466,12 +495,14 @@ def setCurrent(): gStyle.blockSignals(False) + if p.GetBool("Compact", 0): aCompact.setChecked(True) if p.GetBool("Tooltip", 1): aTooltip.setChecked(True) +retranslateUi() onCompact() onTooltip() onOrbitShow()