--- a/src/eric7/Preferences/ConfigurationPages/DiffColoursPage.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Preferences/ConfigurationPages/DiffColoursPage.py Wed Jul 13 14:55:47 2022 +0200 @@ -20,6 +20,7 @@ """ Class implementing the Diff colours configuration page. """ + def __init__(self): """ Constructor @@ -27,9 +28,9 @@ super().__init__() self.setupUi(self) self.setObjectName("DiffColoursPage") - + self.__coloursDict = {} - + monospacedFont = Preferences.getEditorOtherFonts("MonospacedFont") self.__allSamples = ( self.textSample, @@ -38,67 +39,73 @@ self.replacedSample, self.contextSample, self.headerSample, - self.whitespaceSample + self.whitespaceSample, ) for sample in self.__allSamples: sample.setFont(monospacedFont) - + # set initial values self.__initColour( "TextColor", self.textButton, self.__updateSampleTextColour, lambda: self.__selectTextColour(self.textButton), - self.textSample) + self.textSample, + ) self.__initColour( "AddedColor", self.addedButton, self.__updateSampleBackgroundColour, lambda: self.__selectBackgroundColour(self.addedButton), - self.addedSample) + self.addedSample, + ) self.__initColour( "RemovedColor", self.removedButton, self.__updateSampleBackgroundColour, lambda: self.__selectBackgroundColour(self.removedButton), - self.removedSample) + self.removedSample, + ) self.__initColour( "ReplacedColor", self.replacedButton, self.__updateSampleBackgroundColour, lambda: self.__selectBackgroundColour(self.replacedButton), - self.replacedSample) + self.replacedSample, + ) self.__initColour( "ContextColor", self.contextButton, self.__updateSampleBackgroundColour, lambda: self.__selectBackgroundColour(self.contextButton), - self.contextSample) + self.contextSample, + ) self.__initColour( "HeaderColor", self.headerButton, self.__updateSampleBackgroundColour, lambda: self.__selectBackgroundColour(self.headerButton), - self.headerSample) + self.headerSample, + ) self.__initColour( "BadWhitespaceColor", self.whitespaceButton, self.__updateSampleBackgroundColour, lambda: self.__selectBackgroundColour(self.whitespaceButton), - self.whitespaceSample) - + self.whitespaceSample, + ) + def save(self): """ Public slot to save the Diff colours configuration. """ for key in self.__coloursDict: Preferences.setDiffColour(key, self.__coloursDict[key][0]) - - def __initColour(self, colourKey, button, initSlot, selectSlot, - sampleWidget): + + def __initColour(self, colourKey, button, initSlot, selectSlot, sampleWidget): """ Private method to initialize a colour selection button. - + @param colourKey key of the diff colour @type str @param button reference to the button @@ -116,44 +123,47 @@ self.__coloursDict[colourKey] = [colour, sampleWidget] if initSlot: initSlot(colourKey) - + @pyqtSlot() def __selectTextColour(self, button): """ Private slot to select the text colour. - + @param button reference to the button been pressed @type QPushButton """ colorKey = button.property("colorKey") - + colour = QColorDialog.getColor(self.__coloursDict[colorKey][0], self) if colour.isValid(): self.__coloursDict[colorKey][0] = colour self.__updateSampleTextColour(colorKey) - + @pyqtSlot() def __selectBackgroundColour(self, button): """ Private slot to select a background colour. - + @param button reference to the button been pressed @type QPushButton """ colorKey = button.property("colorKey") - + colour = QColorDialog.getColor( - self.__coloursDict[colorKey][0], self, "", - QColorDialog.ColorDialogOption.ShowAlphaChannel) + self.__coloursDict[colorKey][0], + self, + "", + QColorDialog.ColorDialogOption.ShowAlphaChannel, + ) if colour.isValid(): self.__coloursDict[colorKey][0] = colour self.__updateSampleBackgroundColour(colorKey) - + @pyqtSlot() def __updateSampleTextColour(self, colourKey): """ Private slot to update the text colour of all samples. - + @param colourKey key of the diff colour @type str """ @@ -165,14 +175,15 @@ ) else: self.__coloursDict[key][1].setStyleSheet( - "QLineEdit {{ color: {0}; background-color: {1}; }}" - .format(colour.name(), self.__coloursDict[key][0].name()) + "QLineEdit {{ color: {0}; background-color: {1}; }}".format( + colour.name(), self.__coloursDict[key][0].name() + ) ) - + def __updateSampleBackgroundColour(self, colourKey): """ Private slot to update the background colour of a sample. - + @param colourKey key of the diff colour @type str """ @@ -180,16 +191,16 @@ if sample: colour = self.__coloursDict[colourKey][0] sample.setStyleSheet( - "QLineEdit {{ color: {0}; background-color: {1}; }}" - .format(self.__coloursDict["TextColor"][0].name(), - colour.name()) + "QLineEdit {{ color: {0}; background-color: {1}; }}".format( + self.__coloursDict["TextColor"][0].name(), colour.name() + ) ) def create(dlg): """ Module function to create the configuration page. - + @param dlg reference to the configuration dialog @return reference to the instantiated page (ConfigurationPageBase) """