Sat, 06 Mar 2021 15:54:30 +0100
Changed the enum handling.
# -*- coding: utf-8 -*- # Copyright (c) 2008 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the Eric assistant plugin. """ from __future__ import unicode_literals import os from PyQt5.QtCore import QObject, QTranslator, QCoreApplication from E5Gui.E5Application import e5App import Preferences from AssistantEric.Assistant import AcsAPIs, AcsProject # Start-Of-Header name = "Assistant Eric Plugin" author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True version = "5.2.0" className = "AssistantEricPlugin" packageName = "AssistantEric" shortDescription = "Alternative autocompletion and calltips provider." longDescription = ( """This plugin implements an alternative autocompletion and""" """ calltips provider.""" ) needsRestart = True pyqtApi = 2 # End-Of-Header error = "" assistantEricPluginObject = None def createAutoCompletionPage(configDlg): """ Module function to create the autocompletion configuration page. @param configDlg reference to the configuration dialog @return reference to the configuration page """ global assistantEricPluginObject from AssistantEric.ConfigurationPages.AutoCompletionEricPage import ( AutoCompletionEricPage ) return AutoCompletionEricPage(assistantEricPluginObject) def createCallTipsPage(configDlg): """ Module function to create the calltips configuration page. @param configDlg reference to the configuration dialog @return reference to the configuration page """ global assistantEricPluginObject from AssistantEric.ConfigurationPages.CallTipsEricPage import ( CallTipsEricPage ) return CallTipsEricPage(assistantEricPluginObject) def getConfigData(): """ Module function returning data as required by the configuration dialog. @return dictionary containing the relevant data """ try: usesDarkPalette = e5App().usesDarkPalette() except AttributeError: from PyQt5.QtGui import QPalette palette = e5App().palette() lightness = palette.color(QPalette.ColorRole.Window).lightness() usesDarkPalette = lightness <= 128 if usesDarkPalette: iconSuffix = "dark" else: iconSuffix = "light" return { "ericAutoCompletionPage": [ QCoreApplication.translate("AssistantEricPlugin", "Eric"), os.path.join("AssistantEric", "ConfigurationPages", "eric-{0}".format(iconSuffix)), createAutoCompletionPage, "editorAutocompletionPage", None], "ericCallTipsPage": [ QCoreApplication.translate("AssistantEricPlugin", "Eric"), os.path.join("AssistantEric", "ConfigurationPages", "eric-{0}".format(iconSuffix)), createCallTipsPage, "editorCalltipsPage", None], } def prepareUninstall(): """ Module function to prepare for an uninstallation. """ Preferences.Prefs.settings.remove(AssistantEricPlugin.PreferencesKey) class AssistantEricPlugin(QObject): """ Class implementing the Eric assistant plugin. """ PreferencesKey = "AssistantEric" def __init__(self, ui): """ Constructor @param ui reference to the user interface object (UI.UserInterface) """ QObject.__init__(self, ui) self.__ui = ui self.__initialize() self.__defaults = { "AutoCompletionEnabled": False, "AutoCompletionSource": AcsAPIs | AcsProject, "AutoCompletionFollowHierarchy": False, "CalltipsEnabled": False, "CallTipsContextShown": True, "CallTipsFollowHierarchy": False, } self.__translator = None self.__loadTranslator() def __initialize(self): """ Private slot to (re)initialize the plugin. """ self.__object = None def __checkQSql(self): """ Private method to perform some checks on QSql. @return flag indicating QSql is ok (boolean) """ global error try: from PyQt5.QtSql import QSqlDatabase except ImportError: error = self.tr("PyQt5.QtSql is not available.") return False drivers = QSqlDatabase.drivers() if "QSQLITE" not in drivers: error = self.tr("The SQLite database driver is not available.") return False return True def activate(self): """ Public method to activate this plugin. @return tuple of None and activation status (boolean) """ global error error = "" # clear previous error if not self.__checkQSql(): return None, False global assistantEricPluginObject assistantEricPluginObject = self from AssistantEric.Assistant import Assistant self.__object = Assistant(self, self.__ui) e5App().registerPluginObject("AssistantEric", self.__object) self.__object.activate() return None, True def deactivate(self): """ Public method to deactivate this plugin. """ e5App().unregisterPluginObject("AssistantEric") self.__object.deactivate() self.__initialize() def __loadTranslator(self): """ Private method to load the translation file. """ if self.__ui is not None: loc = self.__ui.getLocale() if loc and loc != "C": locale_dir = os.path.join( os.path.dirname(__file__), "AssistantEric", "i18n") translation = "assistant_{0}".format(loc) translator = QTranslator(None) loaded = translator.load(translation, locale_dir) if loaded: self.__translator = translator e5App().installTranslator(self.__translator) else: print("Warning: translation file '{0}' could not be" " loaded.".format(translation)) print("Using default.") def getPreferences(self, key): """ Public method to retrieve the various refactoring settings. @param key the key of the value to get @return the requested refactoring setting """ if key in ["AutoCompletionEnabled", "AutoCompletionFollowHierarchy", "CalltipsEnabled", "CallTipsContextShown", "CallTipsFollowHierarchy"]: return Preferences.toBool(Preferences.Prefs.settings.value( self.PreferencesKey + "/" + key, self.__defaults[key])) else: return int(Preferences.Prefs.settings.value( self.PreferencesKey + "/" + key, self.__defaults[key])) def setPreferences(self, key, value): """ Public method to store the various refactoring settings. @param key the key of the setting to be set (string) @param value the value to be set """ Preferences.Prefs.settings.setValue( self.PreferencesKey + "/" + key, value) if key in ["AutoCompletionEnabled", "CalltipsEnabled"]: self.__object.setEnabled(key, value) # # eflag: noqa = M801