Mon, 24 Jun 2024 15:22:19 +0200
Implemented the basic skeleton for the pipx Interface plugin.
# -*- coding: utf-8 -*- # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the pipx Interface plug-in. """ import os import sysconfig from PyQt6.QtCore import QCoreApplication, QObject, QTranslator from eric7 import Preferences from eric7.EricWidgets.EricApplication import ericApp from eric7.SystemUtilities import OSUtilities # Start-Of-Header __header__ = { "name": "pipx Interface", "author": "Detlev Offenbach <detlev@die-offenbachs.de>", "autoactivate": True, "deactivateable": True, "version": "10.0.0", "className": "PluginPipxInterface", "packageName": "PipxInterface", "shortDescription": "Graphical interface to the 'pipx' command.", "longDescription": ( "Plugin implementing widgets and dialogues to interact with the various pipx" " commands and to start pipx managed applications from within the eric-ide." ), "needsRestart": False, "pyqtApi": 2, } # End-Of-Header error = "" # noqa: U200 pipxInterfacePluginObject = 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 """ pipx = os.path.join(sysconfig.get_path("scripts"), "pipx") if OSUtilities.isWindowsPlatform(): pipx += ".exe" data = { "programEntry": True, "header": QCoreApplication.translate( "PluginPipxInterface", "PyPI Application Management" ), "exe": pipx, "versionCommand": "--version", "versionStartsWith": "", "versionRe": None, "versionPosition": -1, "version": "", "versionCleanup": None, "exeModule": None, } return data def createPipxPage( _configDlg, ): """ Module function to create the autocompletion configuration page. @param _configDlg reference to the configuration dialog (unused) @type ConfigurationWidget @return reference to the configuration page @rtype AutoCompletionRopePage """ global pipxInterfacePluginObject from PipxInterface.ConfigurationPage.PipxPage import PipxPage # noqa: I101 page = PipxPage(pipxInterfacePluginObject) return page def getConfigData(): """ Module function returning data as required by the configuration dialog. @return dictionary containing the relevant data @rtype dict """ return { "pipxPage": [ QCoreApplication.translate( "PluginPipxInterface", "Python Application Management" ), os.path.join("PipxInterface", "icons", "pipx22"), createPipxPage, None, None, ], } def prepareUninstall(): """ Module function to prepare for an un-installation. """ Preferences.getSettings().remove(PluginPipxInterface.PreferencesKey) class PluginPipxInterface(QObject): """ Class documentation goes here. """ PreferencesKey = "Pipx" 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 = { # TODO: fill this dictionary with preferences default values } self.__translator = None self.__loadTranslator() def __initialize(self): """ Private slot to (re)initialize the plugin. """ self.__widget = None def activate(self): """ Public method to activate this plug-in. @return tuple of None and activation status @rtype bool """ global error error = "" # clear previous error return None, True def deactivate(self): """ Public method to deactivate this plug-in. """ pass 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__), "PipxInterface", "i18n" ) translation = "pipx_{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 None 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 """ pass def installDependencies(pipInstall): """ Function to install dependencies of this plug-in. @param pipInstall function to be called with a list of package names. @type function """ try: import pipx # __IGNORE_WARNING__ except ImportError: pipInstall(["pipx>=1.5.0"]) # # eflag: noqa = M801, U200