def find(self):

        # Grab the parent's text
        text = self.parent.text.toPlainText()

        # And the text to find
        query = self.findField.toPlainText()

        if self.normalRadio.isChecked():

            # Use normal string search to find the query from the
            # last starting position
            self.lastStart = text.find(query,self.lastStart + 1)

            # If the find() method didn't return -1 (not found)
            if self.lastStart >= 0:

                end = self.lastStart + len(query)
                
                self.moveCursor(self.lastStart,end)

            else:

                # Make the next search start from the begining again
                self.lastStart = 0
                
                self.parent.text.moveCursor(QtGui.QTextCursor.End)

        else:

            # Compile the pattern
            pattern = re.compile(query)

            # The actual search
            match = pattern.search(text,self.lastStart + 1)

            if match:

                self.lastStart = match.start()
                
                self.moveCursor(self.lastStart,match.end())

            else:

                self.lastStart = 0
                
                # We set the cursor to the end if the search was unsuccessful
                self.parent.text.moveCursor(QtGui.QTextCursor.End)
dataset/ETHPy150Open goldsborough/Writer-Tutorial/Part-3/ext/find.py/Find.find/original