src/eric7/Plugins/UiExtensionPlugins/Translator/Translator.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
19 19
20 class Translator(QObject): 20 class Translator(QObject):
21 """ 21 """
22 Class implementing the translator object. 22 Class implementing the translator object.
23 """ 23 """
24
24 def __init__(self, plugin, usesDarkPalette, parent=None): 25 def __init__(self, plugin, usesDarkPalette, parent=None):
25 """ 26 """
26 Constructor 27 Constructor
27 28
28 @param plugin reference to the plugin object 29 @param plugin reference to the plugin object
29 @type TranslatorPlugin 30 @type TranslatorPlugin
30 @param usesDarkPalette flag indicating that the platform uses a palette 31 @param usesDarkPalette flag indicating that the platform uses a palette
31 with a dark background 32 with a dark background
32 @type bool 33 @type bool
33 @param parent parent 34 @param parent parent
34 @type QObject 35 @type QObject
35 """ 36 """
36 QObject.__init__(self, parent) 37 QObject.__init__(self, parent)
37 38
38 self.__plugin = plugin 39 self.__plugin = plugin
39 self.__ui = parent 40 self.__ui = parent
40 41
41 self.__widget = None 42 self.__widget = None
42 43
43 if usesDarkPalette: 44 if usesDarkPalette:
44 self.__iconSuffix = "dark" 45 self.__iconSuffix = "dark"
45 else: 46 else:
46 self.__iconSuffix = "light" 47 self.__iconSuffix = "light"
47 48
48 def activate(self): 49 def activate(self):
49 """ 50 """
50 Public method to activate the translator. 51 Public method to activate the translator.
51 """ 52 """
52 from .TranslatorWidget import TranslatorWidget 53 from .TranslatorWidget import TranslatorWidget
53 54
54 self.__widget = TranslatorWidget(self.__plugin, self) 55 self.__widget = TranslatorWidget(self.__plugin, self)
55 iconName = ( 56 iconName = (
56 "sbTranslator96" 57 "sbTranslator96"
57 if self.__ui.getLayoutType() == "Sidebars" else 58 if self.__ui.getLayoutType() == "Sidebars"
58 "flag-{0}".format(self.__iconSuffix) 59 else "flag-{0}".format(self.__iconSuffix)
59 ) 60 )
60 self.__ui.addSideWidget( 61 self.__ui.addSideWidget(
61 self.__ui.BottomSide, self.__widget, 62 self.__ui.BottomSide,
63 self.__widget,
62 UI.PixmapCache.getIcon( 64 UI.PixmapCache.getIcon(
63 os.path.join(os.path.dirname(__file__), "icons", iconName)), 65 os.path.join(os.path.dirname(__file__), "icons", iconName)
64 self.tr("Translator")) 66 ),
65 67 self.tr("Translator"),
68 )
69
66 self.__activateAct = EricAction( 70 self.__activateAct = EricAction(
67 self.tr('Translator'), 71 self.tr("Translator"),
68 self.tr('T&ranslator'), 72 self.tr("T&ranslator"),
69 QKeySequence(self.tr("Alt+Shift+R")), 73 QKeySequence(self.tr("Alt+Shift+R")),
70 0, self, 74 0,
71 'translator_activate') 75 self,
72 self.__activateAct.setStatusTip(self.tr( 76 "translator_activate",
73 "Switch the input focus to the Translator window.")) 77 )
74 self.__activateAct.setWhatsThis(self.tr( 78 self.__activateAct.setStatusTip(
75 """<b>Activate Translator</b>""" 79 self.tr("Switch the input focus to the Translator window.")
76 """<p>This switches the input focus to the Translator""" 80 )
77 """ window.</p>""" 81 self.__activateAct.setWhatsThis(
78 )) 82 self.tr(
83 """<b>Activate Translator</b>"""
84 """<p>This switches the input focus to the Translator"""
85 """ window.</p>"""
86 )
87 )
79 self.__activateAct.triggered.connect(self.__activateWidget) 88 self.__activateAct.triggered.connect(self.__activateWidget)
80 89
81 self.__ui.addEricActions([self.__activateAct], 'ui') 90 self.__ui.addEricActions([self.__activateAct], "ui")
82 menu = self.__ui.getMenu("subwindow") 91 menu = self.__ui.getMenu("subwindow")
83 menu.addAction(self.__activateAct) 92 menu.addAction(self.__activateAct)
84 93
85 def deactivate(self): 94 def deactivate(self):
86 """ 95 """
87 Public method to deactivate the time tracker. 96 Public method to deactivate the time tracker.
88 """ 97 """
89 menu = self.__ui.getMenu("subwindow") 98 menu = self.__ui.getMenu("subwindow")
90 menu.removeAction(self.__activateAct) 99 menu.removeAction(self.__activateAct)
91 self.__ui.removeEricActions([self.__activateAct], 'ui') 100 self.__ui.removeEricActions([self.__activateAct], "ui")
92 self.__ui.removeSideWidget(self.__widget) 101 self.__ui.removeSideWidget(self.__widget)
93 102
94 def getAppIcon(self, name): 103 def getAppIcon(self, name):
95 """ 104 """
96 Public method to get an icon. 105 Public method to get an icon.
97 106
98 @param name name of the icon file 107 @param name name of the icon file
99 @type str 108 @type str
100 @return icon 109 @return icon
101 @rtype QIcon 110 @rtype QIcon
102 """ 111 """
103 return UI.PixmapCache.getIcon(os.path.join( 112 return UI.PixmapCache.getIcon(
104 os.path.dirname(__file__), "icons", 113 os.path.join(
105 "{0}-{1}".format(name, self.__iconSuffix) 114 os.path.dirname(__file__),
106 )) 115 "icons",
107 116 "{0}-{1}".format(name, self.__iconSuffix),
117 )
118 )
119
108 def __activateWidget(self): 120 def __activateWidget(self):
109 """ 121 """
110 Private slot to handle the activation of the project browser. 122 Private slot to handle the activation of the project browser.
111 """ 123 """
112 uiLayoutType = self.__ui.getLayoutType() 124 uiLayoutType = self.__ui.getLayoutType()

eric ide

mercurial