src/eric7/EricWidgets/EricTextEditSearchWidget.py

branch
eric7
changeset 10795
89cfe35c12f9
parent 10439
21c28b0f9e41
child 10807
4bcd4e08418f
equal deleted inserted replaced
10794:cd93fbb75019 10795:89cfe35c12f9
183 self.setTabOrder(self.findtextCombo, self.caseCheckBox) 183 self.setTabOrder(self.findtextCombo, self.caseCheckBox)
184 self.setTabOrder(self.caseCheckBox, self.wordCheckBox) 184 self.setTabOrder(self.caseCheckBox, self.wordCheckBox)
185 self.setTabOrder(self.wordCheckBox, self.findPrevButton) 185 self.setTabOrder(self.wordCheckBox, self.findPrevButton)
186 self.setTabOrder(self.findPrevButton, self.findNextButton) 186 self.setTabOrder(self.findPrevButton, self.findNextButton)
187 187
188 self.__isActive = False # trace the activation state
189
188 def setWidthForHeight(self, widthForHeight): 190 def setWidthForHeight(self, widthForHeight):
189 """ 191 """
190 Public method to set the 'width for height'. 192 Public method to set the 'width for height'.
191 193
192 @param widthForHeight flag indicating to prefer width 194 @param widthForHeight flag indicating to prefer width
231 233
232 self.wordCheckBox.setVisible( 234 self.wordCheckBox.setVisible(
233 editType in (EricTextEditType.QTEXTEDIT, EricTextEditType.QTEXTBROWSER) 235 editType in (EricTextEditType.QTEXTEDIT, EricTextEditType.QTEXTBROWSER)
234 ) 236 )
235 self.infoLabel.setVisible(editType == EricTextEditType.QWEBENGINEVIEW) 237 self.infoLabel.setVisible(editType == EricTextEditType.QWEBENGINEVIEW)
236 if editType == EricTextEditType.QWEBENGINEVIEW:
237 self.__textedit.page().findTextFinished.connect(self.__findTextFinished)
238 238
239 def detachTextEdit(self): 239 def detachTextEdit(self):
240 """ 240 """
241 Public method to detach the current text edit. 241 Public method to detach the current text edit.
242 """ 242 """
243 if self.__texteditType == EricTextEditType.QWEBENGINEVIEW:
244 self.__textedit.page().findTextFinished.disconnect(self.__findTextFinished)
245
246 self.__textedit = None 243 self.__textedit = None
247 self.__texteditType = EricTextEditType.UNKNOWN 244 self.__texteditType = EricTextEditType.UNKNOWN
248 245
249 @pyqtSlot() 246 @pyqtSlot()
250 def activate(self): 247 def activate(self):
252 Public slot to activate the widget. 249 Public slot to activate the widget.
253 """ 250 """
254 self.show() 251 self.show()
255 self.findtextCombo.setFocus(Qt.FocusReason.ActiveWindowFocusReason) 252 self.findtextCombo.setFocus(Qt.FocusReason.ActiveWindowFocusReason)
256 self.findtextCombo.lineEdit().selectAll() 253 self.findtextCombo.lineEdit().selectAll()
254 self.infoLabel.clear()
255
256 self.__isActive = True
257 257
258 @pyqtSlot() 258 @pyqtSlot()
259 def deactivate(self): 259 def deactivate(self):
260 """ 260 """
261 Public slot to deactivate the widget. 261 Public slot to deactivate the widget.
262 """ 262 """
263 if self.__textedit: 263 if self.__textedit:
264 self.__textedit.setFocus(Qt.FocusReason.ActiveWindowFocusReason) 264 self.__textedit.setFocus(Qt.FocusReason.ActiveWindowFocusReason)
265 if self.__texteditType == EricTextEditType.QWEBENGINEVIEW: 265 if (
266 self.__texteditType == EricTextEditType.QWEBENGINEVIEW
267 and self.__isActive
268 ):
266 self.__textedit.findText("") 269 self.__textedit.findText("")
267 if self.closeButton is not None: 270 if self.closeButton is not None:
268 self.hide() 271 self.hide()
269 self.closePressed.emit() 272 self.closePressed.emit()
273
274 self.__isActive = False
270 275
271 @pyqtSlot() 276 @pyqtSlot()
272 def __closeButtonClicked(self): 277 def __closeButtonClicked(self):
273 """ 278 """
274 Private slot to close the widget. 279 Private slot to close the widget.
370 @param backwards flag indicating a backwards search 375 @param backwards flag indicating a backwards search
371 @type bool 376 @type bool
372 """ 377 """
373 if not self.__textedit: 378 if not self.__textedit:
374 return 379 return
380
381 self.show()
382 self.__isActive = True
375 383
376 self.infoLabel.clear() 384 self.infoLabel.clear()
377 if self.__texteditType != EricTextEditType.QWEBENGINEVIEW: 385 if self.__texteditType != EricTextEditType.QWEBENGINEVIEW:
378 self.infoLabel.hide() 386 self.infoLabel.hide()
379 self.__setFindtextComboBackground(False) 387 self.__setFindtextComboBackground(False)
444 type QWebEngineView. 452 type QWebEngineView.
445 453
446 @param backwards flag indicating a backwards search 454 @param backwards flag indicating a backwards search
447 @type bool 455 @type bool
448 """ 456 """
449 from PyQt6.QtWebEngineCore import QWebEnginePage # __IGNORE_WARNING_I102__ 457 from PyQt6.QtWebEngineCore import QWebEnginePage # noqa: I102
450 458
451 findFlags = QWebEnginePage.FindFlag(0) 459 if self.findtextCombo.currentText():
452 if self.caseCheckBox.isChecked(): 460 findFlags = QWebEnginePage.FindFlag(0)
453 findFlags |= QWebEnginePage.FindFlag.FindCaseSensitively 461 if self.caseCheckBox.isChecked():
454 if backwards: 462 findFlags |= QWebEnginePage.FindFlag.FindCaseSensitively
455 findFlags |= QWebEnginePage.FindFlag.FindBackward 463 if backwards:
456 self.__textedit.findText(self.findtextCombo.currentText(), findFlags) 464 findFlags |= QWebEnginePage.FindFlag.FindBackward
465 self.__textedit.findText(
466 self.findtextCombo.currentText(), findFlags, self.__findTextFinished
467 )
457 468
458 def __setFindtextComboBackground(self, error): 469 def __setFindtextComboBackground(self, error):
459 """ 470 """
460 Private slot to change the findtext combo background to indicate 471 Private slot to change the findtext combo background to indicate
461 errors. 472 errors.
471 ) 482 )
472 self.findtextCombo.setStyleSheet(styleSheet) 483 self.findtextCombo.setStyleSheet(styleSheet)
473 484
474 def __findTextFinished(self, result): 485 def __findTextFinished(self, result):
475 """ 486 """
476 Private slot handling the findTextFinished signal of the web page. 487 Private method handling the find result of the web page search.
488
489 Note: This method is used as the callback of the 'findText()' method call.
477 490
478 @param result reference to the QWebEngineFindTextResult object of the 491 @param result reference to the QWebEngineFindTextResult object of the
479 last search 492 last search
480 @type QWebEngineFindTextResult 493 @type QWebEngineFindTextResult
481 """ 494 """
482 if result.numberOfMatches() == 0: 495 if result.numberOfMatches() == 0:
483 self.infoLabel.setText( 496 self.infoLabel.setText(
484 self.tr("'{0}' was not found.").format(self.findtextCombo.currentText()) 497 self.tr("'{0}' was not found.")
498 .format(self.findtextCombo.currentText())
485 ) 499 )
486 self.__setFindtextComboBackground(True) 500 self.__setFindtextComboBackground(True)
487 else: 501 else:
488 self.infoLabel.setText( 502 self.infoLabel.setText(
489 self.tr("Match {0} of {1}").format( 503 self.tr("Match {0} of {1}").format(

eric ide

mercurial