[wxPython] Input Validator

thank you, Raul. Let me try it first.

Jenny

···

From: Raul Cota <cota@ucalgary.ca>
Reply-To: wxpython-users@lists.wxwindows.org
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] Input Validator
Date: Wed, 27 Jun 2001 13:02:13 -0600

Today I had to do something like you, but in my case I only accept
integers
this is my code,

id = wxNewId()
nuLiqPh = self.uOp.GetNuLiqPhases()
self.pa = wxTextCtrl(self, id, str(nuLiqPh), pos = wxPoint(540, 90),
size = wxSize(150, 20), style = wxTE_PROCESS_ENTER)
EVT_CHAR(self.pa, self.NuLiqPhChar)

def NuLiqPhChar(self, event):
k = event.GetKeyCode()
txtCtrl = event.GetEventObject()

        # 0 liquid phases not aloud
        if k == 48 and txtCtrl.GetInsertionPoint() == 0:
            return

        #Has to be a number 48 = '0', 57 = '9'
        if k >= 48 and k <= 57:
            event.Skip()
            return

        elif k == 8 or k == 13 or k == 27:
            event.Skip()
            return

As you can see, if the insertion point is == 0, I don't accept the
character '0'
You can do something like this

ip = txtCtrl.GetInsertionPoint()
if ip == 0:
#validate the character in position 0
elif ip == 1:
#validate the character in position 1

etcetera

This was the first time I needed to do something like this in my code,
but so far is working fine, and eventually I'll define functions to
validate a character, for a given insertion point, for a type of data
being used (integers, floating point values, numbers constrained to min
and max, etcetera). Unless I find an easier way of doing things

By the way.... a = 97, z = 122; A = 65, B = 90

qun liu wrote:
>
> Hi,
>
> The input text this time must be something like 10-Jun-2001 instead of
> 10-June-2001 or 10/06/2001. I was taught yesterday by you guys about how to
> limit the length of the input text, but I still can not figure out how to
> implement this one.:-< Any helps will be appreciated.
>
> Jenny
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com