5 |
5 |
6 """ |
6 """ |
7 Module implementing the Kivy project plug-in. |
7 Module implementing the Kivy project plug-in. |
8 """ |
8 """ |
9 |
9 |
|
10 import contextlib |
10 import fnmatch |
11 import fnmatch |
11 import glob |
12 import glob |
12 import os |
13 import os |
13 |
14 |
14 from pygments.lexers._mapping import LEXERS |
15 from pygments.lexers._mapping import LEXERS |
15 from PyQt6.QtCore import QObject, QTranslator |
16 from PyQt6.QtCore import QObject, QTranslator |
16 |
17 |
17 from eric7 import Preferences |
18 from eric7 import Preferences |
18 from eric7.EricWidgets.EricApplication import ericApp |
19 from eric7.EricWidgets.EricApplication import ericApp |
|
20 from eric7.QScintilla import Lexers, TypingCompleters |
19 |
21 |
20 # Start-of-Header |
22 # Start-of-Header |
21 name = "Kivy Project Plugin" |
23 name = "Kivy Project Plugin" |
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
23 autoactivate = True |
25 autoactivate = True |
24 deactivateable = True |
26 deactivateable = True |
25 version = "10.2.1" |
27 version = "10.3.0" |
26 className = "ProjectKivyPlugin" |
28 className = "ProjectKivyPlugin" |
27 packageName = "ProjectKivy" |
29 packageName = "ProjectKivy" |
28 shortDescription = "Project support for Kivy projects." |
30 shortDescription = "Project support for Kivy projects." |
29 longDescription = """This plugin implements project support for Kivy projects.""" |
31 longDescription = """This plugin implements project support for Kivy projects.""" |
30 needsRestart = False |
32 needsRestart = False |
48 return glob.glob(os.path.join(apisDir, "*.api")) |
50 return glob.glob(os.path.join(apisDir, "*.api")) |
49 else: |
51 else: |
50 return [] |
52 return [] |
51 |
53 |
52 |
54 |
|
55 def prepareUninstall(): |
|
56 """ |
|
57 Module function to prepare for an uninstallation. |
|
58 """ |
|
59 Preferences.Prefs.settings.remove(ProjectKivyPlugin.PreferencesKey) |
|
60 |
|
61 |
53 class ProjectKivyPlugin(QObject): |
62 class ProjectKivyPlugin(QObject): |
54 """ |
63 """ |
55 Class implementing the Kivy project plugin. |
64 Class implementing the Kivy project plugin. |
56 """ |
65 """ |
|
66 |
|
67 PreferencesKey = "Kivy" |
57 |
68 |
58 lexerAssociations = { |
69 lexerAssociations = { |
59 "*.kv": "Pygments|Kivy", |
70 "*.kv": "Pygments|Kivy", |
60 "*.kivy": "Pygments|Kivy", |
71 "*.kivy": "Pygments|Kivy", |
61 } |
72 } |
78 """ |
89 """ |
79 QObject.__init__(self, ui) |
90 QObject.__init__(self, ui) |
80 self.__ui = ui |
91 self.__ui = ui |
81 self.__initialize() |
92 self.__initialize() |
82 |
93 |
|
94 self.__typingDefaults = { |
|
95 "EnabledTypingAids": True, |
|
96 "InsertClosingBrace": True, |
|
97 "SkipBrace": True, |
|
98 "InsertQuote": True, |
|
99 "AutoIndentation": True, |
|
100 "ColonDetection": True, |
|
101 "InsertBlankColon": True, |
|
102 "InsertBlankComma": True, |
|
103 } |
|
104 |
83 self.__translator = None |
105 self.__translator = None |
84 self.__loadTranslator() |
106 self.__loadTranslator() |
85 |
107 |
86 def __initialize(self): |
108 def __initialize(self): |
87 """ |
109 """ |
94 Public method to activate this plugin. |
116 Public method to activate this plugin. |
95 |
117 |
96 @return tuple of None and activation status |
118 @return tuple of None and activation status |
97 @rtype bool |
119 @rtype bool |
98 """ |
120 """ |
99 from eric7.QScintilla import Lexers |
|
100 |
|
101 self.__ericProject.registerProjectType( |
121 self.__ericProject.registerProjectType( |
102 "Kivy", |
122 "Kivy", |
103 self.tr("Kivy"), |
123 self.tr("Kivy"), |
104 self.fileTypesCallback, |
124 self.fileTypesCallback, |
105 lexerAssociationCallback=self.lexerAssociationCallback, |
125 lexerAssociationCallback=self.lexerAssociationCallback, |
106 progLanguages=["Python3"], |
126 progLanguages=["Python3"], |
107 ) |
127 ) |
108 |
128 |
109 try: |
129 try: |
110 # backward compatibility for eric7 < 22.12 |
130 # backward compatibility for eric7 < 22.12 |
111 from eric7.Project.ProjectBrowser import ( |
131 from eric7.Project.ProjectBrowser import ( # noqa: I101 |
112 FormsBrowserFlag, |
132 FormsBrowserFlag, |
113 OthersBrowserFlag, |
133 OthersBrowserFlag, |
114 SourcesBrowserFlag, |
134 SourcesBrowserFlag, |
115 TranslationsBrowserFlag, |
135 TranslationsBrowserFlag, |
116 ) |
136 ) |
137 [self.tr("Kivy Files (*.kv *.kivy)")], |
157 [self.tr("Kivy Files (*.kv *.kivy)")], |
138 [self.tr("Kivy Files (*.kv)")], |
158 [self.tr("Kivy Files (*.kv)")], |
139 ["*.kv", "*.kivy"], |
159 ["*.kv", "*.kivy"], |
140 ) |
160 ) |
141 |
161 |
|
162 with contextlib.suppress(AttributeError): |
|
163 # Typing Completer (eric7 > 23.9) |
|
164 TypingCompleters.registerCompleter( |
|
165 language="Pygments|Kivy", |
|
166 createCompleterFunction=self.createTypingCompleter, |
|
167 createConfigPageFunction=self.createTypingCompleterConfigWidget, |
|
168 ) |
|
169 |
142 return None, True |
170 return None, True |
143 |
171 |
144 def deactivate(self): |
172 def deactivate(self): |
145 """ |
173 """ |
146 Public method to deactivate this plugin. |
174 Public method to deactivate this plugin. |
147 """ |
175 """ |
148 from eric7.QScintilla import Lexers |
|
149 |
|
150 self.__ericProject.unregisterProjectType("Kivy") |
176 self.__ericProject.unregisterProjectType("Kivy") |
|
177 |
|
178 with contextlib.suppress(AttributeError): |
|
179 # Typing Completer (eric7 > 23.9) |
|
180 TypingCompleters.unregisterTypingCompleter("Pygments|Kivy") |
151 |
181 |
152 Lexers.unregisterLexer("Pygments|Kivy") |
182 Lexers.unregisterLexer("Pygments|Kivy") |
153 if self.KivyLexerKey in LEXERS: |
183 if self.KivyLexerKey in LEXERS: |
154 del LEXERS[self.KivyLexerKey] |
184 del LEXERS[self.KivyLexerKey] |
155 |
185 |
226 if lexer.canStyle(): |
256 if lexer.canStyle(): |
227 return lexer |
257 return lexer |
228 else: |
258 else: |
229 return None |
259 return None |
230 |
260 |
|
261 def getTypingPreferences(self, key): |
|
262 """ |
|
263 Public method to retrieve the typing completer settings. |
|
264 |
|
265 @param key the key of the value to get |
|
266 @type str |
|
267 @return value of the requested setting |
|
268 @rtype Any |
|
269 """ |
|
270 return Preferences.toBool( |
|
271 Preferences.Prefs.settings.value( |
|
272 f"{self.PreferencesKey}/Typing/{key}", self.__typingDefaults[key] |
|
273 ) |
|
274 ) |
|
275 |
|
276 def setTypingPreferences(self, key, value): |
|
277 """ |
|
278 Public method to store the typing completer settings. |
|
279 |
|
280 @param key the key of the setting to be set |
|
281 @type str |
|
282 @param value value to be set |
|
283 @type Any |
|
284 """ |
|
285 Preferences.Prefs.settings.setValue( |
|
286 f"{self.PreferencesKey}/Typing/{key}", value |
|
287 ) |
|
288 |
|
289 def createTypingCompleter(self, editor, parent=None): |
|
290 """ |
|
291 Public method to create a typing completer object for the given editor. |
|
292 |
|
293 @param editor reference to the editor object |
|
294 @type Editor |
|
295 @param parent reference to the parent object (defaults to None) |
|
296 @type QObject (optional) |
|
297 @return reference to the instantiated typing completer object |
|
298 @rtype CompleterKivy |
|
299 """ |
|
300 from ProjectKivy.CompleterKivy import CompleterKivy |
|
301 |
|
302 return CompleterKivy(self, editor, parent) |
|
303 |
|
304 def createTypingCompleterConfigWidget(self): |
|
305 """ |
|
306 Public method to create and populate the typing completer configuration widget. |
|
307 |
|
308 @return instantiated and populated configuration widget |
|
309 @rtype CompleterKivyConfigWidget |
|
310 """ |
|
311 from ProjectKivy.CompleterKivyConfigWidget import CompleterKivyConfigWidget |
|
312 |
|
313 widget = CompleterKivyConfigWidget(self) |
|
314 return widget |
|
315 |
231 |
316 |
232 # |
317 # |
233 # eflag: noqa = M801, M811 |
318 # eflag: noqa = M801, M811, U200 |