<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=HowToCreateANumbersOnlyControl</id>
	<title>HowToCreateANumbersOnlyControl - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=HowToCreateANumbersOnlyControl"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToCreateANumbersOnlyControl&amp;action=history"/>
	<updated>2026-11-21T05:14:19Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.dabo.leafe.com/index.php?title=HowToCreateANumbersOnlyControl&amp;diff=4189&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;The following class was writtern by &#039;&#039;&#039;Larry Long&#039;&#039;&#039;, &#039;&#039;&#039;Nate Lowrie&#039;&#039;&#039; and &#039;&#039;&#039;John Fabiani&#039;&#039;&#039;.  &lt;code&gt;RANumBox(self, RegID=ncostID, MinValue=0.00, MaxValue=999999.99, Integer...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToCreateANumbersOnlyControl&amp;diff=4189&amp;oldid=prev"/>
		<updated>2020-05-17T14:58:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;The following class was writtern by &amp;#039;&amp;#039;&amp;#039;Larry Long&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Nate Lowrie&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;John Fabiani&amp;#039;&amp;#039;&amp;#039;.  &amp;lt;code&amp;gt;RANumBox(self, RegID=ncostID, MinValue=0.00, MaxValue=999999.99, Integer...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The following class was writtern by &amp;#039;&amp;#039;&amp;#039;Larry Long&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Nate Lowrie&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;John Fabiani&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;RANumBox(self, RegID=ncostID, MinValue=0.00, MaxValue=999999.99, IntegerWidth=6, DecimalWidth=2, Alignment=&amp;quot;R&amp;quot;)&amp;lt;/code&amp;gt; is the line of code that uses the class.&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;code&amp;gt;MinValue&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MaxValue&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;IntegerWidth&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DecimalWidth&amp;lt;/code&amp;gt; will determine the imput mask. Run the code below (you may not see the background color change on linux)&lt;br /&gt;
&lt;br /&gt;
The class is sub-classed on [[dTextBox]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import re&lt;br /&gt;
import dabo&lt;br /&gt;
import dabo.dEvents as dEvents&lt;br /&gt;
import dabo.dException as dException&lt;br /&gt;
from dabo.dLocalize import _&lt;br /&gt;
dabo.ui.loadUI(&amp;#039;wx&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RANumBox(dabo.ui.dTextBox):&lt;br /&gt;
    def afterInit(self):&lt;br /&gt;
        self.Alignment=&amp;#039;Right&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    def onKeyChar(self,evt):&lt;br /&gt;
        from dabo.ui import dKeys as dKeys&lt;br /&gt;
        keyChar = evt.keyChar&lt;br /&gt;
        if evt.keyCode in range(32,126) and not str.isdigit(keyChar) and not keyChar==&amp;#039;.&amp;#039;:&lt;br /&gt;
            evt.stop()&lt;br /&gt;
        if keyChar==&amp;#039;.&amp;#039; and not self.GetValue().find(&amp;#039;.&amp;#039;)==-1:&lt;br /&gt;
            evt.stop()&lt;br /&gt;
        dabo.ui.callAfter(self.Validate)&lt;br /&gt;
&lt;br /&gt;
    def Validate(self):&lt;br /&gt;
        try:&lt;br /&gt;
            value = float(self.GetValue())&lt;br /&gt;
        except:&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        if (self.MinValue is not None and value &amp;lt; self.MinValue) or (&lt;br /&gt;
                self.MaxValue is not None and value &amp;gt; self.MaxValue):&lt;br /&gt;
            self.BackColor = &amp;quot;pink&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        else:&lt;br /&gt;
            self.BackColor = &amp;quot;white&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        pattern = &amp;#039;&amp;#039;&lt;br /&gt;
        if self.IntegerWidth is not None:&lt;br /&gt;
            pattern=&amp;#039;^([0-9]{0,%s})&amp;#039; % (self.IntegerWidth,)&lt;br /&gt;
        else:&lt;br /&gt;
            pattern=&amp;#039;^([0-9]{0,})&amp;#039;&lt;br /&gt;
&lt;br /&gt;
        if self.DecimalWidth is not None:&lt;br /&gt;
            pattern = pattern + &amp;#039;(\.[0-9]{0,%s})&amp;#039; % (self.DecimalWidth,)&lt;br /&gt;
        else:&lt;br /&gt;
            pattern=pattern +&amp;#039;(\.[0-9]{0,})&amp;#039;&lt;br /&gt;
        pattern = pattern +&amp;#039;?$&amp;#039;&lt;br /&gt;
&lt;br /&gt;
        if re.match(pattern, self.GetValue())==None:&lt;br /&gt;
            self.BackColor = &amp;quot;pink&amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            self.BackColor = &amp;quot;white&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def _getDecimalWidth(self):&lt;br /&gt;
        try:&lt;br /&gt;
            return(self._decimalWidth)&lt;br /&gt;
        except:&lt;br /&gt;
            return(None)&lt;br /&gt;
&lt;br /&gt;
    def _setDecimalWidth(self, val):&lt;br /&gt;
        self._decimalWidth = val&lt;br /&gt;
&lt;br /&gt;
    def _getIntegerWidth(self):&lt;br /&gt;
        try:&lt;br /&gt;
            return(self._integerWidth)&lt;br /&gt;
        except:&lt;br /&gt;
            return None&lt;br /&gt;
&lt;br /&gt;
    def _setIntegerWidth(self, val):&lt;br /&gt;
        self._integerWidth = val&lt;br /&gt;
&lt;br /&gt;
    def _getMinValue(self):&lt;br /&gt;
        try:&lt;br /&gt;
            return(self._minValue)&lt;br /&gt;
        except:&lt;br /&gt;
            return(None)&lt;br /&gt;
&lt;br /&gt;
    def _setMinValue(self, val):&lt;br /&gt;
        self._minValue = val&lt;br /&gt;
&lt;br /&gt;
    def _getMaxValue(self):&lt;br /&gt;
        try:&lt;br /&gt;
            return(self._maxValue)&lt;br /&gt;
        except:&lt;br /&gt;
            return(None)&lt;br /&gt;
&lt;br /&gt;
    def _setMaxValue(self, val):&lt;br /&gt;
        self._maxValue = val&lt;br /&gt;
    def _getEditable(self):&lt;br /&gt;
        try:&lt;br /&gt;
            return getattr(self, &amp;quot;_Editable&amp;quot;, None)&lt;br /&gt;
        except:&lt;br /&gt;
            return(None)&lt;br /&gt;
&lt;br /&gt;
    def _setEditable(self, val):&lt;br /&gt;
        self._Editable = val&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    DecimalWidth = property(_getDecimalWidth, _setDecimalWidth, None,&lt;br /&gt;
           &amp;quot;The number of digits after the decimal point (int)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    Editable = property(_getEditable, _setEditable)&lt;br /&gt;
&lt;br /&gt;
    IntegerWidth = property(_getIntegerWidth, _setIntegerWidth, None,&lt;br /&gt;
           &amp;quot;The number of digits before the decimal point (int)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    MinValue = property(_getMinValue, _setMinValue, None,&lt;br /&gt;
           &amp;quot;The minimum value that the entered data can be (int)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    MaxValue = property(_getMaxValue, _setMaxValue, None,&lt;br /&gt;
           &amp;quot;The maximum value that the entered data can be (int)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MainForm(dabo.ui.dForm):&lt;br /&gt;
    def afterInit(self):&lt;br /&gt;
        self.Sizer = hs = dabo.ui.dSizer(&amp;#039;h&amp;#039;)&lt;br /&gt;
        hs.append(dabo.ui.dLabel(self, Caption=&amp;#039;Cost   &amp;#039;),alignment=&amp;#039;Right&amp;#039;)&lt;br /&gt;
        hs.append(RANumBox(self,RegID=&amp;#039;ncostID&amp;#039;, MinValue=0.00, MaxValue=999999.99,&lt;br /&gt;
                IntegerWidth=6, DecimalWidth=2, Alignment=&amp;#039;R&amp;#039;))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
        app = dabo.dApp()&lt;br /&gt;
        app.BasePrefKey = &amp;quot;NumberBox Test&amp;quot;&lt;br /&gt;
        app.setAppInfo(&amp;quot;appName&amp;quot;, &amp;quot;NumberBox Test&amp;quot;)&lt;br /&gt;
        app.MainFormClass = MainForm&lt;br /&gt;
        app.start()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>