Esempio n. 1
0
 def start_editing(self):
     """Starts editing."""
     self.setTextInteractionFlags(Qt.TextEditorInteraction)
     self.setFocus()
     cursor = QTextCursor(self._cursor)
     cursor.select(QTextCursor.Document)
     self.setTextCursor(cursor)
     self._text_backup = self.toPlainText()
Esempio n. 2
0
 def set_line_number(self, lineno):
     if self._current_lineno == lineno:
         return
     self._current_lineno = lineno
     doc = self.text_edit.document()
     # FIXME: complexity in O(number of lines)?
     block = doc.findBlockByLineNumber(lineno - 1)
     cursor = QTextCursor(block)
     cursor.select(QTextCursor.BlockUnderCursor)
     # FIXME: complexity in O(number of lines)?
     self.text_edit.setTextCursor(cursor)
Esempio n. 3
0
    def textUnderCursor(self):
        tc = self.textCursor()
        tc.select(QTextCursor.WordUnderCursor)

        selected_text = tc.selectedText()

        if selected_text == "(":
            cursor_pos = tc.position()
            if cursor_pos - 2 > 0:
                cursor_prev = QTextCursor(self.document())
                cursor_prev.setPosition(cursor_pos - 2)
                cursor_prev.select(QTextCursor.WordUnderCursor)
                selected_text = cursor_prev.selectedText()

        #print(selected_text)
        return selected_text