Пример #1
0
    def run(self): 
        line_ending = ['\r\n', '\r', '\n'][notepad.getFormatType()]
              
        if editor.getSelectionEmpty():
            editor.setText(line_ending.join(self.__sort(editor.getCharacterPointer())))

        elif editor.getSelectionMode() == 1:
            print '-->> {}'.format(editor.getSelectionNStart(0))
            start = editor.getSelectionNStart(0)
            end = editor.getSelectionNEnd(0)
            start_column = editor.getColumn(start)
            end_column = editor.getColumn(end)
            line_start, line_end = editor.getUserLineSelection()
            start_position_selected_lines = editor.positionFromLine(line_start)
            end_position_selected_lines = editor.getLineEndPosition(line_end)
            
            def sort_as_int_if_possible(text):
                return int(text.strip()) if text.strip().isdigit() else text
            
            if (line_start==0) and (line_end==editor.getLineCount()-1):
                editor.setText(line_ending.join(self.__sort(editor.getCharacterPointer(),lambda x: sort_as_int_if_possible(x[start_column:end_column]))))
            else:
                lines = self.__sort(editor.getTextRange(start_position_selected_lines, end_position_selected_lines),
                                    lambda x: sort_as_int_if_possible(x[start_column:end_column]))
                
                print line_ending.join(lines)
                editor.setTarget(start_position_selected_lines, end_position_selected_lines)
                editor.replaceTarget(line_ending.join(lines))
        else:
            text_of_sel = editor.getTextRange(*editor.getUserCharSelection())
            line_end_of_sel = line_ending if text_of_sel.endswith(line_ending) else ''
            lines = self.__sort(text_of_sel)
            editor.replaceSel(line_ending.join(lines) + line_end_of_sel)

        self.window.destroy()
Пример #2
0
 def onCalltipClick(self, args):
     '''When clicked on the calltip write the full calltip in the output console.'''
     if self.activeCalltip == 'doc':  # and args['position']==0:
         var, calltip = self.interp.getFullCallTip()
         head = '=' * (40 - len(var) // 2 -
                       3) + ' Info: ' + var + ' ' + '=' * (
                           40 - len(var) // 2 - 3)
         foot = '=' * len(head)
         self.stdout('\n' + head + '\n' + ''.join(calltip) + '\n' + foot +
                     '\n')
     elif self.activeCalltip == True:
         editor.replaceSel('False')
     elif self.activeCalltip == False:
         editor.replaceSel('True')
     editor.callTipCancel()
     self.activeCalltip = None
Пример #3
0
    def run(self):
        line_ending = ['\r\n', '\r', '\n'][notepad.getFormatType()]

        if editor.getSelectionEmpty():
            editor.setText(
                line_ending.join(self.__sort(editor.getCharacterPointer())))

        elif editor.getSelectionMode() == 1:
            print '-->> {}'.format(editor.getSelectionNStart(0))
            start = editor.getSelectionNStart(0)
            end = editor.getSelectionNEnd(0)
            start_column = editor.getColumn(start)
            end_column = editor.getColumn(end)
            line_start, line_end = editor.getUserLineSelection()
            start_position_selected_lines = editor.positionFromLine(line_start)
            end_position_selected_lines = editor.getLineEndPosition(line_end)

            def sort_as_int_if_possible(text):
                return int(text.strip()) if text.strip().isdigit() else text

            if (line_start == 0) and (line_end == editor.getLineCount() - 1):
                editor.setText(
                    line_ending.join(
                        self.__sort(
                            editor.getCharacterPointer(),
                            lambda x: sort_as_int_if_possible(x[start_column:
                                                                end_column]))))
            else:
                lines = self.__sort(
                    editor.getTextRange(start_position_selected_lines,
                                        end_position_selected_lines), lambda x:
                    sort_as_int_if_possible(x[start_column:end_column]))

                print line_ending.join(lines)
                editor.setTarget(start_position_selected_lines,
                                 end_position_selected_lines)
                editor.replaceTarget(line_ending.join(lines))
        else:
            text_of_sel = editor.getTextRange(*editor.getUserCharSelection())
            line_end_of_sel = line_ending if text_of_sel.endswith(
                line_ending) else ''
            lines = self.__sort(text_of_sel)
            editor.replaceSel(line_ending.join(lines) + line_end_of_sel)

        self.window.destroy()