src/eric7/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py

branch
eric7
changeset 10482
72d9b5ea39b4
parent 10475
ee41fab001f2
child 10595
59579e8aff98
--- 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)

eric ide

mercurial