Wed, 30 Nov 2022 17:56:36 +0100
First incarnation of the CORBA IDL support plugin, that was an integral part of eric7 previously.
# -*- coding: utf-8 -*- # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module documentation goes here. """ import os from PyQt6.QtCore import QCoreApplication, QObject, QTranslator from eric7 import Globals, Preferences from eric7.EricWidgets import EricMessageBox from eric7.EricWidgets.EricApplication import ericApp 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.0.0" 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 exe = corbaExtensionPluginObject.getPreferences("omniidl") if not exe: exe = "omniidl" if Globals.isWindowsPlatform(): exe += ".exe" data = { "programEntry": True, "header": "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", "preferences-orbit-{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 """ global corbaExtensionPluginObject from ExtensionCorba.ConfigurationPage.CorbaPage import CorbaPage page = CorbaPage(corbaExtensionPluginObject) return page def prepareUninstall(): """ Module function to prepare for an un-installation. """ Preferences.getSettings().remove(CorbaExtensionPlugin.PreferencesKey) class CorbaExtensionPlugin(QObject): """ Class documentation goes here. """ PreferencesKey = "Corba" def __init__(self, ui): """ Constructor @param ui reference to the user interface object @type UI.UserInterface """ super(CorbaExtensionPlugin, self).__init__(ui) self.__ui = ui self.__initialize() self.__defaults = { "omniidl": "", } def __initialize(self): """ Private slot to (re)initialize the plugin. """ self.__browser = None def activate(self): """ Public method to activate this plug-in. @return tuple of None and activation status @rtype bool """ global error, corbaExtensionPluginObject error = "" # clear previous error if self.__ui.versionIsNewer("22.12"): corbaExtensionPluginObject = self self.__browser = ProjectInterfacesBrowser(self) 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. """ 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)