|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the translator object. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt6.QtCore import Qt, QObject |
|
13 from PyQt6.QtGui import QKeySequence |
|
14 |
|
15 from EricGui.EricAction import EricAction |
|
16 |
|
17 import UI.PixmapCache |
|
18 |
|
19 |
|
20 class Translator(QObject): |
|
21 """ |
|
22 Class implementing the translator object. |
|
23 """ |
|
24 def __init__(self, plugin, usesDarkPalette, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param plugin reference to the plugin object |
|
29 @type TranslatorPlugin |
|
30 @param usesDarkPalette flag indicating that the platform uses a palette |
|
31 with a dark background |
|
32 @type bool |
|
33 @param parent parent |
|
34 @type QObject |
|
35 """ |
|
36 QObject.__init__(self, parent) |
|
37 |
|
38 self.__plugin = plugin |
|
39 self.__ui = parent |
|
40 |
|
41 self.__widget = None |
|
42 |
|
43 if usesDarkPalette: |
|
44 self.__iconSuffix = "dark" |
|
45 else: |
|
46 self.__iconSuffix = "light" |
|
47 |
|
48 def activate(self): |
|
49 """ |
|
50 Public method to activate the translator. |
|
51 """ |
|
52 from .TranslatorWidget import TranslatorWidget |
|
53 |
|
54 self.__widget = TranslatorWidget(self.__plugin, self) |
|
55 iconName = ( |
|
56 "sbTranslator96" |
|
57 if self.__ui.getLayoutType() == "Sidebars" else |
|
58 "flag-{0}".format(self.__iconSuffix) |
|
59 ) |
|
60 self.__ui.addSideWidget( |
|
61 self.__ui.BottomSide, self.__widget, |
|
62 UI.PixmapCache.getIcon( |
|
63 os.path.join(os.path.dirname(__file__), "icons", iconName)), |
|
64 self.tr("Translator")) |
|
65 |
|
66 self.__activateAct = EricAction( |
|
67 self.tr('Translator'), |
|
68 self.tr('T&ranslator'), |
|
69 QKeySequence(self.tr("Alt+Shift+R")), |
|
70 0, self, |
|
71 'translator_activate') |
|
72 self.__activateAct.setStatusTip(self.tr( |
|
73 "Switch the input focus to the Translator window.")) |
|
74 self.__activateAct.setWhatsThis(self.tr( |
|
75 """<b>Activate Translator</b>""" |
|
76 """<p>This switches the input focus to the Translator""" |
|
77 """ window.</p>""" |
|
78 )) |
|
79 self.__activateAct.triggered.connect(self.__activateWidget) |
|
80 |
|
81 self.__ui.addEricActions([self.__activateAct], 'ui') |
|
82 menu = self.__ui.getMenu("subwindow") |
|
83 menu.addAction(self.__activateAct) |
|
84 |
|
85 def deactivate(self): |
|
86 """ |
|
87 Public method to deactivate the time tracker. |
|
88 """ |
|
89 menu = self.__ui.getMenu("subwindow") |
|
90 menu.removeAction(self.__activateAct) |
|
91 self.__ui.removeEricActions([self.__activateAct], 'ui') |
|
92 self.__ui.removeSideWidget(self.__widget) |
|
93 |
|
94 def getAppIcon(self, name): |
|
95 """ |
|
96 Public method to get an icon. |
|
97 |
|
98 @param name name of the icon file |
|
99 @type str |
|
100 @return icon |
|
101 @rtype QIcon |
|
102 """ |
|
103 return UI.PixmapCache.getIcon(os.path.join( |
|
104 os.path.dirname(__file__), "icons", |
|
105 "{0}-{1}".format(name, self.__iconSuffix) |
|
106 )) |
|
107 |
|
108 def __activateWidget(self): |
|
109 """ |
|
110 Private slot to handle the activation of the project browser. |
|
111 """ |
|
112 uiLayoutType = self.__ui.getLayoutType() |
|
113 if uiLayoutType == "Toolboxes": |
|
114 self.__ui.hToolboxDock.show() |
|
115 self.__ui.hToolbox.setCurrentWidget(self.__widget) |
|
116 elif uiLayoutType == "Sidebars": |
|
117 self.__ui.bottomSidebar.show() |
|
118 self.__ui.bottomSidebar.setCurrentWidget(self.__widget) |
|
119 else: |
|
120 self.__widget.show() |
|
121 self.__widget.setFocus(Qt.FocusReason.ActiveWindowFocusReason) |