--- a/PluginProjectKivy.py Sat Dec 31 16:27:50 2022 +0100 +++ b/PluginProjectKivy.py Sat Sep 09 17:43:15 2023 +0200 @@ -7,6 +7,7 @@ Module implementing the Kivy project plug-in. """ +import contextlib import fnmatch import glob import os @@ -16,13 +17,14 @@ from eric7 import Preferences from eric7.EricWidgets.EricApplication import ericApp +from eric7.QScintilla import Lexers, TypingCompleters # Start-of-Header name = "Kivy Project Plugin" author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "10.2.1" +version = "10.3.0" className = "ProjectKivyPlugin" packageName = "ProjectKivy" shortDescription = "Project support for Kivy projects." @@ -50,11 +52,20 @@ return [] +def prepareUninstall(): + """ + Module function to prepare for an uninstallation. + """ + Preferences.Prefs.settings.remove(ProjectKivyPlugin.PreferencesKey) + + class ProjectKivyPlugin(QObject): """ Class implementing the Kivy project plugin. """ + PreferencesKey = "Kivy" + lexerAssociations = { "*.kv": "Pygments|Kivy", "*.kivy": "Pygments|Kivy", @@ -80,6 +91,17 @@ self.__ui = ui self.__initialize() + self.__typingDefaults = { + "EnabledTypingAids": True, + "InsertClosingBrace": True, + "SkipBrace": True, + "InsertQuote": True, + "AutoIndentation": True, + "ColonDetection": True, + "InsertBlankColon": True, + "InsertBlankComma": True, + } + self.__translator = None self.__loadTranslator() @@ -96,8 +118,6 @@ @return tuple of None and activation status @rtype bool """ - from eric7.QScintilla import Lexers - self.__ericProject.registerProjectType( "Kivy", self.tr("Kivy"), @@ -108,7 +128,7 @@ try: # backward compatibility for eric7 < 22.12 - from eric7.Project.ProjectBrowser import ( + from eric7.Project.ProjectBrowser import ( # noqa: I101 FormsBrowserFlag, OthersBrowserFlag, SourcesBrowserFlag, @@ -139,15 +159,25 @@ ["*.kv", "*.kivy"], ) + with contextlib.suppress(AttributeError): + # Typing Completer (eric7 > 23.9) + TypingCompleters.registerCompleter( + language="Pygments|Kivy", + createCompleterFunction=self.createTypingCompleter, + createConfigPageFunction=self.createTypingCompleterConfigWidget, + ) + return None, True def deactivate(self): """ Public method to deactivate this plugin. """ - from eric7.QScintilla import Lexers + self.__ericProject.unregisterProjectType("Kivy") - self.__ericProject.unregisterProjectType("Kivy") + with contextlib.suppress(AttributeError): + # Typing Completer (eric7 > 23.9) + TypingCompleters.unregisterTypingCompleter("Pygments|Kivy") Lexers.unregisterLexer("Pygments|Kivy") if self.KivyLexerKey in LEXERS: @@ -228,6 +258,61 @@ else: return None + def getTypingPreferences(self, key): + """ + Public method to retrieve the typing completer settings. + + @param key the key of the value to get + @type str + @return value of the requested setting + @rtype Any + """ + return Preferences.toBool( + Preferences.Prefs.settings.value( + f"{self.PreferencesKey}/Typing/{key}", self.__typingDefaults[key] + ) + ) + + def setTypingPreferences(self, key, value): + """ + Public method to store the typing completer settings. + + @param key the key of the setting to be set + @type str + @param value value to be set + @type Any + """ + Preferences.Prefs.settings.setValue( + f"{self.PreferencesKey}/Typing/{key}", value + ) + + def createTypingCompleter(self, editor, parent=None): + """ + Public method to create a typing completer object for the given editor. + + @param editor reference to the editor object + @type Editor + @param parent reference to the parent object (defaults to None) + @type QObject (optional) + @return reference to the instantiated typing completer object + @rtype CompleterKivy + """ + from ProjectKivy.CompleterKivy import CompleterKivy + + return CompleterKivy(self, editor, parent) + + def createTypingCompleterConfigWidget(self): + """ + Public method to create and populate the typing completer configuration widget. + + @return instantiated and populated configuration widget + @rtype CompleterKivyConfigWidget + """ + from ProjectKivy.CompleterKivyConfigWidget import CompleterKivyConfigWidget + + widget = CompleterKivyConfigWidget(self) + return widget + # -# eflag: noqa = M801, M811 +# eflag: noqa = M801, M811, U200