From: Kevin A. <al...@se...> - 2004-04-15 14:34:22
|
> From: ralph heimburger > > Speaking of attributes, TextField esp. is there a way to force > the field to be UPPERCASE? > > In DataFlex all we needed to do was add {CAPSLOCK} to the entry field. There is no attribute for the TextField to force text to be UPPERCASE. If you need that capability a lot you would probably be best off creating a subclass of the TextField component to give you that functionality. Is this a capability a lot of people need for dealing with databases? However, it is easy to force text to be uppercase with event handlers. There are two events worth investigating, textUpdate which is received every time the text in a field changes and keyPress which occurs as the user is typing. 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() The textUpdate solution is a bit more complex since we need to keep track of the selection as well. Since changing the text in the middle of the textUpdate event will cause another text update event, you have to have a check like the one below to avoid a recursion problem. On Linux/GTK you might also have to save and restore the insertion point as well as the selection, but I can't test that from here. def on_fld_textUpdate(self, event): text = event.target.text upper = text.upper() if text != upper: start, end = event.target.getSelection() event.target.text = upper event.target.setSelection(start, end) else: event.skip() Finally, if you just want to make sure the text is uppercase before you plug it into a database or wherever you're going to use the text, you can do the upper() conversion in your code (e.g. self.components.fld.text.upper() ) and not worry about what the user sees. ka |