Re: how to tell gtk to update only the GUI
- From: "David Necas (Yeti)" <yeti physics muni cz>
- To: Mehmet YASAR <myasar free fr>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: how to tell gtk to update only the GUI
- Date: Wed, 3 May 2006 19:25:15 +0200
On Wed, May 03, 2006 at 10:03:34AM -0400, Tristan Van Berkom wrote:
If you need your application to refuse button & key press events
(but still refresh itself graphicly), you should set the sensitivity
of your buttons during the lengthly operation (and just ignore key
press events).
I agree the right thing is normally to make the widgets
insensitive but it is possible to do what Mehmet requested
too with gtk_grab_add() on some `passive' widget -- see the
attached example.
Yeti
--
Anonyms eat their boogers.
===========================================================================
#include <gtk/gtk.h>
static void
response(GtkWidget *dialog,
gint response_id)
{
GtkWidget *progress;
gint i, n = 1000;
if (response_id != GTK_RESPONSE_APPLY) {
gtk_main_quit();
return;
}
progress = g_object_get_data(G_OBJECT(dialog), "progress");
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Calculating...");
gtk_grab_add(progress);
for (i = 0; i < n; i++) {
/* emulate a heavy calculation step */
g_usleep(50);
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), i/(n - 1.0));
while (gtk_events_pending())
gtk_main_iteration_do(FALSE);
}
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), 0.0);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), NULL);
while (gtk_events_pending())
gtk_main_iteration_do(FALSE);
gtk_grab_remove(progress);
}
int
main(int argc, char *argv[])
{
GtkWidget *dialog, *widget;
GtkObject *adj;
GtkBox *box;
gtk_init(&argc, &argv);
dialog = gtk_dialog_new_with_buttons("Modal Trick", NULL, 0,
GTK_STOCK_EXECUTE,
GTK_RESPONSE_APPLY,
GTK_STOCK_CLOSE,
GTK_RESPONSE_CLOSE,
NULL);
g_signal_connect(dialog, "response", G_CALLBACK(response), NULL);
box = GTK_BOX(GTK_DIALOG(dialog)->vbox);
widget = gtk_check_button_new_with_label("Check me!");
gtk_box_pack_start(box, widget, FALSE, FALSE, 0);
widget = gtk_entry_new();
gtk_box_pack_start(box, widget, FALSE, FALSE, 0);
adj = gtk_adjustment_new(0.0, 0.0, 100.0, 1.0, 10.0, 0.0);
widget = gtk_hscale_new(GTK_ADJUSTMENT(adj));
gtk_box_pack_start(box, widget, FALSE, FALSE, 0);
widget = gtk_progress_bar_new();
gtk_box_pack_start(box, widget, FALSE, FALSE, 0);
g_object_set_data(G_OBJECT(dialog), "progress", widget);
gtk_widget_show_all(dialog);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]