eric7/Plugins/UiExtensionPlugins/Translator/Translator.py

Sat, 11 Sep 2021 12:48:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 11 Sep 2021 12:48:59 +0200
branch
eric7
changeset 8590
3663b9de2121
parent 8589
1dfe74571153
child 8592
ab8580937d4b
permissions
-rw-r--r--

Fixed the icon of the translator widget toolboxes layout.

6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the translator object.
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
12 from PyQt6.QtCore import Qt, QObject
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
13 from PyQt6.QtGui import QKeySequence
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
8358
144a6b854f70 Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8356
diff changeset
15 from EricGui.EricAction import EricAction
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import UI.PixmapCache
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class Translator(QObject):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing the translator object.
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
7505
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
24 def __init__(self, plugin, usesDarkPalette, parent=None):
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
7513
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
28 @param plugin reference to the plugin object
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
29 @type TranslatorPlugin
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
30 @param usesDarkPalette flag indicating that the platform uses a palette
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
31 with a dark background
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
32 @type bool
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
33 @param parent parent
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
34 @type QObject
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 QObject.__init__(self, parent)
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__plugin = plugin
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.__ui = parent
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.__widget = None
7505
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
42
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
43 if usesDarkPalette:
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
44 self.__iconSuffix = "dark"
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
45 else:
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
46 self.__iconSuffix = "light"
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 def activate(self):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 Public method to activate the translator.
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 from .TranslatorWidget import TranslatorWidget
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__widget = TranslatorWidget(self.__plugin, self)
8590
3663b9de2121 Fixed the icon of the translator widget toolboxes layout.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8589
diff changeset
55 if self.__ui.getLayoutType() == "Sidebars":
3663b9de2121 Fixed the icon of the translator widget toolboxes layout.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8589
diff changeset
56 iconName = "sbTranslator96"
3663b9de2121 Fixed the icon of the translator widget toolboxes layout.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8589
diff changeset
57 else:
3663b9de2121 Fixed the icon of the translator widget toolboxes layout.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8589
diff changeset
58 iconName = "flag-{0}".format(self.__iconSuffix)
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__ui.addSideWidget(
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__ui.BottomSide, self.__widget,
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 UI.PixmapCache.getIcon(
8590
3663b9de2121 Fixed the icon of the translator widget toolboxes layout.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8589
diff changeset
62 os.path.join(os.path.dirname(__file__), "icons", iconName)),
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.tr("Translator"))
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
65 self.__activateAct = EricAction(
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.tr('Translator'),
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.tr('T&ranslator'),
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 QKeySequence(self.tr("Alt+Shift+R")),
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 0, self,
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 'translator_activate')
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__activateAct.setStatusTip(self.tr(
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 "Switch the input focus to the Translator window."))
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__activateAct.setWhatsThis(self.tr(
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """<b>Activate Translator</b>"""
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """<p>This switches the input focus to the Translator"""
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """ window.</p>"""
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 ))
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.__activateAct.triggered.connect(self.__activateWidget)
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
80 self.__ui.addEricActions([self.__activateAct], 'ui')
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 menu = self.__ui.getMenu("subwindow")
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 menu.addAction(self.__activateAct)
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 def deactivate(self):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 Public method to deactivate the time tracker.
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 menu = self.__ui.getMenu("subwindow")
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 menu.removeAction(self.__activateAct)
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
90 self.__ui.removeEricActions([self.__activateAct], 'ui')
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.__ui.removeSideWidget(self.__widget)
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 def getAppIcon(self, name):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 Public method to get an icon.
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @param name name of the icon file (string)
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @return icon (QIcon)
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 return UI.PixmapCache.getIcon(os.path.join(
7505
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
101 os.path.dirname(__file__), "icons",
7513
d8354f4d3dc7 Translator plug-in: resolved some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7505
diff changeset
102 "{0}-{1}".format(name, self.__iconSuffix)
7505
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
103 ))
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 def __activateWidget(self):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 Private slot to handle the activation of the project browser.
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
6434
872d10fa686a UserInterface, Translator: fixed an issue switching to the translator via the keyboard shortcut.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
109 uiLayoutType = self.__ui.getLayoutType()
872d10fa686a UserInterface, Translator: fixed an issue switching to the translator via the keyboard shortcut.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
110 if uiLayoutType == "Toolboxes":
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.__ui.hToolboxDock.show()
6434
872d10fa686a UserInterface, Translator: fixed an issue switching to the translator via the keyboard shortcut.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
112 self.__ui.hToolbox.setCurrentWidget(self.__widget)
872d10fa686a UserInterface, Translator: fixed an issue switching to the translator via the keyboard shortcut.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
113 elif uiLayoutType == "Sidebars":
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 self.__ui.bottomSidebar.show()
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 self.__ui.bottomSidebar.setCurrentWidget(self.__widget)
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 else:
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.__widget.show()
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
118 self.__widget.setFocus(Qt.FocusReason.ActiveWindowFocusReason)

eric ide

mercurial