diff -r f95dde35d0ab -r 0090cfa83159 eric6/Preferences/ConfigurationDialog.py --- a/eric6/Preferences/ConfigurationDialog.py Mon Apr 26 17:33:08 2021 +0200 +++ b/eric6/Preferences/ConfigurationDialog.py Tue Apr 27 17:25:06 2021 +0200 @@ -7,9 +7,10 @@ Module implementing a dialog for the configuration of eric. """ +import contextlib +import enum import os import types -import contextlib from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QMetaObject, QRect from PyQt5.QtGui import QPixmap @@ -61,6 +62,16 @@ return self.__pageName +class ConfigurationMode(enum.Enum): + """ + Class defining the various modes of the configuration widget. + """ + DEFAULTMODE = 0 + TRAYSTARTERMODE = 1 + HEXEDITORMODE = 2 + WEBBROWSERMODE = 3 + + class ConfigurationWidget(QWidget): """ Class implementing a dialog for the configuration of eric. @@ -76,36 +87,24 @@ accepted = pyqtSignal() rejected = pyqtSignal() - # TODO: convert this to 'enum' - DefaultMode = 0 - TrayStarterMode = 1 - HexEditorMode = 2 - WebBrowserMode = 3 - - def __init__(self, parent=None, fromEric=True, displayMode=DefaultMode, + def __init__(self, parent=None, fromEric=True, + displayMode=ConfigurationMode.DEFAULTMODE, expandedEntries=None): """ Constructor - @param parent The parent widget of this dialog. (QWidget) + @param parent reference to the parent widget + @type QWidget @param fromEric flag indicating a dialog generation from within the - eric ide (boolean) + eric IDE + @type bool @param displayMode mode of the configuration dialog - (DefaultMode, TrayStarterMode, HexEditorMode, WebBrowserMode) - @exception RuntimeError raised to indicate an invalid dialog mode + @type ConfigurationMode @param expandedEntries list of entries to be shown expanded - (list of strings) + @type list of str """ super().__init__(parent) - if displayMode not in ( - ConfigurationWidget.DefaultMode, - ConfigurationWidget.WebBrowserMode, - ConfigurationWidget.TrayStarterMode, - ConfigurationWidget.HexEditorMode, - ): - raise RuntimeError("Illegal mode value: {0}".format(displayMode)) - self.fromEric = fromEric self.displayMode = displayMode self.__webEngine = getWebBrowserSupport() == "QtWebEngine" @@ -131,7 +130,7 @@ e5App().registerObject("VirtualEnvManager", self.virtualenvManager) - if displayMode == ConfigurationWidget.DefaultMode: + if displayMode == ConfigurationMode.DEFAULTMODE: self.configItems = { # key : [display string, pixmap name, dialog module name or # page creation function, parent key, @@ -368,7 +367,7 @@ self.configItems.update( e5App().getObject("PluginManager").getPluginConfigData()) - elif displayMode == ConfigurationWidget.WebBrowserMode: + elif displayMode == ConfigurationMode.WEBBROWSERMODE: self.configItems = { # key : [display string, pixmap name, dialog module name or # page creation function, parent key, @@ -411,7 +410,7 @@ "WebBrowserSpellCheckingPage", None, None], } - elif displayMode == ConfigurationWidget.TrayStarterMode: + elif displayMode == ConfigurationMode.TRAYSTARTERMODE: self.configItems = { # key : [display string, pixmap name, dialog module name or # page creation function, parent key, @@ -424,7 +423,7 @@ "TrayStarterPage", None, None], } - elif displayMode == ConfigurationWidget.HexEditorMode: + elif displayMode == ConfigurationMode.HEXEDITORMODE: self.configItems = { # key : [display string, pixmap name, dialog module name or # page creation function, parent key, @@ -451,9 +450,11 @@ self.itmDict[key] = ConfigurationPageItem(pitm, pageData[0], key, pageData[1]) self.itmDict[key].setData(0, Qt.ItemDataRole.UserRole, key) - if (not self.fromEric or - displayMode != ConfigurationWidget.DefaultMode or - key in expandedEntries): + if ( + not self.fromEric or + displayMode != ConfigurationMode.DEFAULTMODE or + key in expandedEntries + ): self.itmDict[key].setExpanded(True) self.configList.sortByColumn(0, Qt.SortOrder.AscendingOrder) @@ -466,13 +467,13 @@ self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.rejected) - if displayMode in [ConfigurationWidget.TrayStarterMode, - ConfigurationWidget.HexEditorMode, - ConfigurationWidget.WebBrowserMode]: + if displayMode in [ConfigurationMode.TRAYSTARTERMODE, + ConfigurationMode.HEXEDITORMODE, + ConfigurationMode.WEBBROWSERMODE]: self.configListSearch.hide() - if displayMode not in [ConfigurationWidget.TrayStarterMode, - ConfigurationWidget.HexEditorMode]: + if displayMode not in [ConfigurationMode.TRAYSTARTERMODE, + ConfigurationMode.HEXEDITORMODE]: self.__initLexers() def accept(self): @@ -571,7 +572,7 @@ self.buttonBox.setObjectName("buttonBox") if ( not self.fromEric and - self.displayMode == ConfigurationWidget.DefaultMode + self.displayMode == ConfigurationMode.DEFAULTMODE ): self.buttonBox.button(QDialogButtonBox.StandardButton.Apply).hide() self.buttonBox.button( @@ -904,7 +905,7 @@ """ return ( self.__webEngine or - self.displayMode == ConfigurationWidget.WebBrowserMode + self.displayMode == ConfigurationMode.WEBBROWSERMODE ) @@ -919,26 +920,26 @@ preferencesChanged = pyqtSignal() masterPasswordChanged = pyqtSignal(str, str) - DefaultMode = ConfigurationWidget.DefaultMode - TrayStarterMode = ConfigurationWidget.TrayStarterMode - HexEditorMode = ConfigurationWidget.HexEditorMode - WebBrowserMode = ConfigurationWidget.WebBrowserMode - def __init__(self, parent=None, name=None, modal=False, - fromEric=True, displayMode=ConfigurationWidget.DefaultMode, + fromEric=True, + displayMode=ConfigurationMode.DEFAULTMODE, expandedEntries=None): """ Constructor - @param parent The parent widget of this dialog. (QWidget) - @param name The name of this dialog. string - @param modal Flag indicating a modal dialog. (boolean) + @param parent reference to the parent widget + @type QWidget + @param name name of the dialog + @type str + @param modal flag indicating a modal dialog + @type bool @param fromEric flag indicating a dialog generation from within the - eric ide (boolean) + eric IDE + @type bool @param displayMode mode of the configuration dialog - (DefaultMode, TrayStarterMode, HexEditorMode, WebBrowserMode) + @type ConfigurationMode @param expandedEntries list of entries to be shown expanded - (list of strings) + @type list of str """ super().__init__(parent) if name: