#NEWLINE# def _on_key_pressed( self , event ) : #NEWLINE# #INDENT# txt = event . text ( ) #NEWLINE# cursor = self . editor . textCursor ( ) #NEWLINE# from pyqode.qt import QtGui #NEWLINE# assert isinstance ( cursor , QtGui . QTextCursor ) #NEWLINE# if cursor . hasSelection ( ) : #NEWLINE# #INDENT# if ( event . text ( ) in self . MAPPING . keys ( ) ) : #NEWLINE# #INDENT# first = event . text ( ) #NEWLINE# last = self . MAPPING [ event . text ( ) ] #NEWLINE# cursor . insertText ( ( self . SELECTED_QUOTES_FORMATS [ event . text ( ) ] % ( first , cursor . selectedText ( ) , last ) ) ) #NEWLINE# self . editor . setTextCursor ( cursor ) #NEWLINE# event . accept ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _ignore_post = True #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# next_char = TextHelper ( self . editor ) . get_right_character ( ) #NEWLINE# self . logger . debug ( 'next char: %s' , next_char ) #NEWLINE# ignore = False #NEWLINE# if ( event . key ( ) == QtCore . Qt . Key_Backspace ) : #NEWLINE# #INDENT# tc = self . editor . textCursor ( ) #NEWLINE# pos = tc . position ( ) #NEWLINE# tc . movePosition ( tc . Left ) #NEWLINE# tc . movePosition ( tc . Right , tc . KeepAnchor ) #NEWLINE# del_char = tc . selectedText ( ) #NEWLINE# if ( ( pos in self . MAPPING ) and ( self . MAPPING [ del_char ] == next_char ) ) : #NEWLINE# #INDENT# tc . beginEditBlock ( ) #NEWLINE# tc . movePosition ( tc . Right , tc . KeepAnchor ) #NEWLINE# tc . insertText ( '' ) #NEWLINE# tc . setPosition ( ( pos - 2 ) ) #NEWLINE# tc . endEditBlock ( ) #NEWLINE# self . editor . setTextCursor ( tc ) #NEWLINE# ignore = True #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( txt and ( next_char == txt ) and ( next_char in self . MAPPING ) ) : #NEWLINE# #INDENT# ignore = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( event . text ( ) == ')' ) or ( event . text ( ) == ']' ) or ( event . text ( ) == '}' ) ) : #NEWLINE# #INDENT# if ( next_char == event . text ( ) ) : #NEWLINE# #INDENT# ignore = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ignore : #NEWLINE# #INDENT# event . accept ( ) #NEWLINE# TextHelper ( self . editor ) . clear_selection ( ) #NEWLINE# TextHelper ( self . editor ) . move_right ( )