コード例 #1
0
ファイル: matcher.py プロジェクト: aspiers/frescobaldi
    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
0
 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])
コード例 #3
0
ファイル: featureform.py プロジェクト: skeenp/Roam
 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
コード例 #4
0
 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