当前位置: 首页>>代码示例>>Python>>正文


Python QTextCursor.removeSelectedText方法代码示例

本文整理汇总了Python中PyQt5.QtGui.QTextCursor.removeSelectedText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.removeSelectedText方法的具体用法?Python QTextCursor.removeSelectedText怎么用?Python QTextCursor.removeSelectedText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtGui.QTextCursor的用法示例。


在下文中一共展示了QTextCursor.removeSelectedText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: unindent

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import removeSelectedText [as 别名]
    def unindent(self):
        cursor = self._neditor.textCursor()
        start_block = self._neditor.document().findBlock(
            cursor.selectionStart())
        end_block = self._neditor.document().findBlock(
            cursor.selectionEnd())

        position = cursor.position()
        if position == 0:
            return

        if start_block != end_block:
            # Unindent multiple lines
            block = start_block
            stop_block = end_block.next()
            while block != stop_block:
                indentation = self.__block_indentation(block)
                if indentation.endswith(self.text()):
                    cursor = QTextCursor(block)
                    cursor.setPosition(block.position() + len(indentation))
                    cursor.setPosition(cursor.position() - self.WIDTH,
                                       QTextCursor.KeepAnchor)
                    cursor.removeSelectedText()
                block = block.next()
        else:
            # Unindent one line
            indentation = self.__block_indentation(start_block)
            cursor = QTextCursor(start_block)
            cursor.setPosition(start_block.position() + len(indentation))
            cursor.setPosition(cursor.position() - self.WIDTH,
                               QTextCursor.KeepAnchor)
            cursor.removeSelectedText()
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:34,代码来源:base_indenter.py

示例2: setLine

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import removeSelectedText [as 别名]
 def setLine(self, line):
     cursor = QTextCursor(self.document())
     cursor.movePosition(QTextCursor.End)
     cursor.setPosition(self.newPromptPos, QTextCursor.KeepAnchor)
     cursor.removeSelectedText()
     cursor.insertText(line)
     self.setTextCursor(cursor)
开发者ID:srio,项目名称:Orange-XOPPY,代码行数:9,代码来源:python_script.py

示例3: add_debug_message

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import removeSelectedText [as 别名]
    def add_debug_message(self, message):
        self.text_debug.append(message)

        while self.text_debug.document().blockCount() > 1000:
            cursor = QTextCursor(self.text_debug.document().begin())
            cursor.select(QTextCursor.BlockUnderCursor)
            cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
            cursor.removeSelectedText()

        if self.checkbox_debug_auto_scroll.isChecked():
            self.text_debug.verticalScrollBar().setValue(self.text_debug.verticalScrollBar().maximum())
开发者ID:Tinkerforge,项目名称:brickv,代码行数:13,代码来源:setup_dialog.py

示例4: _removeBlock

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import removeSelectedText [as 别名]
 def _removeBlock(blockIndex):
     block = self._doc.findBlockByNumber(blockIndex)
     if block.next().isValid():  # not the last
         cursor = QTextCursor(block)
         cursor.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor)
     elif block.previous().isValid():  # the last, not the first
         cursor = QTextCursor(block.previous())
         cursor.movePosition(QTextCursor.EndOfBlock)
         cursor.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor)
         cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
     else:  # only one block
         cursor = QTextCursor(block)
         cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
     cursor.removeSelectedText()
开发者ID:Aldenis2112,项目名称:qutepart,代码行数:16,代码来源:lines.py

示例5: html_copy

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import removeSelectedText [as 别名]
def html_copy(cursor, scheme='editor', number_lines=False):
    """Return a new QTextDocument with highlighting set as HTML textcharformats.

    The cursor is a cursor of a document.Document instance. If the cursor
    has a selection, only the selection is put in the new document.

    If number_lines is True, line numbers are added.

    """
    data = textformats.formatData(scheme)
    doc = QTextDocument()
    doc.setDefaultFont(data.font)
    doc.setPlainText(cursor.document().toPlainText())
    if metainfo.info(cursor.document()).highlighting:
        highlight(doc, mapping(data), ly.lex.state(documentinfo.mode(cursor.document())))
    if cursor.hasSelection():
        # cut out not selected text
        start, end = cursor.selectionStart(), cursor.selectionEnd()
        cur1 = QTextCursor(doc)
        cur1.setPosition(start, QTextCursor.KeepAnchor)
        cur2 = QTextCursor(doc)
        cur2.setPosition(end)
        cur2.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
        cur2.removeSelectedText()
        cur1.removeSelectedText()
    if number_lines:
        c = QTextCursor(doc)
        f = QTextCharFormat()
        f.setBackground(QColor('#eeeeee'))
        if cursor.hasSelection():
            num = cursor.document().findBlock(cursor.selectionStart()).blockNumber() + 1
            last = cursor.document().findBlock(cursor.selectionEnd())
        else:
            num = 1
            last = cursor.document().lastBlock()
        lastnum = last.blockNumber() + 1
        padding = len(format(lastnum))
        block = doc.firstBlock()
        while block.isValid():
            c.setPosition(block.position())
            c.setCharFormat(f)
            c.insertText('{0:>{1}d} '.format(num, padding))
            block = block.next()
            num += 1
    return doc
开发者ID:brownian,项目名称:frescobaldi,代码行数:47,代码来源:highlighter.py

示例6: _get_textdoc

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import removeSelectedText [as 别名]
    def _get_textdoc(self, index):
        """Create the QTextDocument of an item.

        Args:
            index: The QModelIndex of the item to draw.
        """
        # FIXME we probably should do eliding here. See
        # qcommonstyle.cpp:viewItemDrawText
        text_option = QTextOption()
        if self._opt.features & QStyleOptionViewItem.WrapText:
            text_option.setWrapMode(QTextOption.WordWrap)
        else:
            text_option.setWrapMode(QTextOption.ManualWrap)
        text_option.setTextDirection(self._opt.direction)
        text_option.setAlignment(QStyle.visualAlignment(
            self._opt.direction, self._opt.displayAlignment))

        self._doc = QTextDocument(self)
        if index.parent().isValid():
            self._doc.setPlainText(self._opt.text)
        else:
            self._doc.setHtml('<b>{}</b>'.format(html.escape(self._opt.text)))
        self._doc.setDefaultFont(self._opt.font)
        self._doc.setDefaultTextOption(text_option)
        self._doc.setDefaultStyleSheet(style.get_stylesheet("""
            .highlight {
                {{ color['completion.match.fg'] }}
            }
        """))
        self._doc.setDocumentMargin(2)

        if index.column() == 0:
            marks = index.data(basecompletion.Role.marks)
            if marks is None:
                return
            for mark in marks:
                cur = QTextCursor(self._doc)
                cur.setPosition(mark[0])
                cur.setPosition(mark[1], QTextCursor.KeepAnchor)
                txt = cur.selectedText()
                cur.removeSelectedText()
                cur.insertHtml('<span class="highlight">{}</span>'.format(
                    html.escape(txt)))
开发者ID:har5ha,项目名称:qutebrowser,代码行数:45,代码来源:completiondelegate.py

示例7: cmdJoinLines

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import removeSelectedText [as 别名]
    def cmdJoinLines(self, cmd, repeatLineCount=None):
        if repeatLineCount is not None:
            self._selectRangeForRepeat(repeatLineCount)

        start, end = self._selectedLinesRange()
        count = end - start

        if not count:  # nothing to join
            return

        self._saveLastEditLinesCmd(cmd, end - start + 1)

        cursor = QTextCursor(self._qpart.document().findBlockByNumber(start))
        with self._qpart:
            for _ in range(count):
                cursor.movePosition(QTextCursor.EndOfBlock)
                cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor)
                self.moveToFirstNonSpace(cursor, QTextCursor.KeepAnchor)
                nonEmptyBlock = cursor.block().length() > 1
                cursor.removeSelectedText()
                if nonEmptyBlock:
                    cursor.insertText(' ')

        self._qpart.setTextCursor(cursor)
开发者ID:bjones1,项目名称:qutepart,代码行数:26,代码来源:vim.py


注:本文中的PyQt5.QtGui.QTextCursor.removeSelectedText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。