本文整理汇总了Python中PyQt4.QtCore.QRegExp.escape方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.escape方法的具体用法?Python QRegExp.escape怎么用?Python QRegExp.escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QRegExp
的用法示例。
在下文中一共展示了QRegExp.escape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: slotCursorPositionChanged
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import escape [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])
示例2: findcontrol
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import escape [as 别名]
def findcontrol(self, name):
regex = QRegExp("^{}$".format(QRegExp.escape(name)))
regex.setCaseSensitivity(Qt.CaseInsensitive)
try:
widget = self.findChildren(QWidget, regex)[0]
except IndexError:
widget = None
return widget