Re: [gtk-list] Question about event loops
- From: Erik Mouw <J A K Mouw its tudelft nl>
- To: jemoody home com
- Cc: gtk-list redhat com
- Subject: Re: [gtk-list] Question about event loops
- Date: Mon, 4 Oct 99 10:30:49 +0200
On Sat, 02 Oct 1999 20:49:32 -0400 (EDT), James Moody wrote:
> I have a question about event processing. In my potential use of GTK,
> calling gtk_main() is not acceptable. I need to be able to process
> events that are unrelated to GTK in the same thread, so what would be
> ideal for me is a loop that I can use which will accomplish the same
> thing yet provide me with time to do my alternative event processing.
>
> The basic idea of the loop would be
> while (events pending) {
> process some gtk events
> do some of my own event processing
> sleep maybe?
> }
>
> In Havoc Pennington's book, I see
> while (gtk_events_pending())
> gtk_main_iteration();
>
> which would seem to suit my needs, but I thought I'd ask to make sure.
> Does the code quoted above assume that I'm already in at least one
> level of gtk_main() calls? Or is it intended to be used on its own?
> (The context of the example in the book where the above code came from
> involved processing events while in a lengthy callback, and gtk_main()
> was already running, which is why I wasn't sure).
This can be used instead of gtk_main(), too. But you'd better use
while(! need_to_stop_the_program)
{
while(gtk_events_pending())
gtk_main_iteration();
process_my_own_events();
usleep(somewhat); /* if necessary */
}
because you don't want your program to quit because there are no events to
be processed.
> Before you ask the obvious "why are you doing this? Just call gtk_main()",
> I'll say that this is not a simple GTK application, and having done the
> same thing on other platforms, we have a pretty good idea of the type of
> solution we need for this particular project. The documentation for the
> event functions is just sketchy at best and I need more information on
> what the above calls are intended to do, specifically.
You can also use a gtk_timeout function that checks for your events, I've
done it that way in a MIDI player and a video sequence player. Or fork() a
child that does the processing (done it that way in an agent based
visualisation tool). Or use multi threading.
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2785859 Fax: +31-15-2781843 Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]