Masked Editing Controls, validRequired=True, and exceptions during _insertKey

Reproduction:

In the MaskedEditControls.py demo modify the “An empty control” IP address control in demo page 5 to be this:

label_ipaddr1 = wx.StaticText( self, -1, “An empty control:”)
ipaddr1 = masked.IpAddrCtrl( self, -1, style = wx.TE_PROCESS_TAB, mask="###.###.###.###", formatcodes=‘F_Sr<>’, validRequired=True, validRegex="( \d| \d\d|(1\d\d|2[0-4]\d|25[0-5]))(.( \d| \d\d|(1\d\d|2[0-4]\d|25[0-5]))){3}", value=’ 1. 2. 3. 4’)
field_params = {}
field_params[‘validRegex’] = “( | \d| \d |\d | \d\d|\d\d |\d \d|(1\d\d|2[0-4]\d|25[0-5]))”

require “valid” string; this prevents entry of any value > 255, but allows

    # intermediate constructions; overall control validation requires well-formatted value.
    field_params['formatcodes'] = 'V'

if field_params:
for i in range(4):
ipaddr1.SetFieldParameters(i, **field_params)

Select all of the characters in the 2nd part of the ip address " 2"

Try and replace the selection with ‘3’.

Results:

  • _insertKey calls _OnErase to erase the current selection with just_return_value=True

  • _OnErase doesn’t erase the selection because it violates the validation rules and thus returns False

  • _insertKey throws an exception because you can’t subscript False

Suggested Fix:

  • _OnErase skip validation if just_return_value is True

  • _insertKey and other callers of _OnErase that pass just_return_value=True validate the data after the return value from _OnErase.

I believe all callers that pass just_return_value = True do this already.

See the attached patch. The patch also adds a missing dbg(indent=0) call.

I see this issue and the previous issue on Windows 32-bit python 2.7 btw.

Thoughts?

Bill

maskedEdit_OnEraseJustReturnValue.patch (1.15 KB)