parameters: (self, event=None, just_return_value=False)
return_statement: return False
docstring: Handles backspace and delete keypress in control. Should return False to skip other processing.
docstring_summary: Handles backspace and delete keypress in control. Should return False to skip other processing.
docstring_tokens: Handles backspace and delete keypress in control . Should return False to skip other processing .
function: def _OnErase(self, event=None, just_return_value=False):
          """ Handles backspace and delete keypress in control. Should return False to skip other processing."""
  ##        dbg("MaskedEditMixin::_OnErase", indent=1)
          sel_start, sel_to = self._GetSelection()                   ## check for a range of selected text
  
          if event is None:   # called as action routine from Cut() operation.
              key = wx.WXK_DELETE
          else:
              key = event.GetKeyCode()
  
          field = self._FindField(sel_to)
          start, end = field._extent
          value = self._GetValue()
          oldstart = sel_start
  
          # If trying to erase beyond "legal" bounds, disallow operation:
          if( (sel_to == 0 and key == wx.WXK_BACK)
              or (self._signOk and sel_to == 1 and value[0] == ' ' and key == wx.WXK_BACK)
              or (sel_to == self._masklength and sel_start == sel_to and key in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE) and not field._insertRight)
              or (self._signOk and self._useParens
                  and sel_start == sel_to
                  and sel_to == self._masklength - 1
                  and value[sel_to] == ' ' and key in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE) and not field._insertRight) ):
              if not wx.Validator_IsSilent():
                  wx.Bell()
  ##            dbg(indent=0)
              return False
  
  
          if( field._insertRight                                  # an insert-right field
              and value[start:end] != self._template[start:end]   # and field not empty
              and sel_start >= start                              # and selection starts in field
              and ((sel_to == sel_start                           # and no selection
                    and sel_to == end                             # and cursor at right edge
                    and key in (wx.WXK_BACK, wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE))    # and either delete or backspace key
                   or                                             # or
                   (key == wx.WXK_BACK                               # backspacing
                      and (sel_to == end                          # and selection ends at right edge
                           or sel_to < end and field._allowInsert)) ) ):  # or allow right insert at any point in field
  
  ##            dbg('delete left')
              # if backspace but left of cursor is empty, adjust cursor right before deleting
              while( key == wx.WXK_BACK
                     and sel_start == sel_to
                     and sel_start < end
                     and value[start:sel_start] == self._template[start:sel_start]):
                  sel_start += 1
                  sel_to = sel_start
  
  ##            dbg('sel_start, start:', sel_start, start)
  
              if sel_start == sel_to:
                  keep = sel_start -1
              else:
                  keep = sel_start
              newfield = value[start:keep] + value[sel_to:end]
  
              # handle sign char moving from outside field into the field:
              move_sign_into_field = False
              if not field._padZero and self._signOk and self._isNeg and value[0] in ('-', '('):
                  signchar = value[0]
                  newfield = signchar + newfield
                  move_sign_into_field = True
  ##            dbg('cut newfield: "%s"' % newfield)
  
              # handle what should fill in from the left:
              left = ""
              for i in range(start, end - len(newfield)):
                  if field._padZero:
                      left += '0'
                  elif( self._signOk and self._isNeg and i == 1
                        and ((self._useParens and newfield.find('(') == -1)
                             or (not self._useParens and newfield.find('-') == -1)) ):
                      left += ' '
                  else:
                      left += self._template[i]   # this can produce strange results in combination with default values...
              newfield = left + newfield
  ##            dbg('filled newfield: "%s"' % newfield)
  
              newstr = value[:start] + newfield + value[end:]
  
              # (handle sign located in "mask position" in front of field prior to delete)
              if move_sign_into_field:
                  newstr = ' ' + newstr[1:]
              pos = sel_to
          else:
              # handle erasure of (left) sign, moving selection accordingly...
              if self._signOk and sel_start == 0:
                  newstr = value = ' ' + value[1:]
                  sel_start += 1
  
              if field._allowInsert and sel_start >= start:
                  # selection (if any) falls within current insert-capable field:
                  select_len = sel_to - sel_start
                  # determine where cursor should end up:
                  if key == wx.WXK_BACK:
                      if select_len == 0:
                          newpos = sel_start -1
                      else:
                          newpos = sel_start
                      erase_to = sel_to
                  else:
                      newpos = sel_start
                      if sel_to == sel_start:
                          erase_to = sel_to + 1
                      else:
                          erase_to = sel_to
  
                  if self._isTemplateChar(newpos) and select_len == 0:
                      if self._signOk:
                          if value[newpos] in ('(', '-'):
                              newpos += 1     # don't move cusor
                              newstr = ' ' + value[newpos:]
                          elif value[newpos] == ')':
                              # erase right sign, but don't move cursor; (matching left sign handled later)
                              newstr = value[:newpos] + ' '
                          else:
                              # no deletion; just move cursor
                              newstr = value
                      else:
                          # no deletion; just move cursor
                          newstr = value
                  else:
                      if erase_to > end: erase_to = end
                      erase_len = erase_to - newpos
  
                      left = value[start:newpos]
  ##                    dbg("retained ='%s'" % value[erase_to:end], 'sel_to:', sel_to, "fill: '%s'" % self._template[end - erase_len:end])
                      right = value[erase_to:end] + self._template[end-erase_len:end]
                      pos_adjust = 0
                      if field._alignRight:
                          rstripped = right.rstrip()
                          if rstripped != right:
                              pos_adjust = len(right) - len(rstripped)
                          right = rstripped
  
                      if not field._insertRight and value[-1] == ')' and end == self._masklength - 1:
                          # need to shift ) into the field:
                          right = right[:-1] + ')'
                          value = value[:-1] + ' '
  
                      newfield = left+right
                      if pos_adjust:
                          newfield = newfield.rjust(end-start)
                          newpos += pos_adjust
  ##                    dbg("left='%s', right ='%s', newfield='%s'" %(left, right, newfield))
                      newstr = value[:start] + newfield + value[end:]
  
                  pos = newpos
  
              else:
                  if sel_start == sel_to:
  ##                    dbg("current sel_start, sel_to:", sel_start, sel_to)
                      if key == wx.WXK_BACK:
                          sel_start, sel_to = sel_to-1, sel_to-1
  ##                        dbg("new sel_start, sel_to:", sel_start, sel_to)
  
                      if field._padZero and not value[start:sel_to].replace('0', '').replace(' ','').replace(field._fillChar, ''):
                          # preceding chars (if any) are zeros, blanks or fillchar; new char should be 0:
                          newchar = '0'
                      else:
                          newchar = self._template[sel_to] ## get an original template character to "clear" the current char
  ##                    dbg('value = "%s"' % value, 'value[%d] = "%s"' %(sel_start, value[sel_start]))
  
                      if self._isTemplateChar(sel_to):
                          if sel_to == 0 and self._signOk and value[sel_to] == '-':   # erasing "template" sign char
                              newstr = ' ' + value[1:]
                              sel_to += 1
                          elif self._signOk and self._useParens and (value[sel_to] == ')' or value[sel_to] == '('):
                              # allow "change sign" by removing both parens:
                              newstr = value[:self._signpos] + ' ' + value[self._signpos+1:-1] + ' '
                          else:
                              newstr = value
                          newpos = sel_to
                      else:
                          if field._insertRight and sel_start == sel_to:
                              # force non-insert-right behavior, by selecting char to be replaced:
                              sel_to += 1
                          newstr, ignore = self._insertKey(newchar, sel_start, sel_start, sel_to, value)
  
                  else:
                      # selection made
                      newstr = self._eraseSelection(value, sel_start, sel_to)
  
                  pos = sel_start  # put cursor back at beginning of selection
  
          if self._signOk and self._useParens:
              # account for resultant unbalanced parentheses:
              left_signpos = newstr.find('(')
              right_signpos = newstr.find(')')
  
              if left_signpos == -1 and right_signpos != -1:
                  # erased left-sign marker; get rid of right sign marker:
                  newstr = newstr[:right_signpos] + ' ' + newstr[right_signpos+1:]
  
              elif left_signpos != -1 and right_signpos == -1:
                  # erased right-sign marker; get rid of left-sign marker:
                  newstr = newstr[:left_signpos] + ' ' + newstr[left_signpos+1:]
  
  ##        dbg("oldstr:'%s'" % value, 'oldpos:', oldstart)
  ##        dbg("newstr:'%s'" % newstr, 'pos:', pos)
  
          # if erasure results in an invalid field, disallow it:
  ##        dbg('field._validRequired?', field._validRequired)
  ##        dbg('field.IsValid("%s")?' % newstr[start:end], field.IsValid(newstr[start:end]))
          if field._validRequired and not field.IsValid(newstr[start:end]):
              if not wx.Validator_IsSilent():
                  wx.Bell()
  ##            dbg(indent=0)
              return False
  
          # If the caller just wants the erased value without validation 
          # (because a just pressed key might make this string valid again)
          # then return it.
          if just_return_value:
  ##            dbg(indent=0)
              return newstr
  
          # if erasure results in an invalid value, disallow it:
          if self._ctrl_constraints._validRequired and not self.IsValid(newstr):
              if not wx.Validator_IsSilent():
                  wx.Bell()
  ##            dbg(indent=0)
              return False
  
          # else...
  ##        dbg('setting value (later) to', newstr)
          wx.CallAfter(self._SetValue, newstr)
  ##        dbg('setting insertion point (later) to', pos)
          wx.CallAfter(self._SetInsertionPoint, pos)
  ##        dbg(indent=0)
          if newstr != value:
              self.modified = True
          return False
function_tokens: def _OnErase ( self , event = None , just_return_value = False ) : ##        dbg("MaskedEditMixin::_OnErase", indent=1) sel_start , sel_to = self . _GetSelection ( ) ## check for a range of selected text if event is None : # called as action routine from Cut() operation. key = wx . WXK_DELETE else : key = event . GetKeyCode ( ) field = self . _FindField ( sel_to ) start , end = field . _extent value = self . _GetValue ( ) oldstart = sel_start # If trying to erase beyond "legal" bounds, disallow operation: if ( ( sel_to == 0 and key == wx . WXK_BACK ) or ( self . _signOk and sel_to == 1 and value [ 0 ] == ' ' and key == wx . WXK_BACK ) or ( sel_to == self . _masklength and sel_start == sel_to and key in ( wx . WXK_DELETE , wx . WXK_NUMPAD_DELETE ) and not field . _insertRight ) or ( self . _signOk and self . _useParens and sel_start == sel_to and sel_to == self . _masklength - 1 and value [ sel_to ] == ' ' and key in ( wx . WXK_DELETE , wx . WXK_NUMPAD_DELETE ) and not field . _insertRight ) ) : if not wx . Validator_IsSilent ( ) : wx . Bell ( ) ##            dbg(indent=0) return False if ( field . _insertRight # an insert-right field and value [ start : end ] != self . _template [ start : end ] # and field not empty and sel_start >= start # and selection starts in field and ( ( sel_to == sel_start # and no selection and sel_to == end # and cursor at right edge and key in ( wx . WXK_BACK , wx . WXK_DELETE , wx . WXK_NUMPAD_DELETE ) ) # and either delete or backspace key or # or ( key == wx . WXK_BACK # backspacing and ( sel_to == end # and selection ends at right edge or sel_to < end and field . _allowInsert ) ) ) ) : # or allow right insert at any point in field ##            dbg('delete left') # if backspace but left of cursor is empty, adjust cursor right before deleting while ( key == wx . WXK_BACK and sel_start == sel_to and sel_start < end and value [ start : sel_start ] == self . _template [ start : sel_start ] ) : sel_start += 1 sel_to = sel_start ##            dbg('sel_start, start:', sel_start, start) if sel_start == sel_to : keep = sel_start - 1 else : keep = sel_start newfield = value [ start : keep ] + value [ sel_to : end ] # handle sign char moving from outside field into the field: move_sign_into_field = False if not field . _padZero and self . _signOk and self . _isNeg and value [ 0 ] in ( '-' , '(' ) : signchar = value [ 0 ] newfield = signchar + newfield move_sign_into_field = True ##            dbg('cut newfield: "%s"' % newfield) # handle what should fill in from the left: left = "" for i in range ( start , end - len ( newfield ) ) : if field . _padZero : left += '0' elif ( self . _signOk and self . _isNeg and i == 1 and ( ( self . _useParens and newfield . find ( '(' ) == - 1 ) or ( not self . _useParens and newfield . find ( '-' ) == - 1 ) ) ) : left += ' ' else : left += self . _template [ i ] # this can produce strange results in combination with default values... newfield = left + newfield ##            dbg('filled newfield: "%s"' % newfield) newstr = value [ : start ] + newfield + value [ end : ] # (handle sign located in "mask position" in front of field prior to delete) if move_sign_into_field : newstr = ' ' + newstr [ 1 : ] pos = sel_to else : # handle erasure of (left) sign, moving selection accordingly... if self . _signOk and sel_start == 0 : newstr = value = ' ' + value [ 1 : ] sel_start += 1 if field . _allowInsert and sel_start >= start : # selection (if any) falls within current insert-capable field: select_len = sel_to - sel_start # determine where cursor should end up: if key == wx . WXK_BACK : if select_len == 0 : newpos = sel_start - 1 else : newpos = sel_start erase_to = sel_to else : newpos = sel_start if sel_to == sel_start : erase_to = sel_to + 1 else : erase_to = sel_to if self . _isTemplateChar ( newpos ) and select_len == 0 : if self . _signOk : if value [ newpos ] in ( '(' , '-' ) : newpos += 1 # don't move cusor newstr = ' ' + value [ newpos : ] elif value [ newpos ] == ')' : # erase right sign, but don't move cursor; (matching left sign handled later) newstr = value [ : newpos ] + ' ' else : # no deletion; just move cursor newstr = value else : # no deletion; just move cursor newstr = value else : if erase_to > end : erase_to = end erase_len = erase_to - newpos left = value [ start : newpos ] ##                    dbg("retained ='%s'" % value[erase_to:end], 'sel_to:', sel_to, "fill: '%s'" % self._template[end - erase_len:end]) right = value [ erase_to : end ] + self . _template [ end - erase_len : end ] pos_adjust = 0 if field . _alignRight : rstripped = right . rstrip ( ) if rstripped != right : pos_adjust = len ( right ) - len ( rstripped ) right = rstripped if not field . _insertRight and value [ - 1 ] == ')' and end == self . _masklength - 1 : # need to shift ) into the field: right = right [ : - 1 ] + ')' value = value [ : - 1 ] + ' ' newfield = left + right if pos_adjust : newfield = newfield . rjust ( end - start ) newpos += pos_adjust ##                    dbg("left='%s', right ='%s', newfield='%s'" %(left, right, newfield)) newstr = value [ : start ] + newfield + value [ end : ] pos = newpos else : if sel_start == sel_to : ##                    dbg("current sel_start, sel_to:", sel_start, sel_to) if key == wx . WXK_BACK : sel_start , sel_to = sel_to - 1 , sel_to - 1 ##                        dbg("new sel_start, sel_to:", sel_start, sel_to) if field . _padZero and not value [ start : sel_to ] . replace ( '0' , '' ) . replace ( ' ' , '' ) . replace ( field . _fillChar , '' ) : # preceding chars (if any) are zeros, blanks or fillchar; new char should be 0: newchar = '0' else : newchar = self . _template [ sel_to ] ## get an original template character to "clear" the current char ##                    dbg('value = "%s"' % value, 'value[%d] = "%s"' %(sel_start, value[sel_start])) if self . _isTemplateChar ( sel_to ) : if sel_to == 0 and self . _signOk and value [ sel_to ] == '-' : # erasing "template" sign char newstr = ' ' + value [ 1 : ] sel_to += 1 elif self . _signOk and self . _useParens and ( value [ sel_to ] == ')' or value [ sel_to ] == '(' ) : # allow "change sign" by removing both parens: newstr = value [ : self . _signpos ] + ' ' + value [ self . _signpos + 1 : - 1 ] + ' ' else : newstr = value newpos = sel_to else : if field . _insertRight and sel_start == sel_to : # force non-insert-right behavior, by selecting char to be replaced: sel_to += 1 newstr , ignore = self . _insertKey ( newchar , sel_start , sel_start , sel_to , value ) else : # selection made newstr = self . _eraseSelection ( value , sel_start , sel_to ) pos = sel_start # put cursor back at beginning of selection if self . _signOk and self . _useParens : # account for resultant unbalanced parentheses: left_signpos = newstr . find ( '(' ) right_signpos = newstr . find ( ')' ) if left_signpos == - 1 and right_signpos != - 1 : # erased left-sign marker; get rid of right sign marker: newstr = newstr [ : right_signpos ] + ' ' + newstr [ right_signpos + 1 : ] elif left_signpos != - 1 and right_signpos == - 1 : # erased right-sign marker; get rid of left-sign marker: newstr = newstr [ : left_signpos ] + ' ' + newstr [ left_signpos + 1 : ] ##        dbg("oldstr:'%s'" % value, 'oldpos:', oldstart) ##        dbg("newstr:'%s'" % newstr, 'pos:', pos) # if erasure results in an invalid field, disallow it: ##        dbg('field._validRequired?', field._validRequired) ##        dbg('field.IsValid("%s")?' % newstr[start:end], field.IsValid(newstr[start:end])) if field . _validRequired and not field . IsValid ( newstr [ start : end ] ) : if not wx . Validator_IsSilent ( ) : wx . Bell ( ) ##            dbg(indent=0) return False # If the caller just wants the erased value without validation  # (because a just pressed key might make this string valid again) # then return it. if just_return_value : ##            dbg(indent=0) return newstr # if erasure results in an invalid value, disallow it: if self . _ctrl_constraints . _validRequired and not self . IsValid ( newstr ) : if not wx . Validator_IsSilent ( ) : wx . Bell ( ) ##            dbg(indent=0) return False # else... ##        dbg('setting value (later) to', newstr) wx . CallAfter ( self . _SetValue , newstr ) ##        dbg('setting insertion point (later) to', pos) wx . CallAfter ( self . _SetInsertionPoint , pos ) ##        dbg(indent=0) if newstr != value : self . modified = True return False