Re: Question on C



On a related note, I'd like to make the GTK+ event loop select/poll on a
blocking file descriptor.  When it's ready to read, I want the event loop
to make a callback.  Should I use g_source_new(), g_source_add_poll(), and
g_source_set_callback () for this?  Is there a higher-level GTK+ API that 
I should be using?

thanks
-dwh-



On Wed, 28 Jan 2004, Gus Koppel wrote:

"Thomas Keaney" wrote:

This hasnt anything to do with GTK+ but I was wondering would any one
know how to program in a delay( say a delay of  2 seconds after
clicking on a button before another event happens). Cheers

If you're just thinking of freezing / stopping your application for a
specific amount of time: this is can be done with the sleep () function
(in unistd.h) or the more capable nanosleep () function (in time.h).
Both of them are not part of ANSI-C; they were defined in some later
standard. They're independent from GTK+ indeed. They're pretty simple
and there are lots of descriptions available for them in the internet.

However, these functions MUST NOT be used in any GUI application, like
GTK+ programs! They are of use for console applications only! Don't code
GUI applications if you prefer to use them, i.e. due to their simplicty!

Because of its event loop based execution and programming model GTK+
(and virtually all other GUI toolkits / environments) provide different
means and require different approaches for delays. See functions like

http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#g-timeout-add

This is because a (proper) GUI application must not really freeze ever.
Windows may be moved, resized and uncovered at any time by the user,
requiring the application to be ready to refresh (redraw) windows
contents any time. This isn't the case if an application is frozen
(by use of one of the delay functions).
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list







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