johnf wrote:
> While testing the dTextBox.py I entered several spaces into the DecimalText 
> control.  I discovered that I can cause an error to occur:
> Traceback (most recent call last):
>   File "/home/johnf/downloads/dabo/dabo/ui/uiwx/dPemMixin.py", line 524, in 
> __onWxGotFocus
>     self.raiseEvent(dEvents.GotFocus, evt)
>   File "/home/johnf/downloads/dabo/dabo/ui/uiwx/dPemMixin.py", line 925, in 
> raiseEvent
>     super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args, 
> **kwargs)
>   File "/home/johnf/downloads/dabo/dabo/lib/eventMixin.py", line 92, in 
> raiseEvent
>     bindingFunction(event)
>   File "/home/johnf/downloads/dabo/dabo/ui/dControlMixinBase.py", line 19, in 
> __onGotFocus
>     self.Form.activeControlValid()  ## make sure prior control's value has 
> been flushed.
>   File "/home/johnf/downloads/dabo/dabo/ui/uiwx/dFormMixin.py", line 272, in 
> activeControlValid
>     if not hasattr(ac, "_oldVal") or ac._oldVal != ac.Value:
>   File "/home/johnf/downloads/dabo/dabo/ui/uiwx/dTextBoxMixin.py", line 626, 
> in _getValue
>     convertedVal = self.convertStringValueToDataType(strVal, dataType)
>   File "/home/johnf/downloads/dabo/dabo/ui/uiwx/dTextBoxMixin.py", line 459, 
> in convertStringValueToDataType
>     retVal = decimal.DefaultContext.quantize(decimal.Decimal(strVal), _oldVal)
>   File "/usr/lib/python2.5/decimal.py", line 614, in __new__
>     self._sign, self._int, self._exp = context._raise_error(ConversionSyntax)
>   File "/usr/lib/python2.5/decimal.py", line 2325, in _raise_error
>     raise error, explanation
> 
> I traced it and found that the spaces were in the value that was being 
> processed by "dTextBoxMixin.convertStringValueToDataType()" for a 
> decimal.Decimal.  This of course caused the traceback.  
> 
> If the data type is "decimal.Decimal" is should never have leading or 
> trailing 
> spaces I suggest the following minor change:
> 
> strVal=strVal.strip()
> 
> below is the complete code:
> elif (dataType == decimal.Decimal) and self.StrictNumericEntry:
>    try:
>        _oldVal = self._oldVal
>    except AttributeError:
>       _oldVal = None
>    strVal=strVal.strip()
>     try: 
>         if type(_oldVal) == decimal.Decimal:
>             # Enforce the precision as previously set programatically
>       retVal = decimal.DefaultContext.quantize(decimal.Decimal(strVal), 
> _oldVal)
>         else:
>       retVal = decimal.Decimal(strVal)
>      except ValueError:
>       raise ValueError, _("Can't convert to decimal.")

Thanks. I think instead we want to catch decimal.InvalidOperation as well as 
ValueError, which also catches changing the value to "dd", for example.

Paul


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to