From: Schollnick, B. <Ben...@us...> - 2004-04-15 15:06:58
|
> 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() Why even check to see the keycode is uppercase? Is there really that much latency with the uppercase function? Yet, do we care if it was already uppercase? Uppercasing a uppercase letter results in a uppercase letter.... Since the desire is for the result to be uppercase, there is two ways to approach this. At data entry, which is what you presented... Here's my alteration of your code: def on_fld_keyPress(self, event): """Force the results from the keypress to be uppercase. """ event.target.replaceSelection( chr(event.keyCode).upper() ) Or alternatively, when the entry is done and the user moves to the next field, just do a .upper() on the text string as you leave the field. I would suggest that as a standard pythoncard option, that the field be untouched, or made uppercase, lowercase or normal after leaving the field. The logic for that should only be a few lines of code, but would be quite helpful... - Benjamin |