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


Python QtGui.QTextCursor类代码示例

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


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

示例1: doTextEdit

    def doTextEdit(self, url, setCursor=False):
        """Process a textedit link and either highlight
           the corresponding source code or set the 
           cursor to it.
        """
        t = textedit.link(url)
        # Only process textedit links
        if not t:
            return False
        filename = util.normpath(t.filename)
        doc = self.document(filename, setCursor)
        if doc:
            cursor = QTextCursor(doc)
            b = doc.findBlockByNumber(t.line - 1)
            p = b.position() + t.column
            cursor.setPosition(p)
            cursors = pointandclick.positions(cursor)
            # Do highlighting if the document is active
            if cursors and doc == self.mainwindow().currentDocument():
                import viewhighlighter

                view = self.mainwindow().currentView()
                viewhighlighter.highlighter(view).highlight(self._highlightFormat, cursors, 2, 0)
            # set the cursor and bring the document to front
            if setCursor:
                mainwindow = self.mainwindow()
                mainwindow.setTextCursor(cursor)
                import widgets.blink

                widgets.blink.Blinker.blink_cursor(mainwindow.currentView())
                self.mainwindow().setCurrentDocument(doc)
                mainwindow.activateWindow()
                mainwindow.currentView().setFocus()
        return True
开发者ID:wbsoft,项目名称:frescobaldi,代码行数:34,代码来源:view.py

示例2: actionTriggered

 def actionTriggered(self, name):
     # convert arpeggio_normal to arpeggioNormal, etc.
     name = _arpeggioTypes[name]
     cursor = self.mainwindow().textCursor()
     # which arpeggio type is last used?
     lastused = '\\arpeggioNormal'
     types = set(_arpeggioTypes.values())
     block = cursor.block()
     while block.isValid():
         s = types.intersection(tokeniter.tokens(block))
         if s:
             lastused = s.pop()
             break
         block = block.previous()
     # where to insert
     c = lydocument.cursor(cursor)
     c.select_end_of_block()
     with cursortools.compress_undo(cursor):
         for item in ly.rhythm.music_items(c, partial=ly.document.OUTSIDE):
             c = QTextCursor(cursor.document())
             c.setPosition(item.end)
             c.insertText('\\arpeggio')
             if name != lastused:
                 cursortools.strip_indent(c)
                 indent = c.block().text()[:c.position()-c.block().position()]
                 c.insertText(name + '\n' + indent)
             # just pick the first place
             return
开发者ID:19joho66,项目名称:frescobaldi,代码行数:28,代码来源:spanners.py

示例3: spanner_positions

def spanner_positions(cursor):
    """Return a list with 0 to 2 QTextCursor instances.

    At the first cursor a starting spanner item can be inserted, at the
    second an ending item.

    """
    c = lydocument.cursor(cursor)
    if cursor.hasSelection():
        partial = ly.document.INSIDE
    else:
        # just select until the end of the current line
        c.select_end_of_block()
        partial = ly.document.OUTSIDE

    items = list(ly.rhythm.music_items(c, partial=partial))
    if cursor.hasSelection():
        del items[1:-1]
    else:
        del items[2:]

    positions = []
    for i in items:
        c = QTextCursor(cursor.document())
        c.setPosition(i.end)
        positions.append(c)
    return positions
开发者ID:19joho66,项目名称:frescobaldi,代码行数:27,代码来源:spanners.py

示例4: lineNumberAreaWidth

	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,代码行数:7,代码来源:editor.py

示例5: articulation_positions

def articulation_positions(cursor):
    """Returns a list of positions where an articulation can be added.
    
    Every position is given as a QTextCursor instance.
    If the cursor has a selection, all positions in the selection are returned.
    
    """
    c = lydocument.cursor(cursor)
    if not cursor.hasSelection():
        # just select until the end of the current line
        c.select_end_of_block()
        rests = True
        partial = ly.document.OUTSIDE
    else:
        rests = False
        partial = ly.document.INSIDE

    positions = []
    for item in ly.rhythm.music_items(c, partial):
        if not rests and item.tokens and isinstance(item.tokens[0], ly.lex.lilypond.Rest):
            continue
        csr = QTextCursor(cursor.document())
        csr.setPosition(item.end)
        positions.append(csr)
        if not cursor.hasSelection():
            break  # leave if first found, that's enough
    return positions
开发者ID:wbsoft,项目名称:frescobaldi,代码行数:27,代码来源:articulations.py

示例6: indent_selection

    def indent_selection(self):
        def indent_block(block):
            cursor = QTextCursor(block)
            indentation = self.__block_indentation(block)
            cursor.setPosition(block.position() + len(indentation))
            cursor.insertText(self.text())

        cursor = self._neditor.textCursor()
        start_block = self._neditor.document().findBlock(
            cursor.selectionStart())
        end_block = self._neditor.document().findBlock(
            cursor.selectionEnd())

        with self._neditor:
            if start_block != end_block:
                stop_block = end_block.next()
                # Indent multiple lines
                block = start_block
                while block != stop_block:
                    indent_block(block)
                    block = block.next()
                new_cursor = QTextCursor(start_block)
                new_cursor.setPosition(
                    end_block.position() + len(end_block.text()),
                    QTextCursor.KeepAnchor)
                self._neditor.setTextCursor(new_cursor)
            else:
                # Indent one line
                indent_block(start_block)
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:29,代码来源:base_indenter.py

示例7: keyPressEvent

 def keyPressEvent(self, event):
     #utilities.printKeyEvent(event)
     kkey = int( int(event.modifiers()) & C.KEYPAD_MOD_CLEAR) | int(event.key())
     if kkey in C.KEYS_EDITOR :
         event.accept() # yes, this is one we handle
         if kkey in C.KEYS_FIND :
             # ^f, ^g, etc. -- just pass them straight to the Find panel
             self.editFindKey.emit(kkey)
         elif kkey in C.KEYS_ZOOM :
             self.setFont( fonts.scale(kkey, self.font()) )
             self.my_book.save_font_size(self.font().pointSize())
         elif kkey in C.KEYS_BOOKMARKS :
             # Something to do with a bookmark. They are kept in the Book
             # because they are read and written in the metadata.
             mark_number = int(event.key()) - 0x31  # number in 0..8
             mark_list = self.my_book.bookmarks # quick reference to the list
             if kkey in C.KEYS_MARK_SET : # alt-1..9, set bookmark
                 # Set a bookmark to the current edit selection
                 mark_list[mark_number] = QTextCursor(self.textCursor())
                 self.my_book.metadata_modified(True, C.MD_MOD_FLAG)
             elif kkey in C.KEYS_MARK : # ctl-1..9, go to mark
                 # Move to the save position including a saved selection
                 if mark_list[mark_number] is not None :
                     self.parent().center_this(mark_list[mark_number])
             else : # shft-ctl-1..9, go to mark, extending selection
                 if mark_list[mark_number] is not None:
                     pos = mark_list[mark_number].position()
                     tc = QTextCursor(self.textCursor())
                     tc.setPosition(pos, QTextCursor.KeepAnchor)
                     self.setTextCursor(tc)
                     self.ensureCursorVisible()
     else: # not a key for the editor, pass it on.
         event.ignore()
         super().keyPressEvent(event)
开发者ID:B-Rich,项目名称:PPQT2,代码行数:34,代码来源:editview.py

示例8: load

    def load(self, url=None, encoding=None, keepUndo=False):
        """Load the specified or current url (if None was specified).

        Currently only local files are supported. An IOError is raised
        when trying to load a nonlocal URL.

        If loading succeeds and an url was specified, the url is made the
        current url (by calling setUrl() internally).

        If keepUndo is True, the loading can be undone (with Ctrl-Z).

        """
        if url is None:
            url = QUrl()
        u = url if not url.isEmpty() else self.url()
        text = self.load_data(u, encoding or self._encoding)
        if keepUndo:
            c = QTextCursor(self)
            c.select(QTextCursor.Document)
            c.insertText(text)
        else:
            self.setPlainText(text)
        self.setModified(False)
        if not url.isEmpty():
            self.setUrl(url)
开发者ID:19joho66,项目名称:frescobaldi,代码行数:25,代码来源:document.py

示例9: scrollToLine

    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,代码行数:27,代码来源:baseCodeEditor.py

示例10: test_indentLessWithSelection

	def test_indentLessWithSelection(self):
		self.document.setPlainText('    foo\n    bar\nbaz')
		cursor = QTextCursor(self.document)
		cursor.setPosition(5)
		cursor.setPosition(11, QTextCursor.KeepAnchor)
		documentIndentLess(self.document, cursor, self.settings)
		self.assertEqual('foo\nbar\nbaz', self.document.toPlainText())
开发者ID:liyongming1982,项目名称:retext,代码行数:7,代码来源:test_editor.py

示例11: scan_pages

 def scan_pages(self):
     global re_line_sep
     # first page is Arabic starting at 1
     rule = C.FolioRuleSet
     fmt = C.FolioFormatArabic
     nbr = 1
     self.explicit_formats = {0}
     for qtb in self.document.all_blocks() :
         m = re_line_sep.match(qtb.text())
         if m :
             # capture the image filename
             fname = m.group(1)
             if m.group(3) is not None :
                 # record proofers as a list, omitting the
                 # null element caused by the leading '\'
                 plist = m.group(3).split('\\')[1:]
             else :
                 # sep. line with no proofers, minimal list
                 plist = ['']
             qtc = QTextCursor(self.document)
             qtc.setPosition(qtb.position())
             self.cursor_list.append(qtc)
             self.filename_list.append(fname)
             self.folio_list.append( [rule,fmt,nbr] )
             self.proofers_list.append(plist)
             # remaining pages are ditto, add 1, next number
             rule = C.FolioRuleAdd1
             fmt = C.FolioFormatSame
             nbr += 1
     if 0 < len(self.cursor_list) : # we found at least 1
         self.my_book.metadata_modified(True, C.MD_MOD_FLAG)
         self._active = True
         self._add_stopper()
开发者ID:B-Rich,项目名称:PPQT2,代码行数:33,代码来源:pagedata.py

示例12: test_indentLess

	def test_indentLess(self):
		self.document.setPlainText('        foo')
		cursor = QTextCursor(self.document)
		cursor.setPosition(10)
		documentIndentLess(self.document, cursor, self.settings)
		self.assertEqual('    foo', self.document.toPlainText())
		documentIndentLess(self.document, cursor, self.settings)
		self.assertEqual('foo', self.document.toPlainText())
开发者ID:liyongming1982,项目名称:retext,代码行数:8,代码来源:test_editor.py

示例13: cursor_position

 def cursor_position(self, position):
     line, column = position
     line = min(line, self.line_count() - 1)
     column = min(column, len(self.line_text(line)))
     cursor = QTextCursor(self.document().findBlockByNumber(line))
     cursor.setPosition(cursor.block().position() + column,
                        QTextCursor.MoveAnchor)
     self.setTextCursor(cursor)
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:8,代码来源:base.py

示例14: make_cursor

 def make_cursor(self, position, anchor):
     mx = self.document.characterCount()
     tc = QTextCursor(self.Editor.textCursor())
     anchor = min( max(0,anchor), mx )
     position = min ( max(0,position), mx )
     tc.setPosition(anchor)
     tc.setPosition(position,QTextCursor.KeepAnchor)
     return tc
开发者ID:B-Rich,项目名称:PPQT2,代码行数:8,代码来源:editview.py

示例15: show_msg

 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,代码行数:9,代码来源:pyTesseractDemo.py


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