howto use validRegex, validFunc mask.textctrl

Hi,
I would like see some example code that demonstrates how to use validRegex
without a "mask" or example code that demonstrates how to use "validFunc".
My problem is I have need to allow the following into a text control:

9-99
99-9
999999-999
The number comes from a purchase order. The first section is the purchase
order number(could be very large) and the second section is the line number
never larger than 999.

I'm sure that there is someone out there that can explain it a little better
than the wxPython doc's.

···

--
John Fabiani

The more I get into this the more is see my request is not easy to do. It
appears that what I want is how the mask with a decimal point works. But of
course I can't get that because I'm using a dash '-'. I still can't get
the 'validFunc' to work but then I don't see how it can help me in this case.
I'm sure attempting to change the passed value will cause a loop.

But if anyone comes up with something please let me know.

···

On Saturday 15 November 2008 10:00:34 pm johnf wrote:

Hi,
I would like see some example code that demonstrates how to use validRegex
without a "mask" or example code that demonstrates how to use "validFunc".
My problem is I have need to allow the following into a text control:

9-99
99-9
999999-999
The number comes from a purchase order. The first section is the purchase
order number(could be very large) and the second section is the line number
never larger than 999.

I'm sure that there is someone out there that can explain it a little
better than the wxPython doc's.

--
John Fabiani

Johnf wrote:

Hi,
I would like see some example code that demonstrates how to use
validRegex without a "mask" or example code that demonstrates how to
use "validFunc". My problem is I have need to allow the following
into a text control:

9-99
99-9
999999-999
The number comes from a purchase order. The first section is the
purchase order number(could be very large) and the second section is
the line number never larger than 999.

I'm sure that there is someone out there that can explain it a little
better than the wxPython doc's.

John,

Using a masked.textctrl without a mask is not currently possible; as written,
the masked controls are FIXED WIDTH controls. That is, the number of digits
to the right of the - cannot not be variable, and the whole value cannot
exceed the size of the mask. This is necessary to do the careful manipulation
of the cursor around the masked positions that the library provides. To have
the "mask" shift as someone types, you're going to have to write your own;
feel free to crib from the innards of MaskedEditMixin.py-- that's where all
of the code basically resides.

Alternatively, you could just build your entry form using 2 numctrls, one
for the purchase order number, and the other for the line. Not as elegant,
but it would allow you to use existing functionality without writing a lot
more code...

Regards,
/Will Sadkin
author, lib.masked

Thanks for the response. I started to understand the need of the mask as I
played with the control. Also it helped to start reading the doc's available
in the wxpython demo. I'm still learning how to use the control by playing
around with the methods and attrib's that are available.

I still haven't got the validFunc to work but I haven't tried much. Still
working with the mask,format, and validRegex.

But I am having an issue at the moment. I'm wondering why the following does
not allow any char's to be typed into the control:
mask='#{5}-#{3}'
format = 'FV'
validRegex = '[1-9]+-[1-9]+'

···

On Sunday 16 November 2008 02:35:10 pm Will Sadkin wrote:

Johnf wrote:
> Hi,
> I would like see some example code that demonstrates how to use
> validRegex without a "mask" or example code that demonstrates how to
> use "validFunc". My problem is I have need to allow the following
> into a text control:
>
> 9-99
> 99-9
> 999999-999
> The number comes from a purchase order. The first section is the
> purchase order number(could be very large) and the second section is
> the line number never larger than 999.
>
> I'm sure that there is someone out there that can explain it a little
> better than the wxPython doc's.

John,

Using a masked.textctrl without a mask is not currently possible; as
written, the masked controls are FIXED WIDTH controls. That is, the number
of digits to the right of the - cannot not be variable, and the whole value
cannot exceed the size of the mask. This is necessary to do the careful
manipulation of the cursor around the masked positions that the library
provides. To have the "mask" shift as someone types, you're going to have
to write your own; feel free to crib from the innards of
MaskedEditMixin.py-- that's where all of the code basically resides.

Alternatively, you could just build your entry form using 2 numctrls, one
for the purchase order number, and the other for the line. Not as elegant,
but it would allow you to use existing functionality without writing a lot
more code...

Regards,
/Will Sadkin
author, lib.masked

--
John Fabiani

wrote:

Johnf wrote:

Hi,
I would like see some example code that demonstrates how to use
validRegex without a "mask" or example code that demonstrates how to
use "validFunc". My problem is I have need to allow the following
into a text control:

9-99
99-9
999999-999
The number comes from a purchase order. The first section is the
purchase order number(could be very large) and the second section is
the line number never larger than 999.

I'm sure that there is someone out there that can explain it a
little better than the wxPython doc's.

John,

Using a masked.textctrl without a mask is not currently possible; as
written, the masked controls are FIXED WIDTH controls. That is, the
number of digits to the right of the - cannot not be variable, and
the whole value cannot exceed the size of the mask. This is
necessary to do the careful manipulation of the cursor around the
masked positions that the library provides. To have the "mask"
shift as someone types, you're going to have to write your own; feel
free to crib from the innards of MaskedEditMixin.py-- that's where
all of the code basically resides.

Alternatively, you could just build your entry form using 2
numctrls, one for the purchase order number, and the other for the
line. Not as elegant, but it would allow you to use existing
functionality without writing a lot more code...

Regards,
/Will Sadkin
author, lib.masked

Thanks for the response. I started to understand the need of the
mask as I played with the control. Also it helped to start reading
the doc's available in the wxpython demo. I'm still learning how to
use the control by playing around with the methods and attrib's that
are available.

I still haven't got the validFunc to work but I haven't tried much.
Still working with the mask,format, and validRegex.

But I am having an issue at the moment. I'm wondering why the
following does not allow any char's to be typed into the control:
mask='#{5}-#{3}'
format = 'FV'
validRegex = '[1-9]+-[1-9]+'

With the control built this way, the validRegex applies to the entire
value, including the mask specified, for validation. Because you don't
allow spaces in the validation regular expression, the control won't let
you type, because no single keystroke will result in a "valid" resultant
value. (Hint: try "validRegex = '[ 1-9]+-[ 1-9]+'" instead...)

As for validFunc, this opens up the control to arbitrary validation;
if such a function is suppled for a given field or the control as a whole,
it will call your function on any candidate field or control value (as
appropriate) that passes the basic mask restrictions, and expects back a
boolean value. If the function returns True, the candidate value is
accepted; if False, then it's rejected.

/Will

···

On Sunday 16 November 2008 02:35:10 pm Will Sadkin wrote:

Thanks for the hint. BTW I'm working with the Dabo guys and since you have
provided permission to reuse/steal your code I'll be attempting to improve
our text control to include masks and regular expressions and use your code
to get the job done. Thanks

···

On Monday 17 November 2008 09:06:32 am Will Sadkin wrote:

wrote:
> On Sunday 16 November 2008 02:35:10 pm Will Sadkin wrote:
>> Johnf wrote:
>>> Hi,
>>> I would like see some example code that demonstrates how to use
>>> validRegex without a "mask" or example code that demonstrates how to
>>> use "validFunc". My problem is I have need to allow the following
>>> into a text control:
>>>
>>> 9-99
>>> 99-9
>>> 999999-999
>>> The number comes from a purchase order. The first section is the
>>> purchase order number(could be very large) and the second section is
>>> the line number never larger than 999.
>>>
>>> I'm sure that there is someone out there that can explain it a
>>> little better than the wxPython doc's.
>>
>> John,
>>
>> Using a masked.textctrl without a mask is not currently possible; as
>> written, the masked controls are FIXED WIDTH controls. That is, the
>> number of digits to the right of the - cannot not be variable, and
>> the whole value cannot exceed the size of the mask. This is
>> necessary to do the careful manipulation of the cursor around the
>> masked positions that the library provides. To have the "mask"
>> shift as someone types, you're going to have to write your own; feel
>> free to crib from the innards of MaskedEditMixin.py-- that's where
>> all of the code basically resides.
>>
>> Alternatively, you could just build your entry form using 2
>> numctrls, one for the purchase order number, and the other for the
>> line. Not as elegant, but it would allow you to use existing
>> functionality without writing a lot more code...
>>
>> Regards,
>> /Will Sadkin
>> author, lib.masked
>
> Thanks for the response. I started to understand the need of the
> mask as I played with the control. Also it helped to start reading
> the doc's available in the wxpython demo. I'm still learning how to
> use the control by playing around with the methods and attrib's that
> are available.
>
> I still haven't got the validFunc to work but I haven't tried much.
> Still working with the mask,format, and validRegex.
>
> But I am having an issue at the moment. I'm wondering why the
> following does not allow any char's to be typed into the control:
> mask='#{5}-#{3}'
> format = 'FV'
> validRegex = '[1-9]+-[1-9]+'

With the control built this way, the validRegex applies to the entire
value, including the mask specified, for validation. Because you don't
allow spaces in the validation regular expression, the control won't let
you type, because no single keystroke will result in a "valid" resultant
value. (Hint: try "validRegex = '[ 1-9]+-[ 1-9]+'" instead...)

As for validFunc, this opens up the control to arbitrary validation;
if such a function is suppled for a given field or the control as a whole,
it will call your function on any candidate field or control value (as
appropriate) that passes the basic mask restrictions, and expects back a
boolean value. If the function returns True, the candidate value is
accepted; if False, then it's rejected.

/Will

--
John Fabiani