eric7/Plugins/UiExtensionPlugins/Translator/Translator.py

branch
eric7
changeset 8312
800c432b34c8
parent 8143
2c730d5fd177
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the translator object.
8 """
9
10 import os
11
12 from PyQt5.QtCore import Qt, QObject
13 from PyQt5.QtGui import QKeySequence
14
15 from E5Gui.E5Action import E5Action
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 self.__ui.addSideWidget(
56 self.__ui.BottomSide, self.__widget,
57 UI.PixmapCache.getIcon(
58 os.path.join(os.path.dirname(__file__), "icons",
59 "flag-{0}".format(self.__iconSuffix))),
60 self.tr("Translator"))
61
62 self.__activateAct = E5Action(
63 self.tr('Translator'),
64 self.tr('T&ranslator'),
65 QKeySequence(self.tr("Alt+Shift+R")),
66 0, self,
67 'translator_activate')
68 self.__activateAct.setStatusTip(self.tr(
69 "Switch the input focus to the Translator window."))
70 self.__activateAct.setWhatsThis(self.tr(
71 """<b>Activate Translator</b>"""
72 """<p>This switches the input focus to the Translator"""
73 """ window.</p>"""
74 ))
75 self.__activateAct.triggered.connect(self.__activateWidget)
76
77 self.__ui.addE5Actions([self.__activateAct], 'ui')
78 menu = self.__ui.getMenu("subwindow")
79 menu.addAction(self.__activateAct)
80
81 def deactivate(self):
82 """
83 Public method to deactivate the time tracker.
84 """
85 menu = self.__ui.getMenu("subwindow")
86 menu.removeAction(self.__activateAct)
87 self.__ui.removeE5Actions([self.__activateAct], 'ui')
88 self.__ui.removeSideWidget(self.__widget)
89
90 def getAppIcon(self, name):
91 """
92 Public method to get an icon.
93
94 @param name name of the icon file (string)
95 @return icon (QIcon)
96 """
97 return UI.PixmapCache.getIcon(os.path.join(
98 os.path.dirname(__file__), "icons",
99 "{0}-{1}".format(name, self.__iconSuffix)
100 ))
101
102 def __activateWidget(self):
103 """
104 Private slot to handle the activation of the project browser.
105 """
106 uiLayoutType = self.__ui.getLayoutType()
107 if uiLayoutType == "Toolboxes":
108 self.__ui.hToolboxDock.show()
109 self.__ui.hToolbox.setCurrentWidget(self.__widget)
110 elif uiLayoutType == "Sidebars":
111 self.__ui.bottomSidebar.show()
112 self.__ui.bottomSidebar.setCurrentWidget(self.__widget)
113 else:
114 self.__widget.show()
115 self.__widget.setFocus(Qt.FocusReason.ActiveWindowFocusReason)

eric ide

mercurial