parameters: (self, event)
docstring: Key down event handler.
docstring_summary: Key down event handler.
docstring_tokens: Key down event handler .
function: def OnKeyDown(self, event):
          """Key down event handler."""
  
          key = event.GetKeyCode()
          # If the auto-complete window is up let it do its thing.
          if self.AutoCompActive():
              event.Skip()
              return
          
          # Prevent modification of previously submitted
          # commands/responses.
          controlDown = event.ControlDown()
          rawControlDown = event.RawControlDown()
          altDown = event.AltDown()
          shiftDown = event.ShiftDown()
          currpos = self.GetCurrentPos()
          endpos = self.GetTextLength()
          selecting = self.GetSelectionStart() != self.GetSelectionEnd()
          
          if (rawControlDown or controlDown) and shiftDown and key in (ord('F'), ord('f')): 
              li = self.GetCurrentLine()
              m = self.MarkerGet(li)
              if m & 1<<0:
                  startP = self.PositionFromLine(li)
                  self.MarkerDelete(li, 0)
                  maxli = self.GetLineCount()
                  li += 1 # li stayed visible as header-line
                  li0 = li 
                  while li<maxli and self.GetLineVisible(li) == 0:
                      li += 1
                  endP = self.GetLineEndPosition(li-1)
                  self.ShowLines(li0, li-1)
                  # select reappearing text to allow "hide again"
                  self.SetSelection( startP, endP )
                  return
              startP,endP = self.GetSelection()
              endP-=1
              startL = self.LineFromPosition(startP)
              endL = self.LineFromPosition(endP)
  
              # never hide last prompt
              if endL == self.LineFromPosition(self.promptPosEnd):
                  endL -= 1
  
              m = self.MarkerGet(startL)
              self.MarkerAdd(startL, 0)
              self.HideLines(startL+1,endL)
              self.SetCurrentPos( startP ) # to ensure caret stays visible !
  
          if key == wx.WXK_F12: #seb
              if self.noteMode:
                  # self.promptPosStart not used anyway - or ? 
                  self.promptPosEnd = \
                     self.PositionFromLine( self.GetLineCount()-1 ) + \
                     len(str(sys.ps1))
                  self.GotoLine(self.GetLineCount())
                  self.GotoPos(self.promptPosEnd)
                  self.prompt()  #make sure we have a prompt
                  self.SetCaretForeground("black")
                  self.SetCaretWidth(1)    #default
                  self.SetCaretPeriod(500) #default
              else:
                  self.SetCaretForeground("red")
                  self.SetCaretWidth(4)
                  self.SetCaretPeriod(0) #steady
  
              self.noteMode = not self.noteMode
              return
          if self.noteMode:
              event.Skip()
              return
  
          # Return (Enter) is used to submit a command to the
          # interpreter.
          if (not (rawControlDown or controlDown) and not shiftDown and not altDown) and \
             key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
              if self.CallTipActive():
                  self.CallTipCancel()
              self.processLine()
              
          # Complete Text (from already typed words)    
          elif shiftDown and key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
              self.OnShowCompHistory()
              
          # Ctrl+Return (Ctrl+Enter) is used to insert a line break.
          elif (rawControlDown or controlDown) and key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
              if self.CallTipActive():
                  self.CallTipCancel()
              if currpos == endpos:
                  self.processLine()
              else:
                  self.insertLineBreak()
                  
          # Let Ctrl-Alt-* get handled normally.
          elif (rawControlDown or controlDown) and altDown:
              event.Skip()
              
          # Clear the current, unexecuted command.
          elif key == wx.WXK_ESCAPE:
              if self.CallTipActive():
                  event.Skip()
              else:
                  self.clearCommand()
  
          # Clear the current command
          elif key == wx.WXK_BACK and (rawControlDown or controlDown) and shiftDown:
              self.clearCommand()
  
          # Increase font size.
          elif (rawControlDown or controlDown) and key in (ord(']'), wx.WXK_NUMPAD_ADD):
              dispatcher.send(signal='FontIncrease')
  
          # Decrease font size.
          elif (rawControlDown or controlDown) and key in (ord('['), wx.WXK_NUMPAD_SUBTRACT):
              dispatcher.send(signal='FontDecrease')
  
          # Default font size.
          elif (rawControlDown or controlDown) and key in (ord('='), wx.WXK_NUMPAD_DIVIDE):
              dispatcher.send(signal='FontDefault')
  
          # Cut to the clipboard.
          elif ((rawControlDown or controlDown) and key in (ord('X'), ord('x'))) \
                   or (shiftDown and key == wx.WXK_DELETE):
              self.Cut()
  
          # Copy to the clipboard.
          elif (rawControlDown or controlDown) and not shiftDown \
                   and key in (ord('C'), ord('c'), wx.WXK_INSERT):
              self.Copy()
  
          # Copy to the clipboard, including prompts.
          elif (rawControlDown or controlDown) and shiftDown \
                   and key in (ord('C'), ord('c'), wx.WXK_INSERT):
              self.CopyWithPrompts()
  
          # Copy to the clipboard, including prefixed prompts.
          elif altDown and not controlDown \
                   and key in (ord('C'), ord('c'), wx.WXK_INSERT):
              self.CopyWithPromptsPrefixed()
  
          # Home needs to be aware of the prompt.
          elif (rawControlDown or controlDown) and key == wx.WXK_HOME:
              home = self.promptPosEnd
              if currpos > home:
                  self.SetCurrentPos(home)
                  if not selecting and not shiftDown:
                      self.SetAnchor(home)
                      self.EnsureCaretVisible()
              else:
                  event.Skip()
  
          # Home needs to be aware of the prompt.
          elif key == wx.WXK_HOME:
              home = self.promptPosEnd
              if currpos > home:
                  [line_str,line_len] = self.GetCurLine()
                  pos=self.GetCurrentPos()
                  if line_str[:4] in [sys.ps1,sys.ps2,sys.ps3]:
                      self.SetCurrentPos(pos+4-line_len)
                      #self.SetCurrentPos(home)
                      if not selecting and not shiftDown:
                          self.SetAnchor(pos+4-line_len)
                          self.EnsureCaretVisible()
                  else:
                      event.Skip()
              else:
                  event.Skip()
          
          #
          # The following handlers modify text, so we need to see if
          # there is a selection that includes text prior to the prompt.
          #
          # Don't modify a selection with text prior to the prompt.
          elif selecting and key not in NAVKEYS and not self.CanEdit():
              pass
  
          # Paste from the clipboard.
          elif ((rawControlDown or controlDown) and not shiftDown and key in (ord('V'), ord('v'))) \
                   or (shiftDown and not controlDown and key == wx.WXK_INSERT):
              self.Paste()
  
          # manually invoke AutoComplete and Calltips
          elif (rawControlDown or controlDown) and key == wx.WXK_SPACE:
              self.OnCallTipAutoCompleteManually(shiftDown)
  
          # Paste from the clipboard, run commands.
          elif (rawControlDown or controlDown) and shiftDown and key in (ord('V'), ord('v')):
              self.PasteAndRun()
              
          # Replace with the previous command from the history buffer.
          elif ((rawControlDown or controlDown) and not shiftDown and key == wx.WXK_UP) \
                   or (altDown and key in (ord('P'), ord('p'))):
              self.OnHistoryReplace(step=+1)
              
          # Replace with the next command from the history buffer.
          elif ((rawControlDown or controlDown) and not shiftDown and key == wx.WXK_DOWN) \
                   or (altDown and key in (ord('N'), ord('n'))):
              self.OnHistoryReplace(step=-1)
              
          # Insert the previous command from the history buffer.
          elif ((rawControlDown or controlDown) and shiftDown and key == wx.WXK_UP) and self.CanEdit():
              self.OnHistoryInsert(step=+1)
              
          # Insert the next command from the history buffer.
          elif ((rawControlDown or controlDown) and shiftDown and key == wx.WXK_DOWN) and self.CanEdit():
              self.OnHistoryInsert(step=-1)
              
          # Search up the history for the text in front of the cursor.
          elif key == wx.WXK_F8:
              self.OnHistorySearch()
              
          # Don't backspace over the latest non-continuation prompt.
          elif key == wx.WXK_BACK:
              if selecting and self.CanEdit():
                  event.Skip()
              elif currpos > self.promptPosEnd:
                  event.Skip()
                  
          # Only allow these keys after the latest prompt.
          elif key in (wx.WXK_TAB, wx.WXK_DELETE):
              if self.CanEdit():
                  event.Skip()
                  
          # Don't toggle between insert mode and overwrite mode.
          elif key == wx.WXK_INSERT:
              pass
          
          # Don't allow line deletion.
          elif controlDown and key in (ord('L'), ord('l')):
              # TODO : Allow line deletion eventually...
              #event.Skip()
              pass
  
          # Don't allow line transposition.
          elif controlDown and key in (ord('T'), ord('t')):
              # TODO : Allow line transposition eventually...
              # TODO : Will have to adjust markers accordingly and test if allowed...
              #event.Skip()
              pass
  
          # Basic navigation keys should work anywhere.
          elif key in NAVKEYS:
              event.Skip()
  
          # Protect the readonly portion of the shell.
          elif not self.CanEdit():
              pass
  
          else:
              event.Skip()
function_tokens: def OnKeyDown ( self , event ) : key = event . GetKeyCode ( ) # If the auto-complete window is up let it do its thing. if self . AutoCompActive ( ) : event . Skip ( ) return # Prevent modification of previously submitted # commands/responses. controlDown = event . ControlDown ( ) rawControlDown = event . RawControlDown ( ) altDown = event . AltDown ( ) shiftDown = event . ShiftDown ( ) currpos = self . GetCurrentPos ( ) endpos = self . GetTextLength ( ) selecting = self . GetSelectionStart ( ) != self . GetSelectionEnd ( ) if ( rawControlDown or controlDown ) and shiftDown and key in ( ord ( 'F' ) , ord ( 'f' ) ) : li = self . GetCurrentLine ( ) m = self . MarkerGet ( li ) if m & 1 << 0 : startP = self . PositionFromLine ( li ) self . MarkerDelete ( li , 0 ) maxli = self . GetLineCount ( ) li += 1 # li stayed visible as header-line li0 = li while li < maxli and self . GetLineVisible ( li ) == 0 : li += 1 endP = self . GetLineEndPosition ( li - 1 ) self . ShowLines ( li0 , li - 1 ) # select reappearing text to allow "hide again" self . SetSelection ( startP , endP ) return startP , endP = self . GetSelection ( ) endP -= 1 startL = self . LineFromPosition ( startP ) endL = self . LineFromPosition ( endP ) # never hide last prompt if endL == self . LineFromPosition ( self . promptPosEnd ) : endL -= 1 m = self . MarkerGet ( startL ) self . MarkerAdd ( startL , 0 ) self . HideLines ( startL + 1 , endL ) self . SetCurrentPos ( startP ) # to ensure caret stays visible ! if key == wx . WXK_F12 : #seb if self . noteMode : # self.promptPosStart not used anyway - or ?  self . promptPosEnd = self . PositionFromLine ( self . GetLineCount ( ) - 1 ) + len ( str ( sys . ps1 ) ) self . GotoLine ( self . GetLineCount ( ) ) self . GotoPos ( self . promptPosEnd ) self . prompt ( ) #make sure we have a prompt self . SetCaretForeground ( "black" ) self . SetCaretWidth ( 1 ) #default self . SetCaretPeriod ( 500 ) #default else : self . SetCaretForeground ( "red" ) self . SetCaretWidth ( 4 ) self . SetCaretPeriod ( 0 ) #steady self . noteMode = not self . noteMode return if self . noteMode : event . Skip ( ) return # Return (Enter) is used to submit a command to the # interpreter. if ( not ( rawControlDown or controlDown ) and not shiftDown and not altDown ) and key in [ wx . WXK_RETURN , wx . WXK_NUMPAD_ENTER ] : if self . CallTipActive ( ) : self . CallTipCancel ( ) self . processLine ( ) # Complete Text (from already typed words)     elif shiftDown and key in [ wx . WXK_RETURN , wx . WXK_NUMPAD_ENTER ] : self . OnShowCompHistory ( ) # Ctrl+Return (Ctrl+Enter) is used to insert a line break. elif ( rawControlDown or controlDown ) and key in [ wx . WXK_RETURN , wx . WXK_NUMPAD_ENTER ] : if self . CallTipActive ( ) : self . CallTipCancel ( ) if currpos == endpos : self . processLine ( ) else : self . insertLineBreak ( ) # Let Ctrl-Alt-* get handled normally. elif ( rawControlDown or controlDown ) and altDown : event . Skip ( ) # Clear the current, unexecuted command. elif key == wx . WXK_ESCAPE : if self . CallTipActive ( ) : event . Skip ( ) else : self . clearCommand ( ) # Clear the current command elif key == wx . WXK_BACK and ( rawControlDown or controlDown ) and shiftDown : self . clearCommand ( ) # Increase font size. elif ( rawControlDown or controlDown ) and key in ( ord ( ']' ) , wx . WXK_NUMPAD_ADD ) : dispatcher . send ( signal = 'FontIncrease' ) # Decrease font size. elif ( rawControlDown or controlDown ) and key in ( ord ( '[' ) , wx . WXK_NUMPAD_SUBTRACT ) : dispatcher . send ( signal = 'FontDecrease' ) # Default font size. elif ( rawControlDown or controlDown ) and key in ( ord ( '=' ) , wx . WXK_NUMPAD_DIVIDE ) : dispatcher . send ( signal = 'FontDefault' ) # Cut to the clipboard. elif ( ( rawControlDown or controlDown ) and key in ( ord ( 'X' ) , ord ( 'x' ) ) ) or ( shiftDown and key == wx . WXK_DELETE ) : self . Cut ( ) # Copy to the clipboard. elif ( rawControlDown or controlDown ) and not shiftDown and key in ( ord ( 'C' ) , ord ( 'c' ) , wx . WXK_INSERT ) : self . Copy ( ) # Copy to the clipboard, including prompts. elif ( rawControlDown or controlDown ) and shiftDown and key in ( ord ( 'C' ) , ord ( 'c' ) , wx . WXK_INSERT ) : self . CopyWithPrompts ( ) # Copy to the clipboard, including prefixed prompts. elif altDown and not controlDown and key in ( ord ( 'C' ) , ord ( 'c' ) , wx . WXK_INSERT ) : self . CopyWithPromptsPrefixed ( ) # Home needs to be aware of the prompt. elif ( rawControlDown or controlDown ) and key == wx . WXK_HOME : home = self . promptPosEnd if currpos > home : self . SetCurrentPos ( home ) if not selecting and not shiftDown : self . SetAnchor ( home ) self . EnsureCaretVisible ( ) else : event . Skip ( ) # Home needs to be aware of the prompt. elif key == wx . WXK_HOME : home = self . promptPosEnd if currpos > home : [ line_str , line_len ] = self . GetCurLine ( ) pos = self . GetCurrentPos ( ) if line_str [ : 4 ] in [ sys . ps1 , sys . ps2 , sys . ps3 ] : self . SetCurrentPos ( pos + 4 - line_len ) #self.SetCurrentPos(home) if not selecting and not shiftDown : self . SetAnchor ( pos + 4 - line_len ) self . EnsureCaretVisible ( ) else : event . Skip ( ) else : event . Skip ( ) # # The following handlers modify text, so we need to see if # there is a selection that includes text prior to the prompt. # # Don't modify a selection with text prior to the prompt. elif selecting and key not in NAVKEYS and not self . CanEdit ( ) : pass # Paste from the clipboard. elif ( ( rawControlDown or controlDown ) and not shiftDown and key in ( ord ( 'V' ) , ord ( 'v' ) ) ) or ( shiftDown and not controlDown and key == wx . WXK_INSERT ) : self . Paste ( ) # manually invoke AutoComplete and Calltips elif ( rawControlDown or controlDown ) and key == wx . WXK_SPACE : self . OnCallTipAutoCompleteManually ( shiftDown ) # Paste from the clipboard, run commands. elif ( rawControlDown or controlDown ) and shiftDown and key in ( ord ( 'V' ) , ord ( 'v' ) ) : self . PasteAndRun ( ) # Replace with the previous command from the history buffer. elif ( ( rawControlDown or controlDown ) and not shiftDown and key == wx . WXK_UP ) or ( altDown and key in ( ord ( 'P' ) , ord ( 'p' ) ) ) : self . OnHistoryReplace ( step = + 1 ) # Replace with the next command from the history buffer. elif ( ( rawControlDown or controlDown ) and not shiftDown and key == wx . WXK_DOWN ) or ( altDown and key in ( ord ( 'N' ) , ord ( 'n' ) ) ) : self . OnHistoryReplace ( step = - 1 ) # Insert the previous command from the history buffer. elif ( ( rawControlDown or controlDown ) and shiftDown and key == wx . WXK_UP ) and self . CanEdit ( ) : self . OnHistoryInsert ( step = + 1 ) # Insert the next command from the history buffer. elif ( ( rawControlDown or controlDown ) and shiftDown and key == wx . WXK_DOWN ) and self . CanEdit ( ) : self . OnHistoryInsert ( step = - 1 ) # Search up the history for the text in front of the cursor. elif key == wx . WXK_F8 : self . OnHistorySearch ( ) # Don't backspace over the latest non-continuation prompt. elif key == wx . WXK_BACK : if selecting and self . CanEdit ( ) : event . Skip ( ) elif currpos > self . promptPosEnd : event . Skip ( ) # Only allow these keys after the latest prompt. elif key in ( wx . WXK_TAB , wx . WXK_DELETE ) : if self . CanEdit ( ) : event . Skip ( ) # Don't toggle between insert mode and overwrite mode. elif key == wx . WXK_INSERT : pass # Don't allow line deletion. elif controlDown and key in ( ord ( 'L' ) , ord ( 'l' ) ) : # TODO : Allow line deletion eventually... #event.Skip() pass # Don't allow line transposition. elif controlDown and key in ( ord ( 'T' ) , ord ( 't' ) ) : # TODO : Allow line transposition eventually... # TODO : Will have to adjust markers accordingly and test if allowed... #event.Skip() pass # Basic navigation keys should work anywhere. elif key in NAVKEYS : event . Skip ( ) # Protect the readonly portion of the shell. elif not self . CanEdit ( ) : pass else : event . Skip ( )