[Glade-users] Timing out a dialog
- From: alexey.kurochkin at pathfinderlwd.com (Alexey Kurochkin)
- Subject: [Glade-users] Timing out a dialog
- Date: Mon, 09 Mar 2009 16:11:46 -0500
On Fri, 2009-03-06 at 17:37 -0500, Tristan Van Berkom wrote:
On Fri, Mar 6, 2009 at 8:27 AM, His Majesty <balakkvj at gmail.com> wrote:
Hi Tristan,
I am not sure how to implement your solution.
This should be the sequence you need:
- Create and configure dialog
- source_id = g_timeout_add (2 seconds, new dialog); <--- right here
- run dialog
- if (source_id > 0) source_id = (g_source_remove (source_id), 0);
<--- and cancel it here, reset the timeout id also...
and the timeout:
- quit dialog
- source_id = 0; <-- reset source timeout id
- return FALSE; <-- ensure timeout is cancelled
Cheers,
-Tristan
Here's working example in C. Should be easy to adapt.
#include <gtk/gtk.h>
gboolean timeout_cb (gpointer dialog)
{
static gint countdown = 10;
--countdown;
if (countdown > 5)
return TRUE;
if (countdown > 0)
{
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"Timeout %d", countdown);
return TRUE;
}
if (GTK_WIDGET_HAS_FOCUS (gtk_window_get_focus (GTK_WINDOW (dialog))))
gtk_widget_hide (dialog);
else
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT);
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *dialog;
gtk_init (&argc, &argv);
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, "%s", "Proceed?");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", "Waiting...");
g_timeout_add (1000, timeout_cb, dialog);
switch (gtk_dialog_run (GTK_DIALOG (dialog)))
{
case GTK_RESPONSE_NONE:
g_message ("%s", "Expired (timeout with no action at all)");
break;
case GTK_RESPONSE_REJECT:
g_message ("%s", "Ignored (timeout with lost focus)");
break;
case GTK_RESPONSE_DELETE_EVENT:
g_message ("%s", "Dismissed (window is closed)");
break;
case GTK_RESPONSE_OK:
g_message ("%s", "Approved (button OK is clicked)");
break;
default:
g_message ("%s", "Defaulted (any unspecified response)");
}
g_source_remove_by_user_data (dialog);
gtk_widget_destroy (dialog);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]