本文整理汇总了Python中PyQt4.QtGui.QTextCursor.movePosition方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.movePosition方法的具体用法?Python QTextCursor.movePosition怎么用?Python QTextCursor.movePosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTextCursor
的用法示例。
在下文中一共展示了QTextCursor.movePosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onMatchNumberChange
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def onMatchNumberChange(self, matchNumber):
# Set default format on the whole text before highlighting the selected
# match.
document = self.matchText.document()
cursor = QTextCursor(document)
cursor.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
cursor.setCharFormat(QTextCharFormat())
search = self.getSearchText()
for i, match in enumerate(self.regex.finditer(search)):
if i + 1 == matchNumber:
break
else:
assert False, ("We didn't find a match?! (RE=%r, text=%r" %
(self.regex.pattern, search))
self.formatMatchedText(document, match)
model = self.groupsView.model()
model.clear()
# Create a reversed self.regex.groupindex dictionnary
groupsIndexes = dict((v, k)
for (k, v) in self.regex.groupindex.iteritems())
for i in range(1, self.regex.groups + 1):
groupName = groupsIndexes.get(i, "")
groupValue = match.group(i)
model.append((groupName, groupValue))
示例2: setLine
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.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)
示例3: show
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def show(cursor, pos=None, num_lines=6):
"""Displays a tooltip showing part of the cursor's Document.
If the cursor has a selection, those blocks are displayed.
Otherwise, num_lines lines are displayed.
If pos is not given, the global mouse position is used.
"""
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() * .8)
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))
label = QLabel()
label.setPixmap(pix)
label.setStyleSheet("QLabel { border: 1px solid #777; }")
label.resize(size)
widgets.customtooltip.show(label, pos)
示例4: append
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.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)
示例5: cursorAt
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def cursorAt(self, position, in_active_area=True):
c = QTextCursor(self.block)
p = min(position, self.length-1)
if in_active_area:
p = max(p, self.active_area_start)
c.movePosition(QTextCursor.Right, QTextCursor.MoveAnchor, p)
return c
示例6: _find
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def _find(self, textEdit=None, backward=False):
if textEdit is None:
textEdit = self.textEdit
found = False
if textEdit is not None:
cursor = textEdit.textCursor()
text, flags = self._textAndFindFlags(backward=backward)
position = cursor.position()
cursor = textEdit.document().find(text, cursor, flags)
if not cursor.isNull():
textEdit.setTextCursor(cursor)
found = True
elif self.wrapAroundCheckBox.isChecked():
cursor = QTextCursor(textEdit.textCursor())
cursor.movePosition(backward and QTextCursor.End or QTextCursor.Start)
cursor = textEdit.document().find(text, cursor, flags)
if not cursor.isNull():
if position == cursor.position():
pass #todo
textEdit.setTextCursor(cursor)
found = True
self.writeSettings()
if not found:
QApplication.beep()
self.feedbackLabel.setText(self.tr("Not found"))
else:
self.clearFeedback()
示例7: _selectLines
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def _selectLines(self, startBlockNumber, endBlockNumber):
"""Select whole lines
"""
startBlock = self.document().findBlockByNumber(startBlockNumber)
endBlock = self.document().findBlockByNumber(endBlockNumber)
cursor = QTextCursor(startBlock)
cursor.setPosition(endBlock.position(), QTextCursor.KeepAnchor)
cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
self.setTextCursor(cursor)
示例8: isBlankAfter
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def isBlankAfter(cursor):
"""Returns True if there's no text on the current line after the cursor."""
if cursor.hasSelection():
return False
if cursor.atBlockEnd():
return True
c = QTextCursor(cursor)
c.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
return c.selection().toPlainText().isspace()
示例9: isBlankBefore
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def isBlankBefore(cursor):
"""Returns True if there's no text on the current line before the cursor."""
if cursor.hasSelection():
return False
if cursor.atBlockStart():
return True
c = QTextCursor(cursor)
c.movePosition(QTextCursor.StartOfBlock, QTextCursor.KeepAnchor)
return c.selection().toPlainText().isspace()
示例10: show_msg
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.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()
示例11: formatMatchedText
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def formatMatchedText(self, document, match):
"""Format the matched text in a document"""
cursor = QTextCursor(document)
cursor.setPosition(match.start())
cursor.movePosition(
QTextCursor.NextCharacter,
QTextCursor.KeepAnchor,
match.end() - match.start())
cursor.setCharFormat(self.matchFormat)
示例12: add_debug_message
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.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())
示例13: setTextCursor
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def setTextCursor(self, cursor):
"""Reimplemented to show n surrounding lines."""
numlines = QSettings().value("view_preferences/context_lines", 3, int)
if numlines > 0:
c = QTextCursor(cursor)
c.setPosition(cursor.selectionEnd())
c.movePosition(QTextCursor.Down, QTextCursor.MoveAnchor, numlines)
super(View, self).setTextCursor(c)
c.setPosition(cursor.selectionStart())
c.movePosition(QTextCursor.Up, QTextCursor.MoveAnchor, numlines)
super(View, self).setTextCursor(c)
super(View, self).setTextCursor(cursor)
示例14: __highlight
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import movePosition [as 别名]
def __highlight(self, positions, color=None, cancel=False):
cursor = QTextCursor(self.document())
for position in positions:
if position > self.get_position('eof'):
return
cursor.setPosition(position)
cursor.movePosition(QTextCursor.NextCharacter,
QTextCursor.KeepAnchor)
charformat = cursor.charFormat()
pen = QPen(Qt.NoPen) if cancel else QPen(color)
charformat.setTextOutline(pen)
cursor.setCharFormat(charformat)
示例15: write
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.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()