Re: Newbie & timing issue
- From: Alf C Stockton <alf stockton co za>
- To: "David Necas (Yeti)" <yeti physics muni cz>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Newbie & timing issue
- Date: Mon, 12 Jul 2004 20:24:15 +0200 (SAST)
On Mon, 12 Jul 2004, David Necas (Yeti) wrote:
On Mon, Jul 12, 2004 at 07:16:57PM +0200, Alf C Stockton wrote:
John your program required the user to click the OK button to close the
displayed window. Is there a way this can be done by timing. ie The display
window closes, without user interferance, after say 10 seconds?
Again, you can use g_timeout_add(), now the function will
call gtk_button_clicked() on the button after 10s. Just
remember to remove the timeout function when the button is
pressed, so it isn't run then and doesn't try to press it
again.
David, I don't understand what you mean. The code already includes a
g_timeout_add(). Are you suggesting another call to this function?
The code currently looks like:-
#include <gtk/gtk.h>
#include <glib-2.0/glib.h>
#include <time.h>
void response_cb( GtkDialog *dialog )
{
gtk_widget_destroy( GTK_WIDGET( dialog ) );
}
gboolean timeout_cb()
{
GtkWidget *dialog;
struct tm *tm_ptr;
time_t the_time;
gchar Message[256];
time(&the_time);
tm_ptr = localtime(&the_time);
g_sprintf(Message,"It is now %02d:%02d:%02d\n",
tm_ptr->tm_hour,
tm_ptr->tm_min,
tm_ptr->tm_sec);
dialog = gtk_message_dialog_new( NULL, 0, GTK_MESSAGE_INFO,
// GTK_BUTTONS_OK, Message );
GTK_BUTTONS_NONE, Message);
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 );
}
---
Regards,
Alf Stockton www.stockton.co.za
"Thirty days hath Septober,
April, June, and no wonder.
all the rest have peanut butter
except my father who wears red suspenders."
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]