parameters: (self, char, pos, sel_start, sel_to, value, allowAutoSelect=False)
docstring: Handles replacement of the character at the current insertion point.
docstring_summary: Handles replacement of the character at the current insertion point.
docstring_tokens: Handles replacement of the character at the current insertion point .
function: def _insertKey(self, char, pos, sel_start, sel_to, value, allowAutoSelect=False):
          """ Handles replacement of the character at the current insertion point."""
  ##        dbg('MaskedEditMixin::_insertKey', "\'" + char + "\'", pos, sel_start, sel_to, '"%s"' % value, indent=1)
  
          text = self._eraseSelection(value)
          field = self._FindField(pos)
          start, end = field._extent
          newtext = ""
          newpos = pos
  
          # if >= 2 chars selected in a right-insert field, do appropriate erase on field,
          # then set selection to end, and do usual right insert.
          if sel_start != sel_to and sel_to >= sel_start+2:
              field = self._FindField(sel_start)
              if( field._insertRight                          # if right-insert
                  and field._allowInsert                      # and allow insert at any point in field
                  and field == self._FindField(sel_to) ):     # and selection all in same field
                  text = self._OnErase(just_return_value=True)    # remove selection before insert
  ##                dbg('text after (left)erase: "%s"' % text)
                  pos = sel_start = sel_to
  
          if pos != sel_start and sel_start == sel_to:
              # adjustpos must have moved the position; make selection match:
              sel_start = sel_to = pos
  
  ##        dbg('field._insertRight?', field._insertRight)
  ##        dbg('field._allowInsert?', field._allowInsert)
  ##        dbg('sel_start, end', sel_start, end)
          if sel_start < end:
  ##            dbg('text[sel_start] != field._fillChar?', text[sel_start] != field._fillChar)
              pass
  
          if( field._insertRight                                  # field allows right insert
              and ((sel_start, sel_to) == field._extent           # and whole field selected
                   or (sel_start == sel_to                        # or nothing selected
                       and (sel_start == end                      # and cursor at right edge
                            or (field._allowInsert                # or field allows right-insert
                                and sel_start < end               # next to other char in field:
                                and text[sel_start] != field._fillChar) ) ) ) ):
  ##            dbg('insertRight')
              fstr = text[start:end]
              erasable_chars = [field._fillChar, ' ']
  
              # if zero padding field, or a single digit, and currently a value of 0, allow erasure of 0:
              if field._padZero or (field._isInt and (end - start == 1) and fstr[0] == '0'):
                  erasable_chars.append('0')
  
              erased = ''
  ####            dbg("fstr[0]:'%s'" % fstr[0])
  ####            dbg('field_index:', field._index)
  ####            dbg("fstr[0] in erasable_chars?", fstr[0] in erasable_chars)
  ####            dbg("self._signOk and field._index == 0 and fstr[0] in ('-','(')?", self._signOk and field._index == 0 and fstr[0] in ('-','('))
              if fstr[0] in erasable_chars or (self._signOk and field._index == 0 and fstr[0] in ('-','(')):
                  erased = fstr[0]
  ####                dbg('value:      "%s"' % text)
  ####                dbg('fstr:       "%s"' % fstr)
  ####                dbg("erased:     '%s'" % erased)
                  field_sel_start = sel_start - start
                  field_sel_to = sel_to - start
  ##                dbg('left fstr:  "%s"' % fstr[1:field_sel_start])
  ##                dbg('right fstr: "%s"' % fstr[field_sel_to:end])
                  fstr = fstr[1:field_sel_start] + char + fstr[field_sel_to:end]
              if field._alignRight and sel_start != sel_to:
                  field_len = end - start
  ##                pos += (field_len - len(fstr))    # move cursor right by deleted amount
                  pos = sel_to
  ##                dbg('setting pos to:', pos)
                  if field._padZero:
                      fstr = '0' * (field_len - len(fstr)) + fstr
                  else:
                      fstr = fstr.rjust(field_len)   # adjust the field accordingly
  ##            dbg('field str: "%s"' % fstr)
  
              newtext = text[:start] + fstr + text[end:]
              if erased in ('-', '(') and self._signOk:
                  newtext = erased + newtext[1:]
  ##            dbg('newtext: "%s"' % newtext)
  
              if self._signOk and field._index == 0:
                  start -= 1             # account for sign position
  
  ####            dbg('field._moveOnFieldFull?', field._moveOnFieldFull)
  ####            dbg('len(fstr.lstrip()) == end-start?', len(fstr.lstrip()) == end-start)
              if( field._moveOnFieldFull and pos == end
                  and len(fstr.lstrip()) == end-start     # if field now full
                  and (not field._stopFieldChangeIfInvalid     # and we either don't care about valid
                       or (field._stopFieldChangeIfInvalid     # or we do and the current field value is valid
                           and field.IsValid(fstr)))):
  
                  newpos = self._findNextEntry(end)       #   go to next field
              else:
                  newpos = pos                            # else keep cursor at current position
  
          if not newtext:
  ##            dbg('not newtext')
              if newpos != pos:
  ##                dbg('newpos:', newpos)
                  pass
              if self._signOk and self._useParens:
                  old_right_signpos = text.find(')')
  
              if field._allowInsert and not field._insertRight and sel_to <= end and sel_start >= start:
  ##                dbg('inserting within a left-insert-capable field')
                  field_len = end - start
                  before = text[start:sel_start]
                  after = text[sel_to:end].strip()
  ####                dbg("current field:'%s'" % text[start:end])
  ####                dbg("before:'%s'" % before, "after:'%s'" % after)
                  new_len = len(before) + len(after) + 1 # (for inserted char)
  ####                dbg('new_len:', new_len)
  
                  if new_len < field_len:
                      retained = after + self._template[end-(field_len-new_len):end]
                  elif new_len > end-start:
                      retained = after[1:]
                  else:
                      retained = after
  
                  left = text[0:start] + before
  ####                dbg("left:'%s'" % left, "retained:'%s'" % retained)
                  right   = retained + text[end:]
              else:
                  left  = text[0:pos]
                  right   = text[pos+1:]
  
              if 'unicode' in wx.PlatformInfo and type(char) != types.UnicodeType:
                  # convert the keyboard constant to a unicode value, to
                  # ensure it can be concatenated into the control value:
                  char = char.decode(self._defaultEncoding)
  
              newtext = left + char + right
  ####            dbg('left:    "%s"' % left)
  ####            dbg('right:   "%s"' % right)
  ####            dbg('newtext: "%s"' % newtext)
  
              if self._signOk and self._useParens:
                  # Balance parentheses:
                  left_signpos = newtext.find('(')
  
                  if left_signpos == -1:     # erased '('; remove ')'
                      right_signpos = newtext.find(')')
                      if right_signpos != -1:
                          newtext = newtext[:right_signpos] + ' ' + newtext[right_signpos+1:]
  
                  elif old_right_signpos != -1:
                      right_signpos = newtext.find(')')
  
                      if right_signpos == -1: # just replaced right-paren
                          if newtext[pos] == ' ': # we just erased '); erase '('
                              newtext = newtext[:left_signpos] + ' ' + newtext[left_signpos+1:]
                          else:   # replaced with digit; move ') over
                              if self._ctrl_constraints._alignRight or self._isFloat:
                                  newtext = newtext[:-1] + ')'
                              else:
                                  rstripped_text = newtext.rstrip()
                                  right_signpos = len(rstripped_text)
  ##                                dbg('old_right_signpos:', old_right_signpos, 'right signpos now:', right_signpos)
                                  newtext = newtext[:right_signpos] + ')' + newtext[right_signpos+1:]
  
              if( field._insertRight                                  # if insert-right field (but we didn't start at right edge)
                  and field._moveOnFieldFull                          # and should move cursor when full
                  and len(newtext[start:end].strip()) == end-start    # and field now full
                  and (not field._stopFieldChangeIfInvalid            # and we either don't care about valid
                       or (field._stopFieldChangeIfInvalid            # or we do and the current field value is valid
                           and field.IsValid(newtext[start:end].strip())))):
  
                  newpos = self._findNextEntry(end)                   #   go to next field
  ##                dbg('newpos = nextentry =', newpos)
              else:
  ##                dbg('pos:', pos, 'newpos:', pos+1)
                  newpos = pos+1
  
  
          if allowAutoSelect:
              new_select_to = newpos     # (default return values)
              match_field = None
              match_index = None
  
              if field._autoSelect:
                  match_index, partial_match = self._autoComplete(1,  # (always forward)
                                                                  field._compareChoices,
                                                                  newtext[start:end],
                                                                  compareNoCase=field._compareNoCase,
                                                                  current_index = field._autoCompleteIndex-1)
                  if match_index is not None and partial_match:
                      matched_str = newtext[start:end]
                      newtext = newtext[:start] + field._choices[match_index] + newtext[end:]
                      new_select_to = end
                      match_field = field
                      if field._insertRight:
                          # adjust position to just after partial match in field
                          newpos = end - (len(field._choices[match_index].strip()) - len(matched_str.strip()))
  
              elif self._ctrl_constraints._autoSelect:
                  match_index, partial_match = self._autoComplete(
                                          1,  # (always forward)
                                          self._ctrl_constraints._compareChoices,
                                          newtext,
                                          self._ctrl_constraints._compareNoCase,
                                          current_index = self._ctrl_constraints._autoCompleteIndex - 1)
                  if match_index is not None and partial_match:
                      matched_str = newtext
                      newtext = self._ctrl_constraints._choices[match_index]
                      edit_end = self._ctrl_constraints._extent[1]
                      new_select_to = min(edit_end, len(newtext.rstrip()))
                      match_field = self._ctrl_constraints
                      if self._ctrl_constraints._insertRight:
                          # adjust position to just after partial match in control:
                          newpos = self._masklength - (len(self._ctrl_constraints._choices[match_index].strip()) - len(matched_str.strip()))
  
  ##            dbg('newtext: "%s"' % newtext, 'newpos:', newpos, 'new_select_to:', new_select_to)
  ##            dbg(indent=0)
              return newtext, newpos, new_select_to, match_field, match_index
          else:
  ##            dbg('newtext: "%s"' % newtext, 'newpos:', newpos)
  ##            dbg(indent=0)
              return newtext, newpos
function_tokens: def _insertKey ( self , char , pos , sel_start , sel_to , value , allowAutoSelect = False ) : ##        dbg('MaskedEditMixin::_insertKey', "\'" + char + "\'", pos, sel_start, sel_to, '"%s"' % value, indent=1) text = self . _eraseSelection ( value ) field = self . _FindField ( pos ) start , end = field . _extent newtext = "" newpos = pos # if >= 2 chars selected in a right-insert field, do appropriate erase on field, # then set selection to end, and do usual right insert. if sel_start != sel_to and sel_to >= sel_start + 2 : field = self . _FindField ( sel_start ) if ( field . _insertRight # if right-insert and field . _allowInsert # and allow insert at any point in field and field == self . _FindField ( sel_to ) ) : # and selection all in same field text = self . _OnErase ( just_return_value = True ) # remove selection before insert ##                dbg('text after (left)erase: "%s"' % text) pos = sel_start = sel_to if pos != sel_start and sel_start == sel_to : # adjustpos must have moved the position; make selection match: sel_start = sel_to = pos ##        dbg('field._insertRight?', field._insertRight) ##        dbg('field._allowInsert?', field._allowInsert) ##        dbg('sel_start, end', sel_start, end) if sel_start < end : ##            dbg('text[sel_start] != field._fillChar?', text[sel_start] != field._fillChar) pass if ( field . _insertRight # field allows right insert and ( ( sel_start , sel_to ) == field . _extent # and whole field selected or ( sel_start == sel_to # or nothing selected and ( sel_start == end # and cursor at right edge or ( field . _allowInsert # or field allows right-insert and sel_start < end # next to other char in field: and text [ sel_start ] != field . _fillChar ) ) ) ) ) : ##            dbg('insertRight') fstr = text [ start : end ] erasable_chars = [ field . _fillChar , ' ' ] # if zero padding field, or a single digit, and currently a value of 0, allow erasure of 0: if field . _padZero or ( field . _isInt and ( end - start == 1 ) and fstr [ 0 ] == '0' ) : erasable_chars . append ( '0' ) erased = '' ####            dbg("fstr[0]:'%s'" % fstr[0]) ####            dbg('field_index:', field._index) ####            dbg("fstr[0] in erasable_chars?", fstr[0] in erasable_chars) ####            dbg("self._signOk and field._index == 0 and fstr[0] in ('-','(')?", self._signOk and field._index == 0 and fstr[0] in ('-','(')) if fstr [ 0 ] in erasable_chars or ( self . _signOk and field . _index == 0 and fstr [ 0 ] in ( '-' , '(' ) ) : erased = fstr [ 0 ] ####                dbg('value:      "%s"' % text) ####                dbg('fstr:       "%s"' % fstr) ####                dbg("erased:     '%s'" % erased) field_sel_start = sel_start - start field_sel_to = sel_to - start ##                dbg('left fstr:  "%s"' % fstr[1:field_sel_start]) ##                dbg('right fstr: "%s"' % fstr[field_sel_to:end]) fstr = fstr [ 1 : field_sel_start ] + char + fstr [ field_sel_to : end ] if field . _alignRight and sel_start != sel_to : field_len = end - start ##                pos += (field_len - len(fstr))    # move cursor right by deleted amount pos = sel_to ##                dbg('setting pos to:', pos) if field . _padZero : fstr = '0' * ( field_len - len ( fstr ) ) + fstr else : fstr = fstr . rjust ( field_len ) # adjust the field accordingly ##            dbg('field str: "%s"' % fstr) newtext = text [ : start ] + fstr + text [ end : ] if erased in ( '-' , '(' ) and self . _signOk : newtext = erased + newtext [ 1 : ] ##            dbg('newtext: "%s"' % newtext) if self . _signOk and field . _index == 0 : start -= 1 # account for sign position ####            dbg('field._moveOnFieldFull?', field._moveOnFieldFull) ####            dbg('len(fstr.lstrip()) == end-start?', len(fstr.lstrip()) == end-start) if ( field . _moveOnFieldFull and pos == end and len ( fstr . lstrip ( ) ) == end - start # if field now full and ( not field . _stopFieldChangeIfInvalid # and we either don't care about valid or ( field . _stopFieldChangeIfInvalid # or we do and the current field value is valid and field . IsValid ( fstr ) ) ) ) : newpos = self . _findNextEntry ( end ) #   go to next field else : newpos = pos # else keep cursor at current position if not newtext : ##            dbg('not newtext') if newpos != pos : ##                dbg('newpos:', newpos) pass if self . _signOk and self . _useParens : old_right_signpos = text . find ( ')' ) if field . _allowInsert and not field . _insertRight and sel_to <= end and sel_start >= start : ##                dbg('inserting within a left-insert-capable field') field_len = end - start before = text [ start : sel_start ] after = text [ sel_to : end ] . strip ( ) ####                dbg("current field:'%s'" % text[start:end]) ####                dbg("before:'%s'" % before, "after:'%s'" % after) new_len = len ( before ) + len ( after ) + 1 # (for inserted char) ####                dbg('new_len:', new_len) if new_len < field_len : retained = after + self . _template [ end - ( field_len - new_len ) : end ] elif new_len > end - start : retained = after [ 1 : ] else : retained = after left = text [ 0 : start ] + before ####                dbg("left:'%s'" % left, "retained:'%s'" % retained) right = retained + text [ end : ] else : left = text [ 0 : pos ] right = text [ pos + 1 : ] if 'unicode' in wx . PlatformInfo and type ( char ) != types . UnicodeType : # convert the keyboard constant to a unicode value, to # ensure it can be concatenated into the control value: char = char . decode ( self . _defaultEncoding ) newtext = left + char + right ####            dbg('left:    "%s"' % left) ####            dbg('right:   "%s"' % right) ####            dbg('newtext: "%s"' % newtext) if self . _signOk and self . _useParens : # Balance parentheses: left_signpos = newtext . find ( '(' ) if left_signpos == - 1 : # erased '('; remove ')' right_signpos = newtext . find ( ')' ) if right_signpos != - 1 : newtext = newtext [ : right_signpos ] + ' ' + newtext [ right_signpos + 1 : ] elif old_right_signpos != - 1 : right_signpos = newtext . find ( ')' ) if right_signpos == - 1 : # just replaced right-paren if newtext [ pos ] == ' ' : # we just erased '); erase '(' newtext = newtext [ : left_signpos ] + ' ' + newtext [ left_signpos + 1 : ] else : # replaced with digit; move ') over if self . _ctrl_constraints . _alignRight or self . _isFloat : newtext = newtext [ : - 1 ] + ')' else : rstripped_text = newtext . rstrip ( ) right_signpos = len ( rstripped_text ) ##                                dbg('old_right_signpos:', old_right_signpos, 'right signpos now:', right_signpos) newtext = newtext [ : right_signpos ] + ')' + newtext [ right_signpos + 1 : ] if ( field . _insertRight # if insert-right field (but we didn't start at right edge) and field . _moveOnFieldFull # and should move cursor when full and len ( newtext [ start : end ] . strip ( ) ) == end - start # and field now full and ( not field . _stopFieldChangeIfInvalid # and we either don't care about valid or ( field . _stopFieldChangeIfInvalid # or we do and the current field value is valid and field . IsValid ( newtext [ start : end ] . strip ( ) ) ) ) ) : newpos = self . _findNextEntry ( end ) #   go to next field ##                dbg('newpos = nextentry =', newpos) else : ##                dbg('pos:', pos, 'newpos:', pos+1) newpos = pos + 1 if allowAutoSelect : new_select_to = newpos # (default return values) match_field = None match_index = None if field . _autoSelect : match_index , partial_match = self . _autoComplete ( 1 , # (always forward) field . _compareChoices , newtext [ start : end ] , compareNoCase = field . _compareNoCase , current_index = field . _autoCompleteIndex - 1 ) if match_index is not None and partial_match : matched_str = newtext [ start : end ] newtext = newtext [ : start ] + field . _choices [ match_index ] + newtext [ end : ] new_select_to = end match_field = field if field . _insertRight : # adjust position to just after partial match in field newpos = end - ( len ( field . _choices [ match_index ] . strip ( ) ) - len ( matched_str . strip ( ) ) ) elif self . _ctrl_constraints . _autoSelect : match_index , partial_match = self . _autoComplete ( 1 , # (always forward) self . _ctrl_constraints . _compareChoices , newtext , self . _ctrl_constraints . _compareNoCase , current_index = self . _ctrl_constraints . _autoCompleteIndex - 1 ) if match_index is not None and partial_match : matched_str = newtext newtext = self . _ctrl_constraints . _choices [ match_index ] edit_end = self . _ctrl_constraints . _extent [ 1 ] new_select_to = min ( edit_end , len ( newtext . rstrip ( ) ) ) match_field = self . _ctrl_constraints if self . _ctrl_constraints . _insertRight : # adjust position to just after partial match in control: newpos = self . _masklength - ( len ( self . _ctrl_constraints . _choices [ match_index ] . strip ( ) ) - len ( matched_str . strip ( ) ) ) ##            dbg('newtext: "%s"' % newtext, 'newpos:', newpos, 'new_select_to:', new_select_to) ##            dbg(indent=0) return newtext , newpos , new_select_to , match_field , match_index else : ##            dbg('newtext: "%s"' % newtext, 'newpos:', newpos) ##            dbg(indent=0) return newtext , newpos