def style(self):
     line_number = editor.getFirstVisibleLine()
     start_position = editor.positionFromLine(line_number)
     end_position = editor.getLineEndPosition(line_number +
                                              editor.linesOnScreen())
     for indicator, regex in self.regex_dict.items():
         self.do_regex(regex, indicator, start_position, end_position)
Example #2
0
    def style(self):
        '''
            Calculates the text area to be searched for in the current document.
            Calls up the regexes to find the position and
            calculates the length of the text to be colored.
            Deletes the old indicators before setting new ones.

            Args:
                None
            Returns:
                None
        '''

        start_line = editor.docLineFromVisible(editor.getFirstVisibleLine())
        end_line = editor.docLineFromVisible(start_line +
                                             editor.linesOnScreen())
        if editor.getWrapMode():
            end_line = sum([editor.wrapCount(x) for x in range(end_line)])

        onscreen_start_position = editor.positionFromLine(start_line)
        onscreen_end_pos = editor.getLineEndPosition(end_line)

        editor.setIndicatorCurrent(0)
        editor.indicatorClearRange(0, editor.getTextLength())
        for color, regex in self.regexes.items():
            editor.research(
                regex[0], lambda m: self.paint_it(
                    color[1],
                    m.span(regex[1])[0],
                    m.span(regex[1])[1] - m.span(regex[1])[0],
                    onscreen_start_position, onscreen_end_pos), 0,
                onscreen_start_position, onscreen_end_pos)
Example #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()
Example #4
0
    def style(self):
        line_number = editor.getFirstVisibleLine()
        start_position = editor.positionFromLine(line_number)
        end_position = editor.getLineEndPosition(line_number +
                                                 editor.linesOnScreen())
        editor.setIndicatorCurrent(self.indicator)
        editor.indicatorClearRange(start_position,
                                   end_position - start_position)

        flag = 0
        editor.research(
            '^# ?%%(.*)$',
            lambda m: self.paint_it(self.indicator,
                                    m.span(flag)[0],
                                    m.span(flag)[1] - m.span(flag)[0]), 0,
            start_position, end_position)
Example #5
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 style(self):
     line_number = editor.getFirstVisibleLine()
     start_position = editor.positionFromLine(line_number)
     end_position = editor.getLineEndPosition(line_number + editor.linesOnScreen())
     for indicator, regex in self.regex_dict.items():
         self.do_regex(regex, indicator, start_position, end_position)