eric6/Plugins/UiExtensionPlugins/Translator/Translator.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the translator object.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13
14 from PyQt5.QtCore import Qt, QObject
15 from PyQt5.QtGui import QKeySequence
16
17 from E5Gui.E5Action import E5Action
18
19 import UI.PixmapCache
20
21
22 class Translator(QObject):
23 """
24 Class implementing the translator object.
25 """
26 def __init__(self, plugin, parent=None):
27 """
28 Constructor
29
30 @param plugin reference to the plugin object (TranslatorPlugin)
31 @param parent parent (QObject)
32 """
33 QObject.__init__(self, parent)
34
35 self.__plugin = plugin
36 self.__ui = parent
37
38 self.__widget = None
39
40 def activate(self):
41 """
42 Public method to activate the translator.
43 """
44 from .TranslatorWidget import TranslatorWidget
45
46 self.__widget = TranslatorWidget(self.__plugin, self)
47 self.__ui.addSideWidget(
48 self.__ui.BottomSide, self.__widget,
49 UI.PixmapCache.getIcon(
50 os.path.join(os.path.dirname(__file__), "icons", "flag.png")),
51 self.tr("Translator"))
52
53 self.__activateAct = E5Action(
54 self.tr('Translator'),
55 self.tr('T&ranslator'),
56 QKeySequence(self.tr("Alt+Shift+R")),
57 0, self,
58 'translator_activate')
59 self.__activateAct.setStatusTip(self.tr(
60 "Switch the input focus to the Translator window."))
61 self.__activateAct.setWhatsThis(self.tr(
62 """<b>Activate Translator</b>"""
63 """<p>This switches the input focus to the Translator"""
64 """ window.</p>"""
65 ))
66 self.__activateAct.triggered.connect(self.__activateWidget)
67
68 self.__ui.addE5Actions([self.__activateAct], 'ui')
69 menu = self.__ui.getMenu("subwindow")
70 menu.addAction(self.__activateAct)
71
72 def deactivate(self):
73 """
74 Public method to deactivate the time tracker.
75 """
76 menu = self.__ui.getMenu("subwindow")
77 menu.removeAction(self.__activateAct)
78 self.__ui.removeE5Actions([self.__activateAct], 'ui')
79 self.__ui.removeSideWidget(self.__widget)
80
81 def getAppIcon(self, name):
82 """
83 Public method to get an icon.
84
85 @param name name of the icon file (string)
86 @return icon (QIcon)
87 """
88 return UI.PixmapCache.getIcon(os.path.join(
89 os.path.dirname(__file__), "icons", name))
90
91 def __activateWidget(self):
92 """
93 Private slot to handle the activation of the project browser.
94 """
95 uiLayoutType = self.__ui.getLayoutType()
96 if uiLayoutType == "Toolboxes":
97 self.__ui.hToolboxDock.show()
98 self.__ui.hToolbox.setCurrentWidget(self.__widget)
99 elif uiLayoutType == "Sidebars":
100 self.__ui.bottomSidebar.show()
101 self.__ui.bottomSidebar.setCurrentWidget(self.__widget)
102 else:
103 self.__widget.show()
104 self.__widget.setFocus(Qt.ActiveWindowFocusReason)

eric ide

mercurial