本文整理汇总了Python中PyQt5.QtGui.QTextCursor.selectionStart方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.selectionStart方法的具体用法?Python QTextCursor.selectionStart怎么用?Python QTextCursor.selectionStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextCursor
的用法示例。
在下文中一共展示了QTextCursor.selectionStart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cut_assign
# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import selectionStart [as 别名]
def cut_assign(cursor):
"""Cuts selected text and assigns it to a LilyPond variable."""
# ask the variable name
name = inputdialog.getText(None, _("Cut and Assign"), _(
"Please enter the name for the variable to assign the selected "
"text to:"), regexp="[A-Za-z]+")
if not name:
return
cursortools.strip_selection(cursor)
# determine state at cursor
block = cursortools.block(cursor)
state = tokeniter.state(block)
for t in tokeniter.partition(cursor).left:
state.follow(t)
mode = ""
for p in state.parsers():
if isinstance(p, ly.lex.lilypond.ParseInputMode):
if isinstance(p, ly.lex.lilypond.ParseLyricMode):
mode = " \\lyricmode"
elif isinstance(p, ly.lex.lilypond.ParseChordMode):
mode = " \\chordmode"
elif isinstance(p, ly.lex.lilypond.ParseFigureMode):
mode = " \\figuremode"
elif isinstance(p, ly.lex.lilypond.ParseDrumMode):
mode = " \\drummode"
break
# find insertion place:
found = False
while block.previous().isValid():
block = block.previous()
state = tokeniter.state(block)
if isinstance(state.parser(), ly.lex.lilypond.ParseGlobal):
found = True
break
tokens = tokeniter.tokens(block)
for t in tokens:
if isinstance(t, ly.lex.lilypond.Name):
found = True
break
elif not isinstance(t, (ly.lex.Space, ly.lex.Comment)):
break
if found:
break
insert = QTextCursor(block)
text = cursor.selection().toPlainText()
space = '\n' if '\n' in text else ' '
text = ''.join((name, ' =', mode, ' {', space, text, space, '}\n\n'))
with cursortools.compress_undo(cursor):
cursor.insertText('\\' + name)
pos = insert.selectionStart()
insert.insertText(text)
if metainfo.info(cursor.document()).auto_indent:
insert.setPosition(pos, QTextCursor.KeepAnchor)
with cursortools.compress_undo(insert, True):
indent.re_indent(insert)
示例2: save
# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import selectionStart [as 别名]
def save(self):
"""Called to perform the edits in the document."""
cursor = QTextCursor(self._range)
start = cursor.selectionStart()
# use cursordiff; don't destroy point and click positions
cursordiff.insert_text(cursor, self.view.toPlainText())
cursor.setPosition(start, QTextCursor.KeepAnchor)
with cursortools.compress_undo(cursor, True):
# re-indent the inserted line(s)
indent.re_indent(cursor)