Re: Elapsed time



Fethiye Akbulut wrote:
> I would like to show the elapsed time since one of the windows is popped up.
> I have created a GtkEntry and and my plan is to update its value every
> second. The updated value is not written back to the Entry box. Is there a
> way that I could do that easily, without having an infinite loop to wait for
> a second to pass?

Hi Fethiye,

I'd do this by adding a timeout callback:

in your window build function:

	label = gtk_label_new( "0" );
	gtk_timeout_add( 1000, (GtkFunction) update_time, label );

where update_time() is:

	static gboolean
	update_time( GtkWidget *label )
	{
		static int ticks = 0;

		ticks += 1;
		label_setf( label, "%d", ticks );

		return( TRUE );
	}

and label_setf() is:

	static void
	label_setf( GtkWidget *label, const char *fmt, ... )
	{
		va_list ap;
		char buf[ 10000 ];

		va_start( ap, fmt );
		vsprintf( buf, fmt, ap );
		va_end( ap );

		gtk_label_set_text( label, buf );
	}

HTH, John




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