Beispiel #1
0
    def reformat(separator, area):
        separator = window.clipboard_get() if separator_dict.get(
            separator) == 'clipboard' else separator_dict.get(separator)

        used_eol = format_types_dict.get(notepad.getFormatType())

        editor.beginUndoAction()

        if area == 0:
            rows = editor.getCharacterPointer().splitlines()
            rows = prepare(separator, rows, used_eol)
            editor.setText(used_eol.join(rows))
        elif area == 1:
            if editor.selectionIsRectangle():

                selections = [(editor.getSelectionNStart(i),
                               editor.getSelectionNEnd(i))
                              for i in range(editor.getSelections())]
                rows = [
                    editor.getRangePointer(x, y - x) for x, y in selections
                ]
                rows = prepare(separator, rows, used_eol)

                editor.clearSelections()

                for i, position in zip(reversed(range(len(selections))),
                                       reversed(selections)):
                    editor.setTarget(*position)
                    editor.replaceTarget(rows[i])
            else:
                first_selected_line, last_selected_line = editor.getUserLineSelection(
                )
                startpos = editor.positionFromLine(first_selected_line)
                endpos = editor.positionFromLine(last_selected_line)

                rows = editor.getRangePointer(startpos, endpos - startpos)
                rows = prepare(separator, rows.split(used_eol), used_eol)

                editor.setTarget(startpos, endpos)
                editor.replaceTarget(used_eol.join(rows))
        else:
            first_visible_line = editor.getFirstVisibleLine()
            startpos = editor.positionFromLine(first_visible_line)
            endpos = editor.positionFromLine(editor.linesOnScreen() +
                                             first_visible_line)

            rows = editor.getRangePointer(startpos, endpos - startpos)
            rows = prepare(separator, rows.split(used_eol), used_eol)

            editor.setTarget(startpos, endpos)
            editor.replaceTarget(used_eol.join(rows))
        editor.endUndoAction()
        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)
Beispiel #3
0
    def reformat(separator,area):
        separator = window.clipboard_get() if separator_dict.get(separator) == 'clipboard' else separator_dict.get(separator)

        used_eol = format_types_dict.get(notepad.getFormatType())

        editor.beginUndoAction()

        if area == 0:
            rows = editor.getCharacterPointer().splitlines()
            rows = prepare(separator, rows, used_eol)
            editor.setText(used_eol.join(rows))
        elif area == 1:
            if editor.selectionIsRectangle():

                selections = [(editor.getSelectionNStart(i),editor.getSelectionNEnd(i)) for i in range(editor.getSelections())]
                rows = [editor.getRangePointer(x, y-x) for x,y in selections]
                rows = prepare(separator, rows, used_eol)

                editor.clearSelections()

                for i, position in zip(reversed(range(len(selections))), reversed(selections)):
                    editor.setTarget(*position)
                    editor.replaceTarget(rows[i])
            else:
                first_selected_line, last_selected_line = editor.getUserLineSelection()
                startpos = editor.positionFromLine(first_selected_line)
                endpos = editor.positionFromLine(last_selected_line)

                rows = editor.getRangePointer(startpos, endpos-startpos)
                rows = prepare(separator, rows.split(used_eol), used_eol)

                editor.setTarget(startpos, endpos)
                editor.replaceTarget(used_eol.join(rows))
        else:
            first_visible_line = editor.getFirstVisibleLine()
            startpos = editor.positionFromLine(first_visible_line)
            endpos = editor.positionFromLine(editor.linesOnScreen() + first_visible_line)

            rows = editor.getRangePointer(startpos, endpos-startpos)
            rows = prepare(separator, rows.split(used_eol), used_eol)

            editor.setTarget(startpos, endpos)
            editor.replaceTarget(used_eol.join(rows))
        editor.endUndoAction()
        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)
Beispiel #5
0
 def test_getRangePointer(self):
     editor.write('Hello world')
     rangeText = editor.getRangePointer(3, 5)
     self.assertEqual(rangeText, 'lo wo')