eric6/E5Gui/E5TextEditSearchWidget.py

changeset 8268
6b8128e0c9d1
parent 8257
28146736bbfc
child 8273
698ae46f40a4
--- a/eric6/E5Gui/E5TextEditSearchWidget.py	Tue Apr 27 17:42:00 2021 +0200
+++ b/eric6/E5Gui/E5TextEditSearchWidget.py	Wed Apr 28 19:42:28 2021 +0200
@@ -7,6 +7,8 @@
 Module implementing a horizontal search widget for QTextEdit.
 """
 
+import enum
+
 from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QSize
 from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor
 from PyQt5.QtWidgets import (
@@ -19,6 +21,16 @@
 import UI.PixmapCache
 
 
+class E5TextEditType(enum.Enum):
+    """
+    Class defining the supported text edit types.
+    """
+    UNKNOWN = 0
+    QTEXTEDIT = 1
+    QTEXTBROWSER = 2
+    QWEBENGINEVIEW = 3
+
+
 class E5TextEditSearchWidget(QWidget):
     """
     Class implementing a horizontal search widget for QTextEdit.
@@ -38,7 +50,7 @@
         self.__setupUi(widthForHeight)
         
         self.__textedit = None
-        self.__texteditType = ""
+        self.__texteditType = E5TextEditType.UNKNOWN
         self.__findBackwards = True
         
         self.__defaultBaseColor = (
@@ -179,19 +191,15 @@
         
         self.__widthForHeight = widthForHeight
     
-    def attachTextEdit(self, textedit, editType="QTextEdit"):
+    def attachTextEdit(self, textedit, editType=E5TextEditType.QTEXTEDIT):
         """
         Public method to attach a QTextEdit widget.
         
         @param textedit reference to the edit widget to be attached
         @type QTextEdit, QWebEngineView or QWebView
         @param editType type of the attached edit widget
-        @type str (one of "QTextEdit", "QWebEngineView" or "QWebView")
-        @exception ValueError raised to indicate a bad parameter value
+        @type E5TextEditType
         """
-        if editType not in ["QTextEdit", "QWebEngineView", "QWebView"]:
-            raise ValueError("Bad value for 'editType' parameter.")
-        
         self.__textedit = textedit
         self.__texteditType = editType
         
@@ -275,10 +283,12 @@
         self.findtextCombo.clear()
         self.findtextCombo.addItems(self.findHistory)
         
-        if self.__texteditType == "QTextEdit":
+        if self.__texteditType in (
+            E5TextEditType.QTEXTBROWSER, E5TextEditType.QTEXTEDIT
+        ):
             ok = self.__findPrevNextQTextEdit(backwards)
             self.__findNextPrevCallback(ok)
-        elif self.__texteditType == "QWebEngineView":
+        elif self.__texteditType == E5TextEditType.QWEBENGINEVIEW:
             self.__findPrevNextQWebEngineView(backwards)
     
     def __findPrevNextQTextEdit(self, backwards):

eric ide

mercurial