Sat, 31 Dec 2022 16:27:42 +0100
Updated copyright for 2023.
# -*- coding: utf-8 -*- # Copyright (c) 2022 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a plugin to add support for CORBA development. """ import os from PyQt6.QtCore import QCoreApplication, QObject, QTranslator from eric7 import Preferences from eric7.EricWidgets import EricMessageBox from eric7.EricWidgets.EricApplication import ericApp from eric7.SystemUtilities import OSUtilities from ExtensionCorba import idlclbr from ExtensionCorba.ProjectInterfacesBrowser import ProjectInterfacesBrowser # Start-Of-Header name = "Corba Extension Plugin" author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True version = "10.1.4" className = "CorbaExtensionPlugin" packageName = "ExtensionCorba" shortDescription = "Support for the development of CORBA projects" longDescription = ( "This plugin adds support for the development of CORBA related projects." ) needsRestart = False pyqtApi = 2 # End-Of-Header error = "" corbaExtensionPluginObject = None def exeDisplayData(): """ Module function to support the display of some executable info. @return dictionary containing the data to query the presence of the executable @rtype dict """ global corbaExtensionPluginObject if corbaExtensionPluginObject is None: data = { "programEntry": False, "header": QCoreApplication.translate( "CorbaExtensionPlugin", "CORBA IDL Compiler" ), "text": QCoreApplication.translate( "CorbaExtensionPlugin", "CORBA Support plugin is not activated" ), "version": QCoreApplication.translate("CorbaExtensionPlugin", "(inactive)"), } else: exe = corbaExtensionPluginObject.getPreferences("omniidl") if not exe: exe = "omniidl" if OSUtilities.isWindowsPlatform(): exe += ".exe" data = { "programEntry": True, "header": QCoreApplication.translate( "CorbaExtensionPlugin", "CORBA IDL Compiler" ), "exe": exe, "versionCommand": "-V", "versionStartsWith": "omniidl", "versionRe": "", "versionPosition": -1, "version": "", "versionCleanup": None, "exeModule": None, } return data def getConfigData(): """ Module function returning data as required by the configuration dialog. @return dictionary containing the relevant data @rtype dict """ iconSuffix = "dark" if ericApp().usesDarkPalette() else "light" return { "corbaPage": [ QCoreApplication.translate("CorbaExtensionPlugin", "CORBA"), os.path.join("ExtensionCorba", "icons", "corba-{0}".format(iconSuffix)), createCorbaPage, None, None, ], } def createCorbaPage(configDlg): """ Module function to create the CORBA configuration page. @param configDlg reference to the configuration dialog @type ConfigurationWidget @return reference to the configuration page @rtype CorbaPage """ from ExtensionCorba.ConfigurationPage.CorbaPage import CorbaPage global corbaExtensionPluginObject page = CorbaPage(corbaExtensionPluginObject) return page def prepareUninstall(): """ Module function to prepare for an un-installation. """ Preferences.getSettings().remove(CorbaExtensionPlugin.PreferencesKey) class CorbaExtensionPlugin(QObject): """ Class implementing a plugin to add support for CORBA development. """ PreferencesKey = "Corba" def __init__(self, ui): """ Constructor @param ui reference to the user interface object @type UI.UserInterface """ super().__init__(ui) self.__ui = ui self.__initialize() self.__defaults = { "omniidl": "", } self.__translator = None self.__loadTranslator() def __initialize(self): """ Private slot to (re)initialize the plugin. """ global corbaExtensionPluginObject corbaExtensionPluginObject = None self.__browser = None def activate(self): """ Public method to activate this plug-in. @return tuple of None and activation status @rtype bool """ from eric7.QScintilla import Lexers from eric7.Utilities import ClassBrowsers global error, corbaExtensionPluginObject error = "" # clear previous error if self.__ui.versionIsNewer("22.12"): corbaExtensionPluginObject = self self.__browser = ProjectInterfacesBrowser(self) iconSuffix = "dark" if ericApp().usesDarkPalette() else "light" Lexers.registerLexer( "IDL", self.tr("IDL"), "dummy.idl", self.getLexer, [self.tr("Corba IDL Files (*.idl)")], [self.tr("Corba IDL Files (*.idl)")], ["*.idl"], os.path.join("ExtensionCorba", "icons", "corba-{0}".format(iconSuffix)), ) ClassBrowsers.registerClassBrowser( "IDL", idlclbr.readmodule_ex, idlclbr.scan, self.getFileIcon, [".idl"] ) return None, True else: EricMessageBox.warning( self.__ui, self.tr("CORBA Extension"), self.tr( "The CORBA extension cannot be activated because it requires eric7" " 23.1 or newer." ), ) error = self.tr( "The CORBA extension cannot be activated because it requires eric7" " 23.1 or newer." ) return None, False def deactivate(self): """ Public method to deactivate this plug-in. """ from eric7.QScintilla import Lexers from eric7.Utilities import ClassBrowsers Lexers.unregisterLexer("IDL") ClassBrowsers.unregisterClassBrowser("IDL") self.__browser.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__), "ExtensionCorba", "i18n" ) translation = "corba_{0}".format(loc) translator = QTranslator(None) loaded = translator.load(translation, locale_dir) if loaded: self.__translator = translator ericApp().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 settings values. @param key the key of the value to get @type str @return the requested setting value @rtype any """ return Preferences.Prefs.settings.value( self.PreferencesKey + "/" + key, self.__defaults[key] ) def setPreferences(self, key, value): """ Public method to store the various settings values. @param key the key of the setting to be set @type str @param value the value to be set @type any """ Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value) def getLexer(self, parent=None): """ Public method to instantiate a QScintilla CORBA IDL lexer object. @param parent reference to the parent object @type QObject @return reference to the instanciated lexer object @rtype QsciLexer """ from ExtensionCorba.LexerIDL import LexerIDL return LexerIDL(parent=parent) def getFileIcon(self, filename=""): """ Public method to get the name of a file icon. @param filename file name (defaults to "") @type str (optional) @return name of a file icon @rtype str """ iconSuffix = "dark" if ericApp().usesDarkPalette() else "light" return os.path.join("ExtensionCorba", "icons", "corba-{0}".format(iconSuffix)) # # eflag: noqa = M801