--- a/src/eric7/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py Fri Jan 05 16:04:03 2024 +0100 +++ b/src/eric7/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py Sat Jan 06 15:21:02 2024 +0100 @@ -7,6 +7,7 @@ Module implementing the Editor Highlighting Styles configuration page. """ +import enum import pathlib from PyQt6.QtCore import QFile, QIODevice, Qt, pyqtSlot @@ -31,6 +32,17 @@ from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage +class FontChangeMode(enum.Enum): + """ + Class defining the modes for font changes. + """ + + FAMILYONLY = 0 + SIZEONLY = 1 + FAMILYANDSIZE = 2 + FONT = 99 + + class EditorHighlightingStylesPage( ConfigurationPageBase, Ui_EditorHighlightingStylesPage ): @@ -38,12 +50,6 @@ Class implementing the Editor Highlighting Styles configuration page. """ - # TODO: change this to an enum - FAMILYONLY = 0 - SIZEONLY = 1 - FAMILYANDSIZE = 2 - FONT = 99 - StyleRole = Qt.ItemDataRole.UserRole + 1 SubstyleRole = Qt.ItemDataRole.UserRole + 2 @@ -66,27 +72,27 @@ self.__fontButtonMenu = QMenu() act = self.__fontButtonMenu.addAction(self.tr("Font")) - act.setData(self.FONT) + act.setData(FontChangeMode.FONT) self.__fontButtonMenu.addSeparator() act = self.__fontButtonMenu.addAction(self.tr("Family and Size only")) - act.setData(self.FAMILYANDSIZE) + act.setData(FontChangeMode.FAMILYANDSIZE) act = self.__fontButtonMenu.addAction(self.tr("Family only")) - act.setData(self.FAMILYONLY) + act.setData(FontChangeMode.FAMILYONLY) act = self.__fontButtonMenu.addAction(self.tr("Size only")) - act.setData(self.SIZEONLY) + act.setData(FontChangeMode.SIZEONLY) self.__fontButtonMenu.triggered.connect(self.__fontButtonMenuTriggered) self.fontButton.setMenu(self.__fontButtonMenu) self.__allFontsButtonMenu = QMenu() act = self.__allFontsButtonMenu.addAction(self.tr("Font")) - act.setData(self.FONT) + act.setData(FontChangeMode.FONT) self.__allFontsButtonMenu.addSeparator() act = self.__allFontsButtonMenu.addAction(self.tr("Family and Size only")) - act.setData(self.FAMILYANDSIZE) + act.setData(FontChangeMode.FAMILYANDSIZE) act = self.__allFontsButtonMenu.addAction(self.tr("Family only")) - act.setData(self.FAMILYONLY) + act.setData(FontChangeMode.FAMILYONLY) act = self.__allFontsButtonMenu.addAction(self.tr("Size only")) - act.setData(self.SIZEONLY) + act.setData(FontChangeMode.SIZEONLY) self.__allFontsButtonMenu.triggered.connect(self.__allFontsButtonMenuTriggered) self.allFontsButton.setMenu(self.__allFontsButtonMenu) @@ -424,8 +430,11 @@ if act is None: return - familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY] - sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] + familyOnly = act.data() in ( + FontChangeMode.FAMILYANDSIZE, + FontChangeMode.FAMILYONLY, + ) + sizeOnly = act.data() in (FontChangeMode.FAMILYANDSIZE, FontChangeMode.SIZEONLY) self.__changeFont(False, familyOnly, sizeOnly) def __allFontsButtonMenuTriggered(self, act): @@ -438,8 +447,11 @@ if act is None: return - familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY] - sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] + familyOnly = act.data() in ( + FontChangeMode.FAMILYANDSIZE, + FontChangeMode.FAMILYONLY, + ) + sizeOnly = act.data() in (FontChangeMode.FAMILYANDSIZE, FontChangeMode.SIZEONLY) self.__changeFont(True, familyOnly, sizeOnly) @pyqtSlot(bool)