entry input verification [Was: Uppercase only entry widget?]



Havoc Pennington wrote:

> Denis Sarrazin <dsarrazin@cyberus.ca> writes:
> > I'm in the process of learning to code in GTK+ and I am trying to permit
> > only uppercase text to be typed in an entry widget.  I can't seem to be
> > able to do it?  Any help would be appreciated.
> [..]
>
> do the following:
>  - connect to insert_text on the entry
>  - in your callback, map the text to be inserted to uppercase,
>    gtk_signal_emit_stop_by_name() the insert_text signal,
>    then call gtk_editable_insert_text() with your new uppercase text.
>  - Clearly there's an infinite loop problem, so you'll need to block
>    your callback with the gtk_signal_handler_block() functions when
>    you call insert_text(), or maybe don't re-insert if your string
>    is already all-uppercase.
>

On a related subject (It might be an FAQ, but ...):

I am looking for a method to provide input verification on
GtkEntry/GtkEditable, e.g. I am looking for an GtkEditable which shall only
accept a subset of characters (eg. those that match a regular expression, or
integers only) as text input.

[Actually, I  looking for something similar to Motif's XmNmodifyVerifyCallback
for XmTextFieldWidgets]

The approach you outline above doesn't seem to work in my case, because the
insert_text signal does't seem to allow changing the size of the inserted
text.
Implementing it with the changed signal seems to be possible, but seems to be
rather ineffective and also seems to suffer from the "infinite loop" issue
(changed being called because invoking "set_text" ).

Any hints appreciated,

Ralf



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]