本文整理汇总了Python中PyQt5.QtCore.QRegExp.escape方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.escape方法的具体用法?Python QRegExp.escape怎么用?Python QRegExp.escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QRegExp
的用法示例。
在下文中一共展示了QRegExp.escape方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: slotCursorPositionChanged
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.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: setSearchString
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import escape [as 别名]
def setSearchString(self, string):
"""
Public method to set the current search string.
@param string new search string (string)
"""
if string == self.__searchString:
return
self.__searchString = string
self.__searchMatcher.setPattern(self.__searchString)
self.__wordMatcher.setPattern(
"\\b" + QRegExp.escape(self.__searchString))
self.invalidateFilter()
示例3: filterOnFocus
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import escape [as 别名]
def filterOnFocus(window, focused):
loclist = getattr(window, 'build_loclist', None)
if not loclist:
return
model = loclist.model()
if not getattr(model, 'isFilterOnFocus', False):
orig = model
model = QSortFilterProxyModel()
model.isFilterOnFocus = True
loclist.setModel(model)
model.setSourceModel(orig)
model.setFilterRole(AbsolutePathRole)
model.setFilterRegExp(QRegExp.escape(focused.path or ''))