--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PluginAssistantEric.py Sun Jan 17 19:22:18 2010 +0000 @@ -0,0 +1,229 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2008 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the Eric assistant plugin. +""" + +import sys +import os + +from PyQt4.QtCore import QObject, SIGNAL, QTranslator +from PyQt4.QtGui import QApplication + +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 = "2.0.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. + + @return reference to the configuration page + """ + global assistantEricPluginObject + from AssistantEric.ConfigurationPages.AutoCompletionEricPage \ + import AutoCompletionEricPage + page = AutoCompletionEricPage(assistantEricPluginObject) + return page + +def createCallTipsPage(configDlg): + """ + Module function to create the calltips configuration page. + + @return reference to the configuration page + """ + global assistantEricPluginObject + from AssistantEric.ConfigurationPages.CallTipsEricPage \ + import CallTipsEricPage + page = CallTipsEricPage(assistantEricPluginObject) + return page + +def getConfigData(): + """ + Module function returning data as required by the configuration dialog. + + @return dictionary containing the relevant data + """ + return { + "ericAutoCompletionPage" : \ + [QApplication.translate("AssistantEricPlugin", "Eric"), + os.path.join("AssistantEric", "ConfigurationPages", + "eric.png"), + createAutoCompletionPage, "editorAutocompletionPage", None], + "ericCallTipsPage" : \ + [QApplication.translate("AssistantEricPlugin", "Eric"), + os.path.join("AssistantEric", "ConfigurationPages", + "eric.png"), + createCallTipsPage, "editorCalltipsPage", None], + } + +def prepareUninstall(): + """ + Module function to prepare for an uninstallation. + """ + assistant = AssistantEricPlugin(None) + assistant.prepareUninstall() + +class AssistantEricPlugin(QObject): + """ + Class implementing the Eric assistant plugin. + """ + 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, + "CalltipsEnabled" : False, + "CallTipsContextShown" : 1, + } + + 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 PyQt4.QtSql import QSqlDatabase + except ImportError: + error = self.trUtf8("PyQt4.QtSql is not available.") + return False + + drivers = QSqlDatabase.drivers() + if "QSQLITE" in drivers: + return True + else: + error = self.trUtf8("The SQLite database driver is not available.") + return False + + 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_%s" % loc + translator = QTranslator(None) + loaded = translator.load(translation, locale_dir) + if loaded: + self.__translator = translator + e5App().installTranslator(self.__translator) + else: + print("Warning: translation file '%s' could not be loaded." % \ + 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 + @param prefClass preferences class used as the storage area + @return the requested refactoring setting + """ + if key in ["AutoCompletionEnabled", "CalltipsEnabled"]: + return Preferences.toBool(Preferences.Prefs.settings.value( + "AssistantEric/" + key, self.__defaults[key])) + else: + return int(Preferences.Prefs.settings.value("AssistantEric/" + 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 + @param prefClass preferences class used as the storage area + """ + Preferences.Prefs.settings.setValue("AssistantEric/" + key, value) + + if key in ["AutoCompletionEnabled", "CalltipsEnabled"]: + self.__object.setEnabled(key, value) + + def prepareUninstall(self): + """ + Public method to prepare for an uninstallation. + """ + Preferences.Prefs.settings.remove("AssistantEric") + \ No newline at end of file