Re: Newbie & timing issue



On Fri, 9 Jul 2004 07:47:00 +0200 (SAST), Alf C Stockton
<alf stockton co za> wrote:
Now for my next trick I would like to restart the display after receiving a
interrupt rather than take up memory & cycles while counting down.

Is there a way that my program could instigate/initiate an interrupt to occur at
some time in the future?

Sure, that's what g_timeout_add() does. This hypnotic program pops up
a dialog box every 2 seconds:

#include <gtk/gtk.h>

void
response_cb( GtkDialog *dialog )
{
        gtk_widget_destroy( GTK_WIDGET( dialog ) );
}

gboolean
timeout_cb()
{
        GtkWidget *dialog;

        dialog = gtk_message_dialog_new( NULL, 0, GTK_MESSAGE_INFO,
                GTK_BUTTONS_OK, "You are feeling sleeeepy ..." );
        g_signal_connect( G_OBJECT( dialog ), "response",
                G_CALLBACK( response_cb ), dialog );
        gtk_widget_show( dialog );

        return( TRUE );
}

int
main( int argc, char **argv )
{
        gtk_init (&argc, &argv);

        g_timeout_add( 2000, (GSourceFunc) timeout_cb, NULL );

        gtk_main();

        return( 0 );
}



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