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


Python QRegExp.escape方法代码示例

本文整理汇总了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])
开发者ID:aspiers,项目名称:frescobaldi,代码行数:51,代码来源:matcher.py

示例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
开发者ID:skeenp,项目名称:Roam,代码行数:10,代码来源:featureform.py


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