From: ralph h. <1st...@1I...> - 2004-04-15 17:39:14
|
Forgive my lack of extensive pythonic knowledge but wouldn't a tr work better? Would I have to create a separate event for all 66 fields? --- "Kevin Altis" <al...@se...> wrote: > From: Kevin Altis > > On Apr 15, 2004, at 8:06 AM, Schollnick, Benjamin wrote: > > > > >> Since you have control over what goes in the field within > >> your own code, > >> keyPress is probably the easiest since it would just deal > >> with what a user > >> types. > >> > >> Given a TextField named 'fld' the following event handler > >> should do what you > >> want for plain ascii as well as unicode strings > >> > >> def on_fld_keyPress(self, event): > >> upper = chr(event.keyCode).upper() > >> if chr(event.keyCode) != upper: > >> event.target.replaceSelection(upper) > >> else: > >> event.skip() Well I have egg on my face now. So much for writing and testing code before I have my morning coffee. I thought I had tested arrow keys, but I guess not since chr() will throw a value error for keyCodes outside the range 0-255. At a minimum you need to catch that exception. def on_field1_keyPress(self, event): try: upper = chr(event.keyCode).upper() if chr(event.keyCode) != upper: event.target.replaceSelection(upper) else: event.skip() except ValueError: event.skip() However, now that I think about it more I don't see how this is going to deal with Unicode characters outside the ASCII range. It might be simpler to check whether the keyCode is in the wxWidgets defined key codes to see if it is a special character. Sadly, I don't know enough about Unicode to take this much further. Maybe someone else can chime in with the solution to deal with non-ASCII. ka ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ Pythoncard-users mailing list Pyt...@li... https://lists.sourceforge.net/lists/listinfo/pythoncard-users _____________________________________________________________ ======================================= www.StrictlyEmail.com ...our name says it all! |