eric7/EricWidgets/EricTextEditSearchWidget.py

branch
eric7
changeset 8702
131ef7267fd4
parent 8690
25f68ec4181a
child 8706
16b25e115ac0
--- a/eric7/EricWidgets/EricTextEditSearchWidget.py	Tue Oct 19 19:55:21 2021 +0200
+++ b/eric7/EricWidgets/EricTextEditSearchWidget.py	Tue Oct 19 19:57:26 2021 +0200
@@ -9,7 +9,7 @@
 
 import enum
 
-from PyQt6.QtCore import pyqtSlot, Qt, QMetaObject, QSize
+from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt, QMetaObject, QSize
 from PyQt6.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor
 from PyQt6.QtWidgets import (
     QWidget, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QCheckBox,
@@ -32,7 +32,12 @@
 class EricTextEditSearchWidget(QWidget):
     """
     Class implementing a horizontal search widget for QTextEdit.
+    
+    @signal closePressed() emitted to indicate the closing of the widget via
+        the close button
     """
+    closePressed = pyqtSignal()
+    
     def __init__(self, parent=None, widthForHeight=True, enableClose=False):
         """
         Constructor
@@ -51,7 +56,7 @@
         
         self.__textedit = None
         self.__texteditType = EricTextEditType.UNKNOWN
-        self.__findBackwards = True
+        self.__findBackwards = False
         
         self.__defaultBaseColor = (
             self.findtextCombo.lineEdit().palette().color(
@@ -237,14 +242,34 @@
         self.__texteditType = EricTextEditType.UNKNOWN
     
     @pyqtSlot()
+    def activate(self):
+        """
+        Public slot to activate the widget.
+        """
+        self.show()
+        self.findtextCombo.setFocus(
+            Qt.FocusReason.ActiveWindowFocusReason)
+        self.findtextCombo.lineEdit().selectAll()
+    
+    @pyqtSlot()
+    def deactivate(self):
+        """
+        Public slot to deactivate the widget.
+        """
+        if self.__textedit:
+            self.__textedit.setFocus(Qt.FocusReason.ActiveWindowFocusReason)
+        if self.closeButton is not None:
+            self.hide()
+            self.closePressed.emit()
+    
+    @pyqtSlot()
     def __closeButtonClicked(self):
         """
         Private slot to close the widget.
         
         Note: The widget is just hidden.
         """
-        self.__textedit.setFocus(Qt.FocusReason.ActiveWindowFocusReason)
-        self.hide()
+        self.deactivate()
     
     def keyPressEvent(self, event):
         """
@@ -258,10 +283,7 @@
             modifiers = event.modifiers()
             
             if key == Qt.Key.Key_Escape:
-                self.__textedit.setFocus(
-                    Qt.FocusReason.ActiveWindowFocusReason)
-                if self.closeButton is not None:
-                    self.hide()
+                self.deactivate()
                 event.accept()
             
             elif key == Qt.Key.Key_F3:
@@ -318,6 +340,20 @@
         """
         self.__find(False)
     
+    @pyqtSlot()
+    def findPrev(self):
+        """
+        Public slot to find the previous occurrence of the current search term.
+        """
+        self.on_findPrevButton_clicked()
+    
+    @pyqtSlot()
+    def findNext(self):
+        """
+        Public slot to find the next occurrence of the current search term.
+        """
+        self.on_findNextButton_clicked()
+    
     def __find(self, backwards):
         """
         Private method to search the associated text edit.

eric ide

mercurial