Re: [Fwd: Gnome Style Guide]




Hello Charl,

> I've studied the gnome-libs source code (not in its entirety
> though), but would like to know what gnome function I can
> periodically call so that the event handling of my application can
> still be responsive even during such a long operation, in order to
> implement this mentioned cancel button.

You can just periodically call this:

flush_pending_events ()
{
	while (gtk_events_pending ())
		gtk_main_iteration ();
}

This allows events to be processed while you are executing the lengthy
operation.  Buttons can be pressed and their callbacks will be invoked
at the proper times.  You just need to provide your cancelation method
somewhere there (even a global flag will do it) like this:

int cancel_clicked;

void cancel ()
{
	cancel_clicked = 1;
}

void long_job ()
{
	cancel_button = create_status_window ();
	cancel_clicked = 0;
	gtk_signal_connect (GTK_OBJECT (cancel_button), "clicked",
		GTK_SIGNAL_FUNC (cancel), NULL);

	while (something){
		do_part_of_task ();
		update_progress_bars ();
		flush_pending_events ();
		if (cancel_clicked){
			printf ("cancelling universe mirror\n");
			break;
		}
	}
}

Miguel.



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