예제 #1
0
    def __get_selection(self, posi, color):
        """
        Performs the selection of the given the specified row, column and background color.
        Uses a QTextEdit.ExtraSelection.

        Returns an empty list if the position is not valid
        """
        if not posi:
            return []

        row, column = posi

        selection = QTextEdit.ExtraSelection()
        selection.format.setBackground(QColor(self.config.get('colors',
                                                              color)))
        selection.format.setForeground(QColor('black'))
        selection.cursor = self.textCursor()
        selection.cursor.setPosition(0)  # Move to the beggining
        selection.cursor.movePosition(QTextCursor.Down, QTextCursor.MoveAnchor,
                                      row)  # Move to the row
        selection.cursor.movePosition(QTextCursor.WordRight,
                                      QTextCursor.MoveAnchor,
                                      column + 2)  # Move to the column

        selection.cursor.movePosition(QTextCursor.WordRight,
                                      QTextCursor.KeepAnchor,
                                      1)  # Select the color
        selection.cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor,
                                      1)  # un-select blank space

        return [selection]
    def update_visuals(self):
        """
        Moves text editor's cursor to match currently highlighted `find` word, performs `find` highlighting,
        indicates index on dialog.
        """
        # x of y words indicator
        idx = self.found_cursors.index(self.current_cursor) + 1
        self.found_info_label.setText("{} of {} matches".format(
            idx, len(self.found_cursors)))
        self.found_info_label.repaint()

        # move along text editor's viewport
        next_pte_cursor = QTextCursor(self.current_cursor)
        next_pte_cursor.clearSelection()
        self.plain_text_edit.setTextCursor(next_pte_cursor)

        #highlighting
        normal_color = QColor(Qt.yellow).lighter()
        current_color = QColor(Qt.magenta).lighter()
        extra_selections: List[QTextEdit.ExtraSelection] = []
        for cur in self.found_cursors:
            selection = QTextEdit.ExtraSelection()
            selection.cursor = cur
            if cur == self.current_cursor:
                selection.format.setBackground(current_color)
            else:
                selection.format.setBackground(normal_color)
            extra_selections.append(selection)
        self.plain_text_edit.setExtraSelections(extra_selections)
예제 #3
0
 def testPropertyValues(self):
     app = QApplication(sys.argv)
     textEdit = QPlainTextEdit()
     textEdit.insertPlainText("PySide INdT")
     selection = QTextEdit.ExtraSelection()
     selection.cursor = textEdit.textCursor()
     selection.cursor.setPosition(2)
     self.assertEqual(selection.cursor.position(), 2)
예제 #4
0
파일: textedit.py 프로젝트: safu9/Momiji
    def highlightCurrentLine(self):
        selection = QTextEdit.ExtraSelection()
        selection.format.setBackground(QColor('#ffffdd'))
        selection.format.setProperty(QTextFormat.FullWidthSelection, True)
        selection.cursor = self.textCursor()
        selection.cursor.clearSelection()

        self.setExtraSelections([selection])
예제 #5
0
 def highlight_chunks(self, chunks):
     extra_selections = []
     for start, end in chunks:
         sel = QTextEdit.ExtraSelection()
         sel.cursor = self._textedit.textCursor()
         sel.cursor.setPosition(start)
         sel.cursor.setPosition(end, QTextCursor.KeepAnchor)
         sel.format.setBackground(Qt.yellow)
         extra_selections.append(sel)
     self._textedit.setExtraSelections(extra_selections)
예제 #6
0
 def highlightCurrentLine(self):
     extraSelections = []
     if not self.isReadOnly():
         selection = QTextEdit.ExtraSelection()
         lineColor = QColor("#232323")
         selection.format.setBackground(lineColor)
         selection.format.setProperty(QTextFormat.FullWidthSelection, True)
         selection.cursor = self.textCursor()
         selection.cursor.clearSelection()
         extraSelections.append(selection)
     self.setExtraSelections(extraSelections)
예제 #7
0
 def highligtCurrentLine(self):
     newCurrentLineNumber = self.textCursor().blockNumber()
     if newCurrentLineNumber != self.currentLineNumber:
         self.currentLineNumber = newCurrentLineNumber
         hi_selection = QTextEdit.ExtraSelection()
         hi_selection.format.setBackground(self.currentLineColor)
         hi_selection.format.setProperty(QTextFormat.FullWidthSelection,
                                         True)
         hi_selection.cursor = self.textCursor()
         hi_selection.cursor.clearSelection()
         self.setExtraSelections([hi_selection])
예제 #8
0
파일: codeeditor.py 프로젝트: sb362/ide
	def highlightCurrentLine(self):
		selections = []

		if not self.isReadOnly():
			selection = QTextEdit.ExtraSelection()

			selection.format.setBackground(OuterSpace.lighter(160))
			selection.format.setProperty(QTextFormat.FullWidthSelection, True)
			selection.cursor = self.textCursor()
			selection.cursor.clearSelection()

			selections.append(selection)

		self.setExtraSelections(selections)
예제 #9
0
    def highlight_word(self, cursor: QTextCursor, entry: Optional[Entry]):
        selection = QTextEdit.ExtraSelection()
        normal_color = QColor(Qt.yellow).lighter()
        missing_color = QColor(Qt.magenta).lighter()
        default_color = QColor(Qt.green).lighter()

        if entry is None:
            selection.format.setBackground(missing_color)
        elif entry['default'] == cursor.selection().toPlainText():
            selection.format.setBackground(default_color)
        else:
            selection.format.setBackground(normal_color)

        selection.cursor = cursor

        self.setExtraSelections([selection])
예제 #10
0
    def highlight_current_line(self):
        extra_selections = []

        if not self.isReadOnly():
            selection = QTextEdit.ExtraSelection()

            line_color = QColor(Qt.yellow).lighter(160)
            selection.format.setBackground(line_color)

            selection.format.setProperty(QTextFormat.FullWidthSelection, True)

            selection.cursor = self.textCursor()
            selection.cursor.clearSelection()

            extra_selections.append(selection)

        self.setExtraSelections(extra_selections)
예제 #11
0
    def highlight_current_line(self):
        """
        Highlights the current edited line
        """
        line_selection = []

        if not self.isReadOnly():

            # Selection formatting
            selection = QTextEdit.ExtraSelection()
            lineColor = QColor(self.config.get('colors', 'editor_current_line_bg'))
            selection.format.setBackground(lineColor)
            selection.format.setProperty(QTextFormat.FullWidthSelection, True)
            selection.cursor = self.textCursor()
            selection.cursor.clearSelection()
            line_selection.append(selection)

        self.setExtraSelections(line_selection)
예제 #12
0
    def findTextDialog(self):
        """
        Pesquisar texto no widget QTextEdit
        """
        find_text, ok = QInputDialog.getText(self, "Encontrar Texto",
                                             "Procurar:")

        extra = []

        if ok and not self.tedit.isReadOnly():
            self.tedit.moveCursor(QTextCursor.Start)
            color = QColor(Qt.yellow)

            while (self.tedit.find(find_text)):
                selection = QTextEdit.ExtraSelection()
                selection.format.setBackground(color)
                selection.cursor = self.tedit.textCursor()
                extra.append(selection)

            for i in extra:
                self.tedit.setExtraSelections(i)
예제 #13
0
파일: main.py 프로젝트: safu9/Momiji
    def onFindAllClick(self):
        extraSelections = []
        flags = self.getFindFlags()
        self.ui.textEdit.moveCursor(QTextCursor.Start)
        cursor = self.ui.textEdit.textCursor()
        while True:
            cursor = self.ui.textEdit.document().find(self.getFindText(), cursor, flags)
            if cursor.isNull():
                break
            selection = QTextEdit.ExtraSelection()
            selection.format.setBackground(QColor(191, 191, 191, 189))
            selection.cursor = cursor
            extraSelections.append(selection)

        if len(extraSelections):
            self.ui.labelFindResult.setText(self.tr('%d found') % len(extraSelections))
            self.ui.labelFindResult.setStyleSheet('color: green;')
            self.ui.textEdit.setExtraSelections(extraSelections)
            self.ui.textEdit.moveCursor(QTextCursor.End)
        else:
            self.ui.labelFindResult.setText(self.tr('Not found'))
            self.ui.labelFindResult.setStyleSheet('color: red;')
        self.ui.textEdit.setFocus()
예제 #14
0
파일: ui.py 프로젝트: ramesharun/caribou
    def search_result_reset(self):
        self.goto(QTextCursor.Start)

        string_format = QTextCharFormat()
        string_format.setBackground(QColor('#668B8B'))

        extras = []
        self.search_positions = []
        while True:
            extra = QTextEdit.ExtraSelection()
            found = self.result_text_edit.find(self.search_line.text())

            if not found:
                break

            extra.cursor = self.result_text_edit.textCursor()
            extra.format = string_format

            self.search_positions.append(extra.cursor.position())
            extras.append(extra)

        self.result_text_edit.setExtraSelections(extras)
        self.goto(QTextCursor.Start)
        self.search_result()