masked.NumCtrl: ValueError: value 0 is below minimum value of control

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

masked.NumCtrl: ValueError: value 0 is below minimum value of control

Torsten
When i use the following code to init a NumCtrl i get ValueError: value 0 is below minimum value of control

numctrl = masked.NumCtrl(
   
parent=self,
    min=15,
    value=25.63,
    limited=True,
    groupChar=u'.',
    decimalChar=u',',
    fractionWidth=2
)

I fixed this with the following patch, but i'm not sure if this will have any side-effects. I hope that someone also using NumCtrl or with more knowleage can test it.

Index: wx/lib/masked/numctrl.py
IDEA additional info
:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- wx/lib/masked/numctrl.py    (revision 7a9fb7bb532ca2d9b01d7c87e96e0c7fda945f80)
+++ wx/lib/masked/numctrl.py    (date 1514302056076)
@@ -890,7 +890,7 @@
                 
# ensure latest decimal char is in "numeric value" so it won't be removed
                 
# when going to the GUI:
                 text
= text.replace('.', self._decimalChar)
-            newtext = self._toGUI(text)
+            newtext = self._toGUI(text, apply_limits=False)
 
##            dbg('calling wx.TextCtrl.ChangeValue(self, %s)' % newtext)
             wx
.TextCtrl.ChangeValue(self, newtext)
 


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

wx-masked-numctrl.patch (780 bytes) Download Attachment
NumCtrl-problem.py (663 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: masked.NumCtrl: ValueError: value 0 is below minimum value of control

Tim Roberts
'Torsten' via wxPython-users wrote:
When i use the following code to init a NumCtrl i get ValueError: value 0 is below minimum value of control
...
I fixed this with the following patch, but i'm not sure if this will have any side-effects. I hope that someone also using NumCtrl or with more knowleage can test it.

That's not the correct solution.  You certainly want to re-validate the current value any time you change the parameters, and your code simply disables that.

This is a nasty chicken-and-egg problem.  The current initialization sequence is
    self.SetParameters(...)
    self.SetValue(...)
which will set all of the criteria and then set and validate the default value.  The problem is that SetParameters does a validation on the current value, and in this case the current value is still the default of 0, which fails your criteria.

It looks to me like the correct solution is to swap those two, so that the code looks like this:

        # Set the value requested (if possible)
##        wxCallAfter(self.SetValue, value)
        self.SetValue(value)

        # Establish any additional parameters, with appropriate error checking
        self.SetParameters(**init_args)

        # right alignment with prefixed blanks doesn't work with wxPython 2.9+
        if wx.Platform == "__WXMSW__":
            self.SetWindowStyleFlag(self.GetWindowStyleFlag() | wx.TE_RIGHT)

That certainly allows your example to work properly, but I am at a loss to explain why it wasn't written that way to begin with.  Hopefully someone who remembers those misty days will have an answer.
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.