--- a/src/eric7/Plugins/PluginVcsMercurial.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Plugins/PluginVcsMercurial.py Wed Jul 13 14:55:47 2022 +0200 @@ -33,9 +33,7 @@ className = "VcsMercurialPlugin" packageName = "__core__" shortDescription = "Implements the Mercurial version control interface." -longDescription = ( - """This plugin provides the Mercurial version control interface.""" -) +longDescription = """This plugin provides the Mercurial version control interface.""" pyqtApi = 2 # End-Of-Header @@ -45,29 +43,30 @@ def exeDisplayData(): """ Public method to support the display of some executable info. - + @return dictionary containing the data to query the presence of the executable """ data = { "programEntry": True, "header": QCoreApplication.translate( - "VcsMercurialPlugin", "Version Control - Mercurial"), + "VcsMercurialPlugin", "Version Control - Mercurial" + ), "exe": getHgExecutable(), - "versionCommand": 'version', - "versionStartsWith": 'Mercurial', + "versionCommand": "version", + "versionStartsWith": "Mercurial", "versionPosition": -1, "version": "", "versionCleanup": (0, -1), } - + return data def getVcsSystemIndicator(): """ Public function to get the indicators for this version control system. - + @return dictionary with indicator as key and a tuple with the vcs name (string) and vcs display string (string) """ @@ -83,48 +82,52 @@ def displayString(): """ Public function to get the display string. - + @return display string (string) """ exe = getHgExecutable() if Utilities.isinpath(exe): - return QCoreApplication.translate('VcsMercurialPlugin', 'Mercurial') + return QCoreApplication.translate("VcsMercurialPlugin", "Mercurial") else: return "" + mercurialCfgPluginObject = None def createConfigurationPage(configDlg): """ Module function to create the configuration page. - + @param configDlg reference to the configuration dialog (QDialog) @return reference to the configuration page """ global mercurialCfgPluginObject - from VcsPlugins.vcsMercurial.ConfigurationPage.MercurialPage import ( - MercurialPage - ) + from VcsPlugins.vcsMercurial.ConfigurationPage.MercurialPage import MercurialPage + if mercurialCfgPluginObject is None: mercurialCfgPluginObject = VcsMercurialPlugin(None) page = MercurialPage(mercurialCfgPluginObject) return page - + def getConfigData(): """ Module function returning data as required by the configuration dialog. - + @return dictionary with key "zzz_mercurialPage" containing the relevant data """ return { - "zzz_mercurialPage": - [QCoreApplication.translate("VcsMercurialPlugin", "Mercurial"), - os.path.join("VcsPlugins", "vcsMercurial", "icons", - "preferences-mercurial.svg"), - createConfigurationPage, "vcsPage", None], + "zzz_mercurialPage": [ + QCoreApplication.translate("VcsMercurialPlugin", "Mercurial"), + os.path.join( + "VcsPlugins", "vcsMercurial", "icons", "preferences-mercurial.svg" + ), + createConfigurationPage, + "vcsPage", + None, + ], } @@ -132,8 +135,7 @@ """ Module function to prepare for an uninstallation. """ - if not ericApp().getObject("PluginManager").isPluginLoaded( - "PluginVcsMercurial"): + if not ericApp().getObject("PluginManager").isPluginLoaded("PluginVcsMercurial"): Preferences.getSettings().remove("Mercurial") @@ -143,12 +145,13 @@ """ for key in ["RepositoryUrlHistory"]: VcsMercurialPlugin.setPreferences(key, []) - + class VcsMercurialPlugin(QObject): """ Class implementing the Mercurial version control plugin. """ + MercurialDefaults = { "StopLogOnCopy": True, # used in log browser "LogLimit": 20, @@ -168,8 +171,7 @@ "LogMessageColumnWidth": 30, "LogBrowserShowFullLog": True, "LogBrowserGeometry": QByteArray(), - "LogBrowserSplitterStates": [QByteArray(), QByteArray(), - QByteArray()], + "LogBrowserSplitterStates": [QByteArray(), QByteArray(), QByteArray()], # mainSplitter, detailsSplitter, diffSplitter "StatusDialogGeometry": QByteArray(), "StatusDialogSplitterState": QByteArray(), @@ -178,27 +180,29 @@ "RepositoryUrlHistory": [], "MercurialExecutablePath": "", } - + def __init__(self, ui): """ Constructor - + @param ui reference to the user interface object (UI.UserInterface) """ super().__init__(ui) self.__ui = ui - + from VcsPlugins.vcsMercurial.ProjectHelper import HgProjectHelper + self.__projectHelperObject = HgProjectHelper(None, None) with contextlib.suppress(KeyError): ericApp().registerPluginObject( - pluginTypename, self.__projectHelperObject, pluginType) + pluginTypename, self.__projectHelperObject, pluginType + ) readShortcuts(pluginName=pluginTypename) - + def getProjectHelper(self): """ Public method to get a reference to the project helper object. - + @return reference to the project helper object """ return self.__projectHelperObject @@ -206,71 +210,95 @@ def initToolbar(self, ui, toolbarManager): """ Public slot to initialize the VCS toolbar. - + @param ui reference to the main window (UserInterface) @param toolbarManager reference to a toolbar manager object (EricToolBarManager) """ if self.__projectHelperObject: self.__projectHelperObject.initToolbar(ui, toolbarManager) - + def activate(self): """ Public method to activate this plugin. - + @return tuple of reference to instantiated viewmanager and activation status (boolean) """ from VcsPlugins.vcsMercurial.hg import Hg + self.__object = Hg(self, self.__ui) - + tb = self.__ui.getToolbar("vcs")[1] tb.setVisible(False) tb.setEnabled(False) - + tb = self.__ui.getToolbar("mercurial")[1] tb.setVisible(Preferences.getVCS("ShowVcsToolbar")) tb.setEnabled(True) - + return self.__object, True - + def deactivate(self): """ Public method to deactivate this plugin. """ self.__object = None - + tb = self.__ui.getToolbar("mercurial")[1] tb.setVisible(False) tb.setEnabled(False) - + tb = self.__ui.getToolbar("vcs")[1] tb.setVisible(Preferences.getVCS("ShowVcsToolbar")) tb.setEnabled(True) - + @classmethod def getPreferences(cls, key): """ Class method to retrieve the various settings. - + @param key the key of the value to get @return the requested setting """ - if key in ["StopLogOnCopy", "PullUpdate", "PreferUnbundle", - "CreateBackup", "InternalMerge", "ConsiderHidden", - "LogBrowserShowFullLog"]: - return Preferences.toBool(Preferences.getSettings().value( - "Mercurial/" + key, cls.MercurialDefaults[key])) - elif key in ["LogLimit", "CommitAuthorsLimit", "ServerPort", - "LogMessageColumnWidth"]: - return int(Preferences.getSettings().value( - "Mercurial/" + key, cls.MercurialDefaults[key])) + if key in [ + "StopLogOnCopy", + "PullUpdate", + "PreferUnbundle", + "CreateBackup", + "InternalMerge", + "ConsiderHidden", + "LogBrowserShowFullLog", + ]: + return Preferences.toBool( + Preferences.getSettings().value( + "Mercurial/" + key, cls.MercurialDefaults[key] + ) + ) + elif key in [ + "LogLimit", + "CommitAuthorsLimit", + "ServerPort", + "LogMessageColumnWidth", + ]: + return int( + Preferences.getSettings().value( + "Mercurial/" + key, cls.MercurialDefaults[key] + ) + ) elif key in ["Commits", "CommitAuthors", "RepositoryUrlHistory"]: - return Preferences.toList(Preferences.getSettings().value( - "Mercurial/" + key, cls.MercurialDefaults[key])) - elif key in ["LogBrowserGeometry", "StatusDialogGeometry", - "StatusDialogSplitterState", "MqStatusDialogGeometry", - "MqStatusDialogSplitterState"]: + return Preferences.toList( + Preferences.getSettings().value( + "Mercurial/" + key, cls.MercurialDefaults[key] + ) + ) + elif key in [ + "LogBrowserGeometry", + "StatusDialogGeometry", + "StatusDialogSplitterState", + "MqStatusDialogGeometry", + "MqStatusDialogSplitterState", + ]: # QByteArray values v = Preferences.getSettings().value("Mercurial/" + key) if v is not None: @@ -286,13 +314,14 @@ return cls.MercurialDefaults[key] else: return Preferences.getSettings().value( - "Mercurial/" + key, cls.MercurialDefaults[key]) - + "Mercurial/" + key, cls.MercurialDefaults[key] + ) + @classmethod def setPreferences(cls, key, value): """ Class method to store the various settings. - + @param key the key of the setting to be set @param value the value to be set """ @@ -301,45 +330,43 @@ def getGlobalOptions(self): """ Public method to build a list of global options. - + @return list of global options (list of string) """ args = [] - if ( - self.getPreferences("Encoding") != - self.MercurialDefaults["Encoding"] - ): + if self.getPreferences("Encoding") != self.MercurialDefaults["Encoding"]: args.append("--encoding") args.append(self.getPreferences("Encoding")) if ( - self.getPreferences("EncodingMode") != - self.MercurialDefaults["EncodingMode"] + self.getPreferences("EncodingMode") + != self.MercurialDefaults["EncodingMode"] ): args.append("--encodingmode") args.append(self.getPreferences("EncodingMode")) if self.getPreferences("ConsiderHidden"): args.append("--hidden") return args - + def getConfigPath(self): """ Public method to get the filename of the config file. - + @return filename of the config file (string) """ return getConfigPath() - + def prepareUninstall(self): """ Public method to prepare for an uninstallation. """ ericApp().unregisterPluginObject(pluginTypename) - + def prepareUnload(self): """ Public method to prepare for an unload. """ if self.__projectHelperObject: self.__projectHelperObject.removeToolbar( - self.__ui, ericApp().getObject("ToolbarManager")) + self.__ui, ericApp().getObject("ToolbarManager") + ) ericApp().unregisterPluginObject(pluginTypename)