Updates to MaskedEdit controls from Will Sadkin:

maskededit.py:
    Added parameter option stopFieldChangeIfInvalid, which can be used to
    relax the validation rules for a control, but make best efforts to stop
    navigation out of that field should its current value be invalid.  Note:
    this does not prevent the value from remaining invalid if focus for the
    control is lost, via mousing etc.

  numctrl.py, demo / MaskedNumCtrl.py:
    In response to user request, added limitOnFieldChange feature, so that
    out-of-bounds values can be temporarily added to the control, but should
    navigation be attempted out of an invalid field, it will not navigate,
    and if focus is lost on a control so limited with an invalid value, it
    will change the value to the nearest bound.

  combobox.py:
    Added handler for EVT_COMBOBOX to address apparently inconsistent behavior
    of control when the dropdown control is used to do a selection.

  textctrl.py
    Added support for ChangeValue() function, similar to that of the base
    control, added in wxPython 2.7.1.1.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@45743 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2007-05-02 01:00:30 +00:00
parent 3ead8c473e
commit e75f43c577
4 changed files with 216 additions and 33 deletions

View File

@@ -152,29 +152,35 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
return self.GetValue()
def _SetValue(self, value):
def _SetValue(self, value, use_change_value=False):
"""
Allow mixin to set the raw value of the control with this function.
REQUIRED by any class derived from MaskedEditMixin.
"""
## dbg('MaskedTextCtrl::_SetValue("%(value)s")' % locals(), indent=1)
## dbg('MaskedTextCtrl::_SetValue("%(value)s", use_change_value=%(use_change_value)d)' % locals(), indent=1)
# Record current selection and insertion point, for undo
self._prevSelection = self._GetSelection()
self._prevInsertionPoint = self._GetInsertionPoint()
wx.TextCtrl.SetValue(self, value)
if use_change_value:
wx.TextCtrl.ChangeValue(self, value)
else:
wx.TextCtrl.SetValue(self, value)
## dbg(indent=0)
def SetValue(self, value):
def SetValue(self, value, use_change_value=False):
"""
This function redefines the externally accessible .SetValue() to be
a smart "paste" of the text in question, so as not to corrupt the
masked control. NOTE: this must be done in the class derived
from the base wx control.
"""
## dbg('MaskedTextCtrl::SetValue = "%s"' % value, indent=1)
## dbg('MaskedTextCtrl::SetValue("%(value)s", use_change_value=%(use_change_value)d)' % locals(), indent=1)
if not self._mask:
wx.TextCtrl.SetValue(self, value) # revert to base control behavior
if use_change_value:
wx.TextCtrl.ChangeValue(self, value) # revert to base control behavior
else:
wx.TextCtrl.SetValue(self, value) # revert to base control behavior
return
# empty previous contents, replacing entire value:
@@ -221,14 +227,20 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
## dbg('exception thrown', indent=0)
raise
self._SetValue(value) # note: to preserve similar capability, .SetValue()
# does not change IsModified()
self._SetValue(value, use_change_value) # note: to preserve similar capability, .SetValue()
# does not change IsModified()
#### dbg('queuing insertion after .SetValue', replace_to)
# set selection to last char replaced by paste
wx.CallAfter(self._SetInsertionPoint, replace_to)
wx.CallAfter(self._SetSelection, replace_to, replace_to)
## dbg(indent=0)
def ChangeValue(self, value):
"""
Provided to accomodate similar functionality added to base control in wxPython 2.7.1.1.
"""
self.SetValue(value, use_change_value=True)
def SetFont(self, *args, **kwargs):
""" Set the font, then recalculate control size, if appropriate. """
@@ -372,6 +384,10 @@ class PreMaskedTextCtrl( BaseMaskedTextCtrl, MaskedEditAccessorsMixin ):
__i=0
## CHANGELOG:
## ====================
## Version 1.3
## - Added support for ChangeValue() function, similar to that of the base
## control, added in wxPython 2.7.1.1.
##
## Version 1.2
## - Converted docstrings to reST format, added doc for ePyDoc.
## removed debugging override functions.