RE: Creating a local event loop (modality again...)
- From: Warrior <ymg azstarnet com>
- To: gtk-app-devel-list gnome org
- Subject: RE: Creating a local event loop (modality again...)
- Date: Wed, 08 Nov 2000 17:43:43 -0700 (MST)
On 08-Nov-2000 Federico Heinz shared with us the following piece of wisdom:
Suppose you have a text entry, where the user can enter
abbreviations, and the program must expand the abbreviations when the
user leaves the entry. This is pretty easy, all you must do is
connect the entry's "focus_out_event" to a handler that replaces the
abbreviations for the full text.
Now suppose that the abbreviations are not univocal, i.e. it might
happen that the user enters an abbreviation that matches more than
one expansion. In that case, I would like to have the program pop up
a window with the list of potential matches, and let the user decide
which expansion she meant. If there are more than one ambiguous
match, the program should pop up the window to let the user select
which is the right expansion for the first one, then pop it up again
for the second, and so on.
I'm having real trouble implementing this. The main problem here is
that the "focus_out_event" handler must create the window, display
it, and handle this window's user input, and even potentially repeat
all of this several times BEFORE returning to the main Gtk event
loop. What this amounts to, basically, is a local event loop for this
window exclusively, but I haven't been able to figure out how to do
that yet. I considered using gtk_main_iteration(), but I understand
that it does busy waiting, and I'm not THAT desperate.
Any pointers on how to go about this? Or even a suggestion for a
better implementation? I must admit I hate modal windows myself, but
I seem unable to come up with a better idea.
All right, here's the implementation that works for me (although there might be
better implementations out there, which I'm not aware about):
1. End the function, which creates the modal window with call to gtk_main().
2. In the callback attached to "destroy" signal call gtk_main_quit() after
destroying the window.
3. IMPORTANT: Block the "delete_event" signal for this window - callback
attached to this signal should simply return TRUE.
4. It might be possible to also call gtk_main_quit() from the callback attached
to "delete_event" instead of doing step #3, but I never tried that and
don't know if it's gonna work or not.
Hope this helps.
--
Bye, Warrior.
ICQ #24496762
-------------
Tagline for Wednesday, November 08, 2000, 17:33
--- Don't Take Life Seriously, It Is Not Permanent.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]