From 8c29915355f83bfb6954d102e53560a2b1e7d355 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 26 Aug 2006 21:13:58 +0000 Subject: [PATCH 1/1] Patch from Will Sadkin: - Fixed masked.numctrl to properly limit integer controls, and also handle '-.00' properly. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40851 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/wx/lib/masked/maskededit.py | 2 +- wxPython/wx/lib/masked/numctrl.py | 31 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/wxPython/wx/lib/masked/maskededit.py b/wxPython/wx/lib/masked/maskededit.py index c57038ed60..ec608dbf62 100644 --- a/wxPython/wx/lib/masked/maskededit.py +++ b/wxPython/wx/lib/masked/maskededit.py @@ -3200,7 +3200,7 @@ class MaskedEditMixin: Should return False to skip other processing. """ ## dbg("MaskedEditMixin::_OnCtrl_V", indent=1) self.Paste() - dbg(indent=0) +## dbg(indent=0) return False def _OnInsert(self, event=None): diff --git a/wxPython/wx/lib/masked/numctrl.py b/wxPython/wx/lib/masked/numctrl.py index 3104724c7a..73a837039b 100644 --- a/wxPython/wx/lib/masked/numctrl.py +++ b/wxPython/wx/lib/masked/numctrl.py @@ -947,6 +947,7 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin): ## dbg('calling base BaseMaskedTextCtrl._SetValue(self, "%s")' % value) BaseMaskedTextCtrl._SetValue(self, value) self.Refresh() +## dbg(indent=0) return elif self._min > 0 and self.IsLimited(): replacement = self._min @@ -964,6 +965,11 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin): ## dbg('integer: "%s"' % int) try: + # if a float value, this will implicitly verify against limits, + # and generate an exception if out-of-bounds and limited + # if not a float, it will just return 0.0, and we therefore + # have to test against the limits explicitly after testing + # special cases for handling -0 and empty controls... fracval = self.GetFraction(value) except ValueError, e: ## dbg('Exception:', e, 'must be out of bounds; disallow value') @@ -971,13 +977,20 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin): ## dbg(indent=0) return - if fracval == 0.0: + if fracval == 0.0: # (can be 0 for floats as well as integers) + # we have to do special testing to account for emptying controls, or -0 + # and/or just leaving the sign character or changing the sign, + # so we can do appropriate things to the value of the control, + # we can't just immediately test to see if the value is valid + # If all of these special cases are not in play, THEN we can do + # a limits check and see if the value is otherwise ok... + ## dbg('self._isNeg?', self._isNeg) if int == '-' and self._oldvalue < 0 and not self._typedSign: ## dbg('just a negative sign; old value < 0; setting replacement of 0') replacement = 0 self._isNeg = False - elif int[:2] == '-0' and self._fractionWidth == 0: + elif int[:2] == '-0': if self._oldvalue < 0: ## dbg('-0; setting replacement of 0') replacement = 0 @@ -992,7 +1005,7 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin): ## dbg(indent=0) return - elif int == '-' and (self._oldvalue >= 0 or self._typedSign) and self._fractionWidth == 0: + elif int == '-' and (self._oldvalue >= 0 or self._typedSign): if not self._limited or (self._min < -1 and self._max >= -1): ## dbg('just a negative sign; setting replacement of -1') replacement = -1 @@ -1030,14 +1043,22 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin): ## dbg(indent=0) return - if int[0] == '0' and len(int) > 1: -## dbg('numvalue: "%s"' % numvalue.replace(' ', '')) +## dbg('numvalue: "%s"' % numvalue.replace(' ', '')) + # finally, (potentially re) verify that numvalue will pass any limits imposed: + try: if self._fractionWidth: value = self._toGUI(string.atof(numvalue)) else: value = self._toGUI(string.atol(numvalue)) + except ValueError, e: +## dbg('Exception:', e, 'must be out of bounds; disallow value') + self._disallowValue() +## dbg(indent=0) + return + ## dbg('modified value: "%s"' % value) + self._typedSign = False # reset state var if replacement is not None: -- 2.47.2