7 Module implementing the Eric assistant plugin. |
7 Module implementing the Eric assistant plugin. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication |
12 from PyQt6.QtCore import QObject, QTranslator, QCoreApplication |
13 |
13 |
14 from E5Gui.E5Application import e5App |
14 from EricWidgets.EricApplication import ericApp |
15 |
15 |
16 import Preferences |
16 import Preferences |
17 |
17 |
18 from AssistantEric.Assistant import AcsAPIs, AcsProject |
18 from AssistantEric.Assistant import AcsAPIs, AcsProject |
19 |
19 |
20 # Start-Of-Header |
20 # Start-Of-Header |
21 name = "Assistant Eric Plugin" |
21 name = "Assistant Eric Plugin" |
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
23 autoactivate = True |
23 autoactivate = True |
24 deactivateable = True |
24 deactivateable = True |
25 version = "5.3.0" |
25 version = "1.0.0" |
26 className = "AssistantEricPlugin" |
26 className = "AssistantEricPlugin" |
27 packageName = "AssistantEric" |
27 packageName = "AssistantEric" |
28 shortDescription = "Alternative autocompletion and calltips provider." |
28 shortDescription = "Alternative autocompletion and calltips provider." |
29 longDescription = ( |
29 longDescription = ( |
30 """This plugin implements an alternative autocompletion and""" |
30 """This plugin implements an alternative autocompletion and""" |
42 def createAutoCompletionPage(configDlg): |
42 def createAutoCompletionPage(configDlg): |
43 """ |
43 """ |
44 Module function to create the autocompletion configuration page. |
44 Module function to create the autocompletion configuration page. |
45 |
45 |
46 @param configDlg reference to the configuration dialog |
46 @param configDlg reference to the configuration dialog |
|
47 @type ConfigurationWidget |
47 @return reference to the configuration page |
48 @return reference to the configuration page |
|
49 @rtype QWidget |
48 """ |
50 """ |
49 global assistantEricPluginObject |
51 global assistantEricPluginObject |
50 from AssistantEric.ConfigurationPages.AutoCompletionEricPage import ( |
52 from AssistantEric.ConfigurationPages.AutoCompletionEricPage import ( |
51 AutoCompletionEricPage |
53 AutoCompletionEricPage |
52 ) |
54 ) |
53 return AutoCompletionEricPage(assistantEricPluginObject) |
55 return AutoCompletionEricPage(assistantEricPluginObject) |
54 |
56 |
55 |
57 |
56 def createCallTipsPage(configDlg): |
58 def createCallTipsPage(configDlg): |
57 """ |
59 """ |
58 Module function to create the calltips configuration page. |
60 Module function to create the calltips configuration page. |
59 |
61 |
60 @param configDlg reference to the configuration dialog |
62 @param configDlg reference to the configuration dialog |
|
63 @type ConfigurationWidget |
61 @return reference to the configuration page |
64 @return reference to the configuration page |
|
65 @rtype QWidget |
62 """ |
66 """ |
63 global assistantEricPluginObject |
67 global assistantEricPluginObject |
64 from AssistantEric.ConfigurationPages.CallTipsEricPage import ( |
68 from AssistantEric.ConfigurationPages.CallTipsEricPage import ( |
65 CallTipsEricPage |
69 CallTipsEricPage |
66 ) |
70 ) |
67 return CallTipsEricPage(assistantEricPluginObject) |
71 return CallTipsEricPage(assistantEricPluginObject) |
68 |
72 |
69 |
73 |
70 def getConfigData(): |
74 def getConfigData(): |
71 """ |
75 """ |
72 Module function returning data as required by the configuration dialog. |
76 Module function returning data as required by the configuration dialog. |
73 |
77 |
74 @return dictionary containing the relevant data |
78 @return dictionary containing the relevant data |
|
79 @rtype dict |
75 """ |
80 """ |
76 try: |
81 try: |
77 usesDarkPalette = e5App().usesDarkPalette() |
82 usesDarkPalette = ericApp().usesDarkPalette() |
78 except AttributeError: |
83 except AttributeError: |
79 from PyQt5.QtGui import QPalette |
84 from PyQt6.QtGui import QPalette |
80 palette = e5App().palette() |
85 palette = ericApp().palette() |
81 lightness = palette.color(QPalette.ColorRole.Window).lightness() |
86 lightness = palette.color(QPalette.ColorRole.Window).lightness() |
82 usesDarkPalette = lightness <= 128 |
87 usesDarkPalette = lightness <= 128 |
83 iconSuffix = "dark" if usesDarkPalette else "light" |
88 iconSuffix = "dark" if usesDarkPalette else "light" |
84 |
89 |
85 return { |
90 return { |
139 |
145 |
140 def __checkQSql(self): |
146 def __checkQSql(self): |
141 """ |
147 """ |
142 Private method to perform some checks on QSql. |
148 Private method to perform some checks on QSql. |
143 |
149 |
144 @return flag indicating QSql is ok (boolean) |
150 @return flag indicating QSql is ok |
|
151 @rtype bool |
145 """ |
152 """ |
146 global error |
153 global error |
147 |
154 |
148 try: |
155 try: |
149 from PyQt5.QtSql import QSqlDatabase |
156 from PyQt6.QtSql import QSqlDatabase |
150 except ImportError: |
157 except ImportError: |
151 error = self.tr("PyQt5.QtSql is not available.") |
158 error = self.tr("PyQt6.QtSql is not available.") |
152 return False |
159 return False |
153 |
160 |
154 drivers = QSqlDatabase.drivers() |
161 drivers = QSqlDatabase.drivers() |
155 if "QSQLITE" not in drivers: |
162 if "QSQLITE" not in drivers: |
156 error = self.tr("The SQLite database driver is not available.") |
163 error = self.tr("The SQLite database driver is not available.") |
174 assistantEricPluginObject = self |
182 assistantEricPluginObject = self |
175 |
183 |
176 from AssistantEric.Assistant import Assistant |
184 from AssistantEric.Assistant import Assistant |
177 |
185 |
178 self.__object = Assistant(self, self.__ui) |
186 self.__object = Assistant(self, self.__ui) |
179 e5App().registerPluginObject("AssistantEric", self.__object) |
187 ericApp().registerPluginObject("AssistantEric", self.__object) |
180 |
188 |
181 self.__object.activate() |
189 self.__object.activate() |
182 |
190 |
183 return None, True |
191 return None, True |
184 |
192 |
185 def deactivate(self): |
193 def deactivate(self): |
186 """ |
194 """ |
187 Public method to deactivate this plugin. |
195 Public method to deactivate this plugin. |
188 """ |
196 """ |
189 e5App().unregisterPluginObject("AssistantEric") |
197 ericApp().unregisterPluginObject("AssistantEric") |
190 |
198 |
191 self.__object.deactivate() |
199 self.__object.deactivate() |
192 |
200 |
193 self.__initialize() |
201 self.__initialize() |
194 |
202 |
204 translation = "assistant_{0}".format(loc) |
212 translation = "assistant_{0}".format(loc) |
205 translator = QTranslator(None) |
213 translator = QTranslator(None) |
206 loaded = translator.load(translation, locale_dir) |
214 loaded = translator.load(translation, locale_dir) |
207 if loaded: |
215 if loaded: |
208 self.__translator = translator |
216 self.__translator = translator |
209 e5App().installTranslator(self.__translator) |
217 ericApp().installTranslator(self.__translator) |
210 else: |
218 else: |
211 print("Warning: translation file '{0}' could not be" |
219 print("Warning: translation file '{0}' could not be" |
212 " loaded.".format(translation)) |
220 " loaded.".format(translation)) |
213 print("Using default.") |
221 print("Using default.") |
214 |
222 |
215 def getPreferences(self, key): |
223 def getPreferences(self, key): |
216 """ |
224 """ |
217 Public method to retrieve the various refactoring settings. |
225 Public method to retrieve the various settings. |
218 |
226 |
219 @param key the key of the value to get |
227 @param key the key of the value to get |
220 @return the requested refactoring setting |
228 @type str |
|
229 @return value of the requested setting |
|
230 @rtype Any |
221 """ |
231 """ |
222 if key in ["AutoCompletionEnabled", "AutoCompletionFollowHierarchy", |
232 if key in ["AutoCompletionEnabled", "AutoCompletionFollowHierarchy", |
223 "CalltipsEnabled", "CallTipsContextShown", |
233 "CalltipsEnabled", "CallTipsContextShown", |
224 "CallTipsFollowHierarchy"]: |
234 "CallTipsFollowHierarchy"]: |
225 return Preferences.toBool(Preferences.Prefs.settings.value( |
235 return Preferences.toBool(Preferences.Prefs.settings.value( |
228 return int(Preferences.Prefs.settings.value( |
238 return int(Preferences.Prefs.settings.value( |
229 self.PreferencesKey + "/" + key, self.__defaults[key])) |
239 self.PreferencesKey + "/" + key, self.__defaults[key])) |
230 |
240 |
231 def setPreferences(self, key, value): |
241 def setPreferences(self, key, value): |
232 """ |
242 """ |
233 Public method to store the various refactoring settings. |
243 Public method to store the various settings. |
234 |
244 |
235 @param key the key of the setting to be set (string) |
245 @param key the key of the setting to be set |
236 @param value the value to be set |
246 @type str |
|
247 @param value value to be set |
|
248 @type Any |
237 """ |
249 """ |
238 Preferences.Prefs.settings.setValue( |
250 Preferences.Prefs.settings.setValue( |
239 self.PreferencesKey + "/" + key, value) |
251 self.PreferencesKey + "/" + key, value) |
240 |
252 |
241 if key in ["AutoCompletionEnabled", "CalltipsEnabled"]: |
253 if key in ["AutoCompletionEnabled", "CalltipsEnabled"]: |