def logfile_lexer(self, start_pos, end_pos):
            ''' Main lexing logic.
                Gets called by styleneeded callback
            '''

            def style_it(match, STYLE):
                ''' Inform scintilla to do the styling'''
                if match[1]-match[0] >= 0:
                    editor.startStyling(start_pos + match[0], 31)
                    editor.setStyling(match[1]-match[0], STYLE)

            def do_regex(regex):
                ''' return a list of match positions 
                    Note, is using python regular expression instead of boost::re
                '''
                return [m.span(0) for m in re.finditer(regex, text, flags=re.I)]

            # ensure that position is really the first position for each line
            start_pos = editor.positionFromLine(editor.lineFromPosition(start_pos))
            # fast but potentially unsafe way to get the text of the line
            text = editor.getRangePointer(start_pos, end_pos-start_pos)
            
            # first everything will be styled with default style
            style_it((start_pos, end_pos), self.DEFAULT)

            # map style_it function to each match returned by do_regex
            # ordering is important as it might be that a line matches
            # multiple regexes - the last do_regex overwrites previous styling
            map(lambda match: style_it(match, self.WARNING_STYLE), do_regex(self.WARNING_REGEX))
            map(lambda match: style_it(match, self.ERROR_STYLE), do_regex(self.ERROR_REGEX))

            # this needs to stay and to be the last line, to signal scintilla we are done.
            editor.startStyling(end_pos,31)
Exemple #2
0
 def test_scintillawrapper_void_position_int(self):
     editor.setText('Hello world')
     editor.setLexer(LEXER.CONTAINER)
     editor.startStyling(0, 31)
     editor.setStyling(5, 29)
     styledText = editor.getStyledText(0, 5)
     editor.setLexer(LEXER.NULL)
     self.assertEqual(styledText, ('Hello', [29, 29, 29, 29, 29]))
        def logfile_lexer(self, start_pos, end_pos):
            ''' Main lexing logic.
                Gets called by styleneeded callback
            '''
            def style_it(match, STYLE):
                ''' Inform scintilla to do the styling'''
                if match[1] - match[0] >= 0:
                    editor.startStyling(start_pos + match[0], 31)
                    editor.setStyling(match[1] - match[0], STYLE)

            def do_regex(regex):
                ''' return a list of match positions 
                    Note, is using python regular expression instead of boost::re
                '''
                return [
                    m.span(0) for m in re.finditer(regex, text, flags=re.I)
                ]

            # ensure that position is really the first position for each line
            start_pos = editor.positionFromLine(
                editor.lineFromPosition(start_pos))
            # fast but potentially unsafe way to get the text of the line
            text = editor.getRangePointer(start_pos, end_pos - start_pos)

            # first everything will be styled with default style
            style_it((start_pos, end_pos), self.DEFAULT)

            # map style_it function to each match returned by do_regex
            # ordering is important as it might be that a line matches
            # multiple regexes - the last do_regex overwrites previous styling
            map(lambda match: style_it(match, self.WARNING_STYLE),
                do_regex(self.WARNING_REGEX))
            map(lambda match: style_it(match, self.ERROR_STYLE),
                do_regex(self.ERROR_REGEX))

            # this needs to stay and to be the last line, to signal scintilla we are done.
            editor.startStyling(end_pos, 31)
        def column_lexer(self, start_pos, end_pos):
            ''' Main lexing logic.
                Gets called by styleneeded callback
            '''
            
            def style_it(start, length, STYLE):
                ''' Inform scintilla to do the styling'''
                if length >= 0:
                    editor.startStyling(start, 31)
                    editor.setStyling(length, STYLE)

            # first everything will be styled with default style
            style_it(start_pos, end_pos-start_pos, self.DEFAULT)

            # loop over line indexes from start_pos and end_pos
            for line in range(editor.lineFromPosition(start_pos), editor.lineFromPosition(end_pos)):
                # get start position for each line
                line_start_pos = editor.positionFromLine(line)
                # split current line into columns
                columns = editor.getLine(line).split(self.COLUMN_SEPARATOR)
                if columns > 0:
                    # iterate over all columns
                    for i, column in enumerate(columns):
                        # get the width of the current column
                        col_length = len(column)
                        if i % 2 == 0:
                            # even column
                            style_it(line_start_pos,col_length,self.EVEN_COLUMN_STYLE)
                        else:
                            # odd column
                            style_it(line_start_pos,col_length, self.ODD_COLUMN_STYLE)
                        # recalculate start position for next column
                        line_start_pos += col_length+1

            # this needs to stay and to be the last line, to signal scintilla we are done.
            editor.startStyling(end_pos,31)
Exemple #5
0
        def column_lexer(self, start_pos, end_pos):
            ''' Main lexing logic.
                Gets called by styleneeded callback
            '''

            def style_it(start, length, STYLE):
                ''' Inform scintilla to do the styling'''
                if length >= 0:
                    editor.startStyling(start, 31)
                    editor.setStyling(length, STYLE)

            # first everything will be styled with default style
            style_it(start_pos, end_pos-start_pos, self.DEFAULT)

            # loop over line indexes from start_pos and end_pos
            for line in range(editor.lineFromPosition(start_pos), editor.lineFromPosition(end_pos)):
                # get start position for each line
                line_start_pos = editor.positionFromLine(line)
                # split current line into columns
                columns = editor.getLine(line).split(self.COLUMN_SEPARATOR)
                if columns > 0:
                    # iterate over all columns
                    for i, column in enumerate(columns):
                        # get the width of the current column
                        col_length = len(column)
                        if i % 2 == 0:
                            # even column
                            style_it(line_start_pos,col_length,self.EVEN_COLUMN_STYLE)
                        else:
                            # odd column
                            style_it(line_start_pos,col_length, self.ODD_COLUMN_STYLE)
                        # recalculate start position for next column
                        line_start_pos += col_length+1

            # this needs to stay and to be the last line, to signal scintilla we are done.
            editor.startStyling(end_pos,31)
 def style_it(match, STYLE):
     ''' Inform scintilla to do the styling'''
     if match[1] - match[0] >= 0:
         editor.startStyling(start_pos + match[0], 31)
         editor.setStyling(match[1] - match[0], STYLE)
 def style_it(start, length, STYLE):
     ''' Inform scintilla to do the styling'''
     if length >= 0:
         editor.startStyling(start, 31)
         editor.setStyling(length, STYLE)
 def style_it(match, STYLE):
     ''' Inform scintilla to do the styling'''
     if match[1]-match[0] >= 0:
         editor.startStyling(start_pos + match[0], 31)
         editor.setStyling(match[1]-match[0], STYLE)
Exemple #9
0
 def style_it(start, length, STYLE):
     ''' Inform scintilla to do the styling'''
     if length >= 0:
         editor.startStyling(start, 31)
         editor.setStyling(length, STYLE)