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


Python QTextCursor.movePosition方法代码示例

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


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

示例1: setLine

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [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

示例2: scrollToLine

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
    def scrollToLine(self, lineNumber, columnNumber=None):
        """
        Scrolls this widget’s viewport to the line *lineNumber* and sets the
        text cursor to that line, at *columnNumber*. If *columnNumber* is None,
        bookkeeping will be performed.

        Strictly positive numbers are expected.
        """
        lineNumber -= 1
        if columnNumber is None:
            columnNumber = self.textCursor().positionInBlock()
        else:
            columnNumber -= 1
        scrollingUp = lineNumber < self.textCursor().blockNumber()
        # scroll to block
        textBlock = self.document().findBlockByLineNumber(lineNumber)
        newCursor = QTextCursor(textBlock)
        self.setTextCursor(newCursor)
        # make some headroom
        one, two = QTextCursor.Down, QTextCursor.Up
        if scrollingUp:
            one, two = two, one
        for move in (one, one, two, two):
            self.moveCursor(move)
        # address column
        newCursor.movePosition(QTextCursor.NextCharacter, n=columnNumber)
        self.setTextCursor(newCursor)
开发者ID:adrientetar,项目名称:defconQt,代码行数:29,代码来源:baseCodeEditor.py

示例3: append

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
 def append(self, text):
     """Append line to the end
     """
     cursor = QTextCursor(self._doc)
     cursor.movePosition(QTextCursor.End)
     cursor.insertBlock()
     cursor.insertText(text)
开发者ID:Aldenis2112,项目名称:qutepart,代码行数:9,代码来源:lines.py

示例4: pixmap

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
def pixmap(cursor, num_lines=6, scale=0.8):
    """Return a QPixmap displaying the selected lines of the document.

    If the cursor has no selection, num_lines are drawn.

    By default the text is drawn 0.8 * the normal font size. You can change
    that by supplying the scale parameter.

    """
    block = cursor.document().findBlock(cursor.selectionStart())
    c2 = QTextCursor(block)
    if cursor.hasSelection():
        c2.setPosition(cursor.selectionEnd(), QTextCursor.KeepAnchor)
        c2.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
    else:
        c2.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor, num_lines)

    data = textformats.formatData('editor')
    doc = QTextDocument()
    font = QFont(data.font)
    font.setPointSizeF(font.pointSizeF() * scale)
    doc.setDefaultFont(font)
    doc.setPlainText(c2.selection().toPlainText())
    if metainfo.info(cursor.document()).highlighting:
        highlighter.highlight(doc, state=tokeniter.state(block))
    size = doc.size().toSize() + QSize(8, -4)
    pix = QPixmap(size)
    pix.fill(data.baseColors['background'])
    doc.drawContents(QPainter(pix))
    return pix
开发者ID:19joho66,项目名称:frescobaldi,代码行数:32,代码来源:documenttooltip.py

示例5: lineNumberAreaWidth

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
	def lineNumberAreaWidth(self):
		if not globalSettings.lineNumbersEnabled:
			return 0
		cursor = QTextCursor(self.document())
		cursor.movePosition(QTextCursor.End)
		digits = len(str(cursor.blockNumber() + 1))
		return 5 + self.fontMetrics().width('9') * digits
开发者ID:farseerfc,项目名称:retext,代码行数:9,代码来源:editor.py

示例6: show_msg

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
 def show_msg(self, message):
     """Show message in textBrowser
     """
     self.textEdit.append(message)
     # Scroll to end of the last message
     cursor = QTextCursor(self.textEdit.textCursor())
     cursor.movePosition(QTextCursor.End)
     self.textEdit.setTextCursor(cursor)
     QApplication.processEvents()
开发者ID:zdenop,项目名称:pyTesseractDemo,代码行数:11,代码来源:pyTesseractDemo.py

示例7: _make_selection

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
 def _make_selection(self, block, index, matched):
     cur = QTextCursor(block)
     cur.setPosition(block.position() + index)
     cur.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
     selection = ExtraSelection(cur)
     background = self.matched_background
     if not matched:
         background = self.unmatched_background
     selection.set_background(background)
     return selection
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:12,代码来源:symbol_highlighter.py

示例8: add_debug_message

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [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

示例9: write

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
 def write(self, s):
     if self.echo:
         sys.__stdout__.write(s)
     doc = self.document()
     cursor = QTextCursor(doc)
     cursor.clearSelection()
     cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
     cursor.insertText(s)
     cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
     cursor.clearSelection()
     self.ensureCursorVisible()
     qApp.processEvents()
开发者ID:jlpoolen,项目名称:scribus-plugin-scripter,代码行数:14,代码来源:console.py

示例10: _removeBlock

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [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

示例11: slotCursorPositionChanged

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
    def slotCursorPositionChanged(self):
        """Called whenever the cursor position changes.
        
        Highlights matching characters if the cursor is at one of them.
        
        """
        cursor = self.edit().textCursor()
        block = cursor.block()
        text = block.text()

        # try both characters at the cursor
        col = cursor.position() - block.position()
        end = col + 1
        col = max(0, col - 1)
        for c in text[col:end]:
            if c in self.matchPairs:
                break
            col += 1
        else:
            self.clear()
            return

        # the cursor is at a character from matchPairs
        i = self.matchPairs.index(c)
        cursor.setPosition(block.position() + col)

        # find the matching character
        new = QTextCursor(cursor)
        if i & 1:
            # look backward
            match = self.matchPairs[i - 1]
            flags = QTextDocument.FindBackward
        else:
            # look forward
            match = self.matchPairs[i + 1]
            flags = QTextDocument.FindFlags()
            new.movePosition(QTextCursor.Right)

        # search, also nesting
        rx = QRegExp(QRegExp.escape(c) + "|" + QRegExp.escape(match))
        nest = 0
        while nest >= 0:
            new = cursor.document().find(rx, new, flags)
            if new.isNull():
                self.clear()
                return
            nest += 1 if new.selectedText() == c else -1
        cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
        self.highlight([cursor, new])
开发者ID:wbsoft,项目名称:frescobaldi,代码行数:51,代码来源:matcher.py

示例12: apply_changes

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
 def apply_changes(self):
     """Apply the changes and update the tokens."""
     c = QTextCursor(self._d)
     # record a sensible position for undo
     c.setPosition(self._changes_list[-1][0])
     c.joinPreviousEditBlock() if self.combine_undo else c.beginEditBlock()
     try:
         for start, end, text in self._changes_list:
             c.movePosition(QTextCursor.End) if end is None else c.setPosition(end)
             c.setPosition(start, QTextCursor.KeepAnchor)
             c.insertText(text)
     finally:
         c.endEditBlock()
         if self.combine_undo is None:
             self.combine_undo = True
开发者ID:AlexSchr,项目名称:frescobaldi,代码行数:17,代码来源:lydocument.py

示例13: _getCursorSelectAll

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
 def _getCursorSelectAll(self, morph):
   '''
   Cursor on entire document (text) of a morph (DocumentElement) of type Text.
   
   morph may be empty of text.
   !!! Cursor may not hasSelection() if morph is empty of text.
   '''
   cursor = QTextCursor(morph.document())
   cursor.setPosition(0)
   cursor.clearSelection()
   # programmatic selection requires movePosition(), not setPosition()
   cursor.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
   # In Qt, cursor is valid for further operations regardless of whether hasSelection()
   # ensure document not empty => cursor.hasSelection
   assert morph.document().isEmpty() or cursor.hasSelection()
   return cursor
开发者ID:bootchk,项目名称:documentStyle,代码行数:18,代码来源:textFormation.py

示例14: insert

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [as 别名]
    def insert(self, index, text):
        """Insert line to the document
        """
        if index < 0 or index > self._doc.blockCount():
            raise IndexError('Invalid block index', index)

        if index == 0:  # first
            cursor = QTextCursor(self._doc.firstBlock())
            cursor.insertText(text)
            cursor.insertBlock()
        elif index != self._doc.blockCount():  # not the last
            cursor = QTextCursor(self._doc.findBlockByNumber(index).previous())
            cursor.movePosition(QTextCursor.EndOfBlock)
            cursor.insertBlock()
            cursor.insertText(text)
        else:  # last append to the end
            self.append(text)
开发者ID:Aldenis2112,项目名称:qutepart,代码行数:19,代码来源:lines.py

示例15: html_copy

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import movePosition [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


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