PluginExtensionCorba.py

changeset 1
d4384e4d7aff
parent 0
02171512ef2f
child 2
68c017d640b0
equal deleted inserted replaced
0:02171512ef2f 1:d4384e4d7aff
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module documentation goes here.
8 """
9
10 import os
11
12 from PyQt6.QtCore import QCoreApplication, QObject, QTranslator
13
14 from eric7 import Globals, Preferences
15 from eric7.EricWidgets import EricMessageBox
16 from eric7.EricWidgets.EricApplication import ericApp
17 from ExtensionCorba.ProjectInterfacesBrowser import ProjectInterfacesBrowser
18
19 # Start-Of-Header
20 name = "Corba Extension Plugin"
21 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
22 autoactivate = True
23 deactivateable = True
24 version = "10.0.0"
25 className = "CorbaExtensionPlugin"
26 packageName = "ExtensionCorba"
27 shortDescription = "Support for the development of CORBA projects"
28 longDescription = (
29 "This plugin adds support for the development of CORBA related projects."
30 )
31 needsRestart = False
32 pyqtApi = 2
33 # End-Of-Header
34
35 error = ""
36
37 corbaExtensionPluginObject = None
38
39
40 def exeDisplayData():
41 """
42 Module function to support the display of some executable info.
43
44 @return dictionary containing the data to query the presence of
45 the executable
46 @rtype dict
47 """
48 global corbaExtensionPluginObject
49
50 exe = corbaExtensionPluginObject.getPreferences("omniidl")
51 if not exe:
52 exe = "omniidl"
53 if Globals.isWindowsPlatform():
54 exe += ".exe"
55
56 data = {
57 "programEntry": True,
58 "header": "CORBA IDL compiler",
59 "exe": exe,
60 "versionCommand": "-V",
61 "versionStartsWith": "omniidl",
62 "versionRe": "",
63 "versionPosition": -1,
64 "version": "",
65 "versionCleanup": None,
66 "exeModule": None,
67 }
68
69 return data
70
71
72 def getConfigData():
73 """
74 Module function returning data as required by the configuration dialog.
75
76 @return dictionary containing the relevant data
77 @rtype dict
78 """
79 iconSuffix = "dark" if ericApp().usesDarkPalette() else "light"
80
81 return {
82 "corbaPage": [
83 QCoreApplication.translate("CorbaExtensionPlugin", "CORBA"),
84 os.path.join(
85 "ExtensionCorba", "icons", "preferences-orbit-{0}".format(iconSuffix)
86 ),
87 createCorbaPage,
88 None,
89 None,
90 ],
91 }
92
93
94 def createCorbaPage(configDlg):
95 """
96 Module function to create the CORBA configuration page.
97
98 @param configDlg reference to the configuration dialog
99 @type ConfigurationWidget
100 @return reference to the configuration page
101 @rtype CorbaPage
102 """
103 global corbaExtensionPluginObject
104
105 from ExtensionCorba.ConfigurationPage.CorbaPage import CorbaPage
106
107 page = CorbaPage(corbaExtensionPluginObject)
108 return page
109
110
111 def prepareUninstall():
112 """
113 Module function to prepare for an un-installation.
114 """
115 Preferences.getSettings().remove(CorbaExtensionPlugin.PreferencesKey)
116
117
118 class CorbaExtensionPlugin(QObject):
119 """
120 Class documentation goes here.
121 """
122
123 PreferencesKey = "Corba"
124
125 def __init__(self, ui):
126 """
127 Constructor
128
129 @param ui reference to the user interface object
130 @type UI.UserInterface
131 """
132 super(CorbaExtensionPlugin, self).__init__(ui)
133 self.__ui = ui
134 self.__initialize()
135
136 self.__defaults = {
137 "omniidl": "",
138 }
139
140 def __initialize(self):
141 """
142 Private slot to (re)initialize the plugin.
143 """
144 self.__browser = None
145
146 def activate(self):
147 """
148 Public method to activate this plug-in.
149
150 @return tuple of None and activation status
151 @rtype bool
152 """
153 global error, corbaExtensionPluginObject
154 error = "" # clear previous error
155
156 if self.__ui.versionIsNewer("22.12"):
157 corbaExtensionPluginObject = self
158
159 self.__browser = ProjectInterfacesBrowser(self)
160
161 return None, True
162 else:
163 EricMessageBox.warning(
164 self.__ui,
165 self.tr("CORBA Extension"),
166 self.tr(
167 "The CORBA extension cannot be activated because it requires eric7"
168 " 23.1 or newer."
169 ),
170 )
171 error = self.tr(
172 "The CORBA extension cannot be activated because it requires eric7"
173 " 23.1 or newer."
174 )
175
176 return None, False
177
178 def deactivate(self):
179 """
180 Public method to deactivate this plug-in.
181 """
182 self.__initialize()
183
184 def __loadTranslator(self):
185 """
186 Private method to load the translation file.
187 """
188 if self.__ui is not None:
189 loc = self.__ui.getLocale()
190 if loc and loc != "C":
191 locale_dir = os.path.join(
192 os.path.dirname(__file__), "ExtensionCorba", "i18n"
193 )
194 translation = "corba_{0}".format(loc)
195 translator = QTranslator(None)
196 loaded = translator.load(translation, locale_dir)
197 if loaded:
198 self.__translator = translator
199 ericApp().installTranslator(self.__translator)
200 else:
201 print(
202 "Warning: translation file '{0}' could not be"
203 " loaded.".format(translation)
204 )
205 print("Using default.")
206
207 def getPreferences(self, key):
208 """
209 Public method to retrieve the various settings values.
210
211 @param key the key of the value to get
212 @type str
213 @return the requested setting value
214 @rtype any
215 """
216 return Preferences.Prefs.settings.value(
217 self.PreferencesKey + "/" + key, self.__defaults[key]
218 )
219
220 def setPreferences(self, key, value):
221 """
222 Public method to store the various settings values.
223
224 @param key the key of the setting to be set
225 @type str
226 @param value the value to be set
227 @type any
228 """
229 Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value)

eric ide

mercurial