eric6/E5Gui/E5TextEditSearchWidget.py

changeset 8268
6b8128e0c9d1
parent 8257
28146736bbfc
child 8273
698ae46f40a4
equal deleted inserted replaced
8267:6baca884c73a 8268:6b8128e0c9d1
4 # 4 #
5 5
6 """ 6 """
7 Module implementing a horizontal search widget for QTextEdit. 7 Module implementing a horizontal search widget for QTextEdit.
8 """ 8 """
9
10 import enum
9 11
10 from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QSize 12 from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QSize
11 from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor 13 from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor
12 from PyQt5.QtWidgets import ( 14 from PyQt5.QtWidgets import (
13 QWidget, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QCheckBox, 15 QWidget, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QCheckBox,
17 from E5Gui.E5ComboBox import E5ClearableComboBox 19 from E5Gui.E5ComboBox import E5ClearableComboBox
18 20
19 import UI.PixmapCache 21 import UI.PixmapCache
20 22
21 23
24 class E5TextEditType(enum.Enum):
25 """
26 Class defining the supported text edit types.
27 """
28 UNKNOWN = 0
29 QTEXTEDIT = 1
30 QTEXTBROWSER = 2
31 QWEBENGINEVIEW = 3
32
33
22 class E5TextEditSearchWidget(QWidget): 34 class E5TextEditSearchWidget(QWidget):
23 """ 35 """
24 Class implementing a horizontal search widget for QTextEdit. 36 Class implementing a horizontal search widget for QTextEdit.
25 """ 37 """
26 def __init__(self, parent=None, widthForHeight=True): 38 def __init__(self, parent=None, widthForHeight=True):
36 """ 48 """
37 super().__init__(parent) 49 super().__init__(parent)
38 self.__setupUi(widthForHeight) 50 self.__setupUi(widthForHeight)
39 51
40 self.__textedit = None 52 self.__textedit = None
41 self.__texteditType = "" 53 self.__texteditType = E5TextEditType.UNKNOWN
42 self.__findBackwards = True 54 self.__findBackwards = True
43 55
44 self.__defaultBaseColor = ( 56 self.__defaultBaseColor = (
45 self.findtextCombo.lineEdit().palette().color( 57 self.findtextCombo.lineEdit().palette().color(
46 QPalette.ColorRole.Base) 58 QPalette.ColorRole.Base)
177 self.verticalLayout.insertLayout(1, self.horizontalLayout2) 189 self.verticalLayout.insertLayout(1, self.horizontalLayout2)
178 self.__widthForHeightLayoutIndex = 1 190 self.__widthForHeightLayoutIndex = 1
179 191
180 self.__widthForHeight = widthForHeight 192 self.__widthForHeight = widthForHeight
181 193
182 def attachTextEdit(self, textedit, editType="QTextEdit"): 194 def attachTextEdit(self, textedit, editType=E5TextEditType.QTEXTEDIT):
183 """ 195 """
184 Public method to attach a QTextEdit widget. 196 Public method to attach a QTextEdit widget.
185 197
186 @param textedit reference to the edit widget to be attached 198 @param textedit reference to the edit widget to be attached
187 @type QTextEdit, QWebEngineView or QWebView 199 @type QTextEdit, QWebEngineView or QWebView
188 @param editType type of the attached edit widget 200 @param editType type of the attached edit widget
189 @type str (one of "QTextEdit", "QWebEngineView" or "QWebView") 201 @type E5TextEditType
190 @exception ValueError raised to indicate a bad parameter value 202 """
191 """
192 if editType not in ["QTextEdit", "QWebEngineView", "QWebView"]:
193 raise ValueError("Bad value for 'editType' parameter.")
194
195 self.__textedit = textedit 203 self.__textedit = textedit
196 self.__texteditType = editType 204 self.__texteditType = editType
197 205
198 self.wordCheckBox.setVisible(editType == "QTextEdit") 206 self.wordCheckBox.setVisible(editType == "QTextEdit")
199 207
273 self.findHistory.remove(txt) 281 self.findHistory.remove(txt)
274 self.findHistory.insert(0, txt) 282 self.findHistory.insert(0, txt)
275 self.findtextCombo.clear() 283 self.findtextCombo.clear()
276 self.findtextCombo.addItems(self.findHistory) 284 self.findtextCombo.addItems(self.findHistory)
277 285
278 if self.__texteditType == "QTextEdit": 286 if self.__texteditType in (
287 E5TextEditType.QTEXTBROWSER, E5TextEditType.QTEXTEDIT
288 ):
279 ok = self.__findPrevNextQTextEdit(backwards) 289 ok = self.__findPrevNextQTextEdit(backwards)
280 self.__findNextPrevCallback(ok) 290 self.__findNextPrevCallback(ok)
281 elif self.__texteditType == "QWebEngineView": 291 elif self.__texteditType == E5TextEditType.QWEBENGINEVIEW:
282 self.__findPrevNextQWebEngineView(backwards) 292 self.__findPrevNextQWebEngineView(backwards)
283 293
284 def __findPrevNextQTextEdit(self, backwards): 294 def __findPrevNextQTextEdit(self, backwards):
285 """ 295 """
286 Private method to to search the associated edit widget of 296 Private method to to search the associated edit widget of

eric ide

mercurial