Python PySide.QtCore.QRegExp() Examples

The following are 10 code examples of PySide.QtCore.QRegExp(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySide.QtCore , or try the search function .
Example #1
Source File: xrefwindow.py    From TimeMachine with GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.xrefwindow.proxyModel.setFilterRegExp(regExp) 
Example #2
Source File: stringswindow.py    From TimeMachine with GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.stringswindow.proxyModel.setFilterRegExp(regExp) 
Example #3
Source File: xrefwindow.py    From AndroBugs_Framework with GNU General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.xrefwindow.proxyModel.setFilterRegExp(regExp) 
Example #4
Source File: stringswindow.py    From AndroBugs_Framework with GNU General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.stringswindow.proxyModel.setFilterRegExp(regExp) 
Example #5
Source File: CodeEditor.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def match_multiline(self, text, delimiter, in_state, style):
        """Do highlighting of multi-line strings. ``delimiter`` should be a
        ``QRegExp`` for triple-single-quotes or triple-double-quotes, and
        ``in_state`` should be a unique integer to represent the corresponding
        state changes when inside those strings. Returns True if we're still
        inside a multi-line string when this function is finished.
        """
        # If inside triple-single quotes, start at 0
        if self.previousBlockState() == in_state:
            start = 0
            add = 0
        # Otherwise, look for the delimiter on this line
        else:
            start = delimiter.indexIn(text)
            # Move past this match
            add = delimiter.matchedLength()

        # As long as there's a delimiter match on this line...
        while start >= 0:
            # Look for the ending delimiter
            end = delimiter.indexIn(text, start + add)
            # Ending delimiter on this line?
            if end >= add:
                length = end - start + add + delimiter.matchedLength()
                self.setCurrentBlockState(0)
            # No; multi-line string
            else:
                self.setCurrentBlockState(in_state)
                length = len(text) - start + add
            # Apply formatting
            self.setFormat(start, length, style)
            # Look for the next match
            start = delimiter.indexIn(text, start + length)

        # Return True if still inside a multi-line string, False otherwise
        if self.currentBlockState() == in_state:
            return True
        else:
            return False 
Example #6
Source File: xrefwindow.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.xrefwindow.proxyModel.setFilterRegExp(regExp) 
Example #7
Source File: stringswindow.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.stringswindow.proxyModel.setFilterRegExp(regExp) 
Example #8
Source File: syntax.py    From hrdev with MIT License 5 votes vote down vote up
def highlightBlock(self, text):
        '''Highlight block.'''

        for pattern, hl_format in self._highlighting_rules:
            expression = QtCore.QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index, length, hl_format)
                index = expression.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        start_index = 0
        if self.previousBlockState() != 1:
            start_index = self.comment_start_expression.indexIn(text)

        while start_index >= 0:
            end_index = self.comment_end_expression.indexIn(text, start_index)

            if end_index == -1:
                self.setCurrentBlockState(1)
                comment_length = text.length() - start_index
            else:
                comment_length = end_index - \
                                 start_index + \
                                 self.comment_end_expression.matchedLength()

            multi_line_comment_format = QtGui.QTextCharFormat()
            multiline_color = self.config_theme.get('tokens_highlight',
                                                    'quotation_color')
            multi_line_comment_format.setForeground(QtGui.QColor(multiline_color))
            self.setFormat(start_index, comment_length,
                           multi_line_comment_format)
            start_index = self.comment_start_expression.indexIn(text,
                                                                start_index +
                                                                comment_length)
        return 
Example #9
Source File: gui.py    From hrdev with MIT License 5 votes vote down vote up
def _toggle_casts(self):
            '''TODO: feature to toggle casting.'''

            if self._casts_marked:
                for selection in self._casts_selections:
                    selection.cursor.clearSelection()
                self._casts_marked = False
                self._casts_selections = None
                return
            search_flag = QTextDocument.FindFlags(0)
            search_flag |= QTextDocument.FindWholeWords
            search_flag |= QTextDocument.FindCaseSensitively
            marker_color = self.config_theme.get('editor', 'hidden_color')

            self._casts_selections = []
            selection = QTextEdit.ExtraSelection()

            cursor = self.document().find(QtCore.QRegExp(r'\(\w+\s\*\)'))
            cursor.select(QTextCursor.WordUnderCursor)

            cursor.movePosition(QTextCursor.Start)

            selection.format.setBackground(QColor(marker_color))
            selection.cursor = cursor
            self._casts_selections.append(selection)

            while cursor:
                cursor = self.document().find(QtCore.QRegExp(r'\(\w+\s\*\)'),
                                              cursor, search_flag)
                if not cursor:
                    break
                selection = QTextEdit.ExtraSelection()
                selection.format.setBackground(QColor(marker_color))
                selection.cursor = cursor
                self._casts_selections.append(selection)
            self.setExtraSelections(self._casts_selections)
            self._casts_marked = True
            return 
Example #10
Source File: CodeEditor.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 4 votes vote down vote up
def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        # Multi-line strings (expression, flag, style)
        # FIXME: The triple-quotes in these two lines will mess up the
        # syntax highlighting from this point onward
        self.tri_single = (QRegExp("'''"), 1, STYLES['string2'])
        self.tri_double = (QRegExp('"""'), 2, STYLES['string2'])

        rules = []

        # Keyword, operator, and brace rules
        rules += [(r'\b%s\b' % w, 0, STYLES['keyword'])
            for w in PythonHighlighter.keywords]
        rules += [(r'%s' % o, 0, STYLES['operator'])
            for o in PythonHighlighter.operators]
        rules += [(r'%s' % b, 0, STYLES['brace'])
            for b in PythonHighlighter.braces]

        # All other rules
        rules += [
            # 'self'
            (r'\bself\b', 0, STYLES['self']),

            # Double-quoted string, possibly containing escape sequences
            (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),
            # Single-quoted string, possibly containing escape sequences
            (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']),

            # 'def' followed by an identifier
            (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']),
            # 'class' followed by an identifier
            (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']),

            # From '#' until a newline
            (r'#[^\n]*', 0, STYLES['comment']),

            # Numeric literals
            (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']),
        ]

        # Build a QRegExp for each pattern
        self.rules = [(QRegExp(pat), index, fmt)
            for (pat, index, fmt) in rules]