wxFormattedText masked edit control v0.0.1

Ok, I am hardly a python -or- wxAnything expert. But I was itching to take a
crack at this, so here's version 0.0.1. I hope that there're some experts
out there who can help me get this thing finished and in the library. I know
it will be helpful for me and I'm guessing lots of others.

It should run in demo mode from double-clicking (in Win32 anyways).

The .test method is very easy to play with. If you want to add controls or
change the ones that display, just add them to the controls list. You'll see
how it's formatted.

Check out the date/time format. Pretty cool. Now we just combine that with a
small button that pops up the calendar and we'll be in business :wink:

Apologies to Magnus and Joe - your suggestion about using regular
expressions is a great one, it could combine validation logic with
formatting, but I am totally lost with regular expressions at the moment so
that particular hurdle was too high. I'm thinking a set method could be
added later to parse re's and create the format mask while still preserving
the validation capability of the re. I think.

I'll take any suggestions, code, criticisms, or whatever. I'm going to try
to finish this up quickly before I lose steam. Email me directly at
jchilders_98@yahoo.com.

Ps- I cc'd Donnal and Joe since you both seemed interested in helping. Sorry
if I bugged you in error. :slight_smile:

Current Issues:

tst_fmttext.py (10.8 KB)

···

===============
1. I haven't figured out how to force focus to move to the next control
(i.e. simulate a tab keypress) when the user reaches the end of the format
field. If you get stuck at the end of the field, press shift-Tab to get out,
then you can tab past the field to the next control.

2. I haven't yet contemplated right-justified data (e.g currency), or data
that wraps around or fills around a currency field (e.g. "99.99").

3. Arrow keys are not quite working properly.

4. Cut/Copy/Paste not yet addressed.

5. Backspace not yet addressed.

6. Mask characters [A,a,X,#] cannot appear in the format string as literals.

7. No method yet to GET the value free of formatting characters.

8. It should allow some way to specify repeating masks, e.g. (#3)-(#3)-(#4)
- this
   could be parsed by re and the standard format string could be built
(###-###-####).
   Therefore no additional logic would be needed, just the syntax and the re
parser.

9. Nothing has been optimized or factored, much less refactored. Heh.

Ideas/Comments:

1. I think it will be easy to setup char-position validations for say dates.
I.e. first char must be 0 or 1, 1 can only be followed by 0, 1 or 2, etc.

2. Note that the alpha character 'A' can -either- REQUIRE a cap or can force
caps.

3. I stole code shamelessly from the wxTimeCtrl written by Will Sadkin.
Kudos Will, I never would have figured out the fixselection method on my
own. Oh! And thanks for the *great* debug function :slight_smile:

Regards,

Jeff Childers
jchilders_98@yahoo.com

-----Original Message-----
From: Jason Hihn [mailto:jhihn@paytimepayroll.com]
Sent: Tuesday, February 11, 2003 10:30 AM
To: wxPython-users@lists.wxwindows.org
Subject: RE: [wxPython-users] Masked edits?

I have not been able to put time into this endeavor yet. You can start it if
you wish. I will eventually need this, so I'll end up doing it if it's not
already done by the time I get to it. But for the time being I've been put
on higher priority stuff. :frowning:

The functions I listed were just to illustrate an idea - the notion was that
you can assign the behavior by calling a function, and leave the format
specs as a parameter. At that time we had people wanting to use RE, I was
concerned with easy formatting of currency, and someone wanted printf
styles. So rather than bicker about which one to use, I wanted to show that
you could use all of them on the same class, and infer the behavior :wink:

Also, I'm rather new to Python and wxWindows so I probably won't write the
best code. I'm picking it up quickly though!

-J

-----Original Message-----
From: Jeff Childers [mailto:jchilders@smartbusinessware.com]
Sent: Tuesday, February 11, 2003 8:59 AM
To: 'wxPython-users@lists.wxwindows.org'
Subject: RE: [wxPython-users] Masked edits?

I would be happy to help with this, if I can. Send me code to test, or send
me what you've got and assign me a function or two.

Regards,

Jeff Childers

-----Original Message-----
From: Jason Hihn [mailto:jhihn@paytimepayroll.com]
Sent: Wednesday, January 29, 2003 1:34 PM
To: wxPython-users@lists.wxwindows.org
Subject: RE: [wxPython-users] Masked edits?

def SetFormatByRegExp(self, format): # r'\(\d\d\d\)\d\d\d-\d\d\d'
def SetFormatByString(self, format): # (###)###-####
def SetFormatAsCurrency(self, format): # ###,###.##;-;[red]###,###.##
def SetCurrencyDecimal(self, ch): ch='.' or ','; only valid when
SetFormatAsCurrency has been called.
def SetFormatByPrintf(self, format): # (%03d)%03d-%04d

-----Original Message-----
From: Magnus Lycka [mailto:magnus@thinkware.se]
Sent: Wednesday, January 29, 2003 1:15 PM
To: wxPython-users@lists.wxwindows.org
Subject: RE: [wxPython-users] Masked edits?

At 16:21 2003-01-29 +0100, Magnus Lycka wrote:

At 10:10 2003-01-28 -0800, Donnal Walter wrote:

What else would we need besides # for digit?

I think it's a good idea to avoid reinventing the wheel.

Actually, considering what I just said, I feel that there
are two natural forms of syntax for edit masks. One is
string formatting, and the other is regular expressions.
Why should programmers have to learn a third way of saying
more or less the same thing?

Rather than: Format='(###)###-####' I would suggest that we
either write Format='(%3i)%3i-%4i' or
Format=r'\(\d\d\d\)\d\d\d-\d\d\d'

I realize that RE and format strings are different from edit
masks, but at least we won't have to invent so much, and
programmers won't have yet another syntax to learn. One could
actually imagine reusing the strptime syntax as well, it fits
with string syntax.

I guess the regular expression syntax is the most versitile
of these though. We have \d for digit and \w for alphanumeric.
If we want to be able to enter floats, we can type
Format = r'-?\d+\.\d*' only letters Format=r'[A-Za-z]*' and
so on.

One thing to consider though: Don't forget that not all people
use US ASCII letters, or decimal points. (Some countries actually
follow the ISO standard...)

--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Hi Jeff,

Thanks for your efforts. I wanted to try out your sample file but ran into the following error:

[ewalstad@padma Desktop]$ py tst_fmttext.py
Traceback (most recent call last):
   File "tst_fmttext.py", line 64, in ?
     from wxPython.lib.evtmgr import eventManager
ImportError: No module named evtmgr

I searched my wxPython directory for evtmgr and didn't find anything. Can you point me to info on this module?

I'm running RedHat Linux with wxPython 2.3.3.1 and Python 2.2

Thanks again,

Eric.

Jeff Childers wrote:

···

Ok, I am hardly a python -or- wxAnything expert. But I was itching to take a
crack at this, so here's version 0.0.1. I hope that there're some experts
out there who can help me get this thing finished and in the library. I know
it will be helpful for me and I'm guessing lots of others.

It should run in demo mode from double-clicking (in Win32 anyways).

The .test method is very easy to play with. If you want to add controls or
change the ones that display, just add them to the controls list. You'll see
how it's formatted.

Check out the date/time format. Pretty cool. Now we just combine that with a
small button that pops up the calendar and we'll be in business :wink:

Apologies to Magnus and Joe - your suggestion about using regular
expressions is a great one, it could combine validation logic with
formatting, but I am totally lost with regular expressions at the moment so
that particular hurdle was too high. I'm thinking a set method could be
added later to parse re's and create the format mask while still preserving
the validation capability of the re. I think.

I'll take any suggestions, code, criticisms, or whatever. I'm going to try
to finish this up quickly before I lose steam. Email me directly at
jchilders_98@yahoo.com.

Ps- I cc'd Donnal and Joe since you both seemed interested in helping. Sorry
if I bugged you in error. :slight_smile:

Current Issues:

1. I haven't figured out how to force focus to move to the next control
(i.e. simulate a tab keypress) when the user reaches the end of the format
field. If you get stuck at the end of the field, press shift-Tab to get out,
then you can tab past the field to the next control.

2. I haven't yet contemplated right-justified data (e.g currency), or data
that wraps around or fills around a currency field (e.g. "99.99").

3. Arrow keys are not quite working properly.

4. Cut/Copy/Paste not yet addressed.

5. Backspace not yet addressed.

6. Mask characters [A,a,X,#] cannot appear in the format string as literals.

7. No method yet to GET the value free of formatting characters.

8. It should allow some way to specify repeating masks, e.g. (#3)-(#3)-(#4)
- this
   could be parsed by re and the standard format string could be built
(###-###-####).
   Therefore no additional logic would be needed, just the syntax and the re
parser.

9. Nothing has been optimized or factored, much less refactored. Heh.

Ideas/Comments:

1. I think it will be easy to setup char-position validations for say dates.
I.e. first char must be 0 or 1, 1 can only be followed by 0, 1 or 2, etc.

2. Note that the alpha character 'A' can -either- REQUIRE a cap or can force
caps.

3. I stole code shamelessly from the wxTimeCtrl written by Will Sadkin.
Kudos Will, I never would have figured out the fixselection method on my
own. Oh! And thanks for the *great* debug function :slight_smile:

Regards,

Jeff Childers
jchilders_98@yahoo.com

-----Original Message-----
From: Jason Hihn [mailto:jhihn@paytimepayroll.com]
Sent: Tuesday, February 11, 2003 10:30 AM
To: wxPython-users@lists.wxwindows.org
Subject: RE: [wxPython-users] Masked edits?

I have not been able to put time into this endeavor yet. You can start it if
you wish. I will eventually need this, so I'll end up doing it if it's not
already done by the time I get to it. But for the time being I've been put
on higher priority stuff. :frowning:

The functions I listed were just to illustrate an idea - the notion was that
you can assign the behavior by calling a function, and leave the format
specs as a parameter. At that time we had people wanting to use RE, I was
concerned with easy formatting of currency, and someone wanted printf
styles. So rather than bicker about which one to use, I wanted to show that
you could use all of them on the same class, and infer the behavior :wink:

Also, I'm rather new to Python and wxWindows so I probably won't write the
best code. I'm picking it up quickly though!

-J

-----Original Message-----
From: Jeff Childers [mailto:jchilders@smartbusinessware.com]
Sent: Tuesday, February 11, 2003 8:59 AM
To: 'wxPython-users@lists.wxwindows.org'
Subject: RE: [wxPython-users] Masked edits?

I would be happy to help with this, if I can. Send me code to test, or send
me what you've got and assign me a function or two.

Regards,

Jeff Childers

-----Original Message-----
From: Jason Hihn [mailto:jhihn@paytimepayroll.com]
Sent: Wednesday, January 29, 2003 1:34 PM
To: wxPython-users@lists.wxwindows.org
Subject: RE: [wxPython-users] Masked edits?

def SetFormatByRegExp(self, format): # r'\(\d\d\d\)\d\d\d-\d\d\d'
def SetFormatByString(self, format): # (###)###-####
def SetFormatAsCurrency(self, format): # ###,###.##;-;[red]###,###.##
def SetCurrencyDecimal(self, ch): ch='.' or ','; only valid when
SetFormatAsCurrency has been called.
def SetFormatByPrintf(self, format): # (%03d)%03d-%04d

-----Original Message-----
From: Magnus Lycka [mailto:magnus@thinkware.se]
Sent: Wednesday, January 29, 2003 1:15 PM
To: wxPython-users@lists.wxwindows.org
Subject: RE: [wxPython-users] Masked edits?

At 16:21 2003-01-29 +0100, Magnus Lycka wrote:

At 10:10 2003-01-28 -0800, Donnal Walter wrote:

What else would we need besides # for digit?

I think it's a good idea to avoid reinventing the wheel.

Actually, considering what I just said, I feel that there
are two natural forms of syntax for edit masks. One is
string formatting, and the other is regular expressions.
Why should programmers have to learn a third way of saying
more or less the same thing?

Rather than: Format='(###)###-####' I would suggest that we
either write Format='(%3i)%3i-%4i' or
Format=r'\(\d\d\d\)\d\d\d-\d\d\d'

I realize that RE and format strings are different from edit
masks, but at least we won't have to invent so much, and
programmers won't have yet another syntax to learn. One could
actually imagine reusing the strptime syntax as well, it fits
with string syntax.

I guess the regular expression syntax is the most versitile
of these though. We have \d for digit and \w for alphanumeric.
If we want to be able to enter floats, we can type
Format = r'-?\d+\.\d*' only letters Format=r'[A-Za-z]*' and
so on.

One thing to consider though: Don't forget that not all people
use US ASCII letters, or decimal points. (Some countries actually
follow the ISO standard...)

--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

I'm pretty sure that the Event Manager stuff was added very recently; you
probably need 2.4 (2.4.0.2 is the current download).

  /cco

Ok, I am hardly a python -or- wxAnything expert. But I was itching to take a
crack at this, so here's version 0.0.1. I hope that there're some experts
out there who can help me get this thing finished and in the library. I know
it will be helpful for me and I'm guessing lots of others.

[...]

I'll take any suggestions, code, criticisms, or whatever. I'm going to try
to finish this up quickly before I lose steam. Email me directly at
jchilders_98@yahoo.com.

[...]

Current Issues:

1. I haven't figured out how to force focus to move to the next control
(i.e. simulate a tab keypress) when the user reaches the end of the format
field. If you get stuck at the end of the field, press shift-Tab to get out,
then you can tab past the field to the next control.

I haven't actually looked at Jeff's control, but the issue of how to
programatically move to the next (or previous) control seems to have come
up recently; at least, that's the way it seems to me.

This afternoon, I finally broke down and fetched the source code (the
Win32 and Debian packages work so well that I've never needed to, until
now), and as it turns out, the solution is really very simple. A simple
control that wants to push focus to the next control in line just needs to
do this:

        new_event = wxNavigationKeyEvent()
        new_event.SetEventObject( self )
        new_event.SetDirection( 1 )
        new_event.SetWindowChange( 0 )
        new_event.SetCurrentFocus( self )
        self.GetEventHandler().ProcessEvent( new_event )

That's it! All of the container handling code already in wxWindows will
take care of finding and settting focus to the control after the one used
in the call to "new_event.SetCurrentFocus()".

I have an annotated demo module that shows how this works; if that's
interesting, I can post it or put it in the wiki. (Robin? any preference?)

  /cco

p.s. Robin - I think there may be some initialization bugs in the Generic
Button code; my test doesn't always work correctly from the keyboard if I
use wxGenButton, but always works right with wxButton. Where should the
bug be filed? Gtk 1.2, Debian Linux, using the 2.4.0.3 packages.

···

On Tue, 11 Feb 2003, Jeff Childers wrote: