diff -r fb0ef164f536 -r 698ae46f40a4 eric6/E5Gui/E5TextEditSearchWidget.py --- a/eric6/E5Gui/E5TextEditSearchWidget.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/E5Gui/E5TextEditSearchWidget.py Sat May 01 14:27:20 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. @@ -34,11 +46,11 @@ line. @type bool """ - super(E5TextEditSearchWidget, self).__init__(parent) + super().__init__(parent) 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): @@ -291,11 +301,11 @@ @return flag indicating the search result @rtype bool """ - if backwards: - flags = QTextDocument.FindFlags( - QTextDocument.FindFlag.FindBackward) - else: - flags = QTextDocument.FindFlags() + flags = ( + QTextDocument.FindFlags(QTextDocument.FindFlag.FindBackward) + if backwards else + QTextDocument.FindFlags() + ) if self.caseCheckBox.isChecked(): flags |= QTextDocument.FindFlag.FindCaseSensitively if self.wordCheckBox.isChecked():