Re: timeout function not called
Thanks James, Sorry, I didn't mean to seem like I was ignoring you, but the code I am working on is part of a bigger application and I wasn't sure how to extract the bit I was working on into a usable piece. I was also looking into using GIOChannels to see if I could make that work. Thanks for the example. I'll work through it and see if I can get that working in my project. Sincerely, Vicki Quoting James Scott Jr [EMAIL PROTECTED]: Vicki, Here is a more complete example of how to resolve your issue. Compile with this command '# gcc -Wall -g -O2 `pkg-config --libs --cflags gtk+-2.0 glib-2.0 gthread-2.0` gprogress.c' -- Invent your own San Diego at sandiego.com! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: timeout function not called
Vicki, I though you might have been chopping something up, thats the reason for the quick samepl. I'm going to assume it worked for you and you understand why it works. As for GIOChannels, they are very handy and could be used in an elaborate scheme to get this simple thing done. James, (This mailing list has an archive you can search for q/a on GIOChannels and ProgressBars...) - Original Message From: [EMAIL PROTECTED] [EMAIL PROTECTED] To: James Scott Jr [EMAIL PROTECTED] Cc: gtk-app-devel-list@gnome.org Sent: Tuesday, October 9, 2007 11:45:52 AM Subject: Re: timeout function not called Thanks James, Sorry, I didn't mean to seem like I was ignoring you, but the code I am working on is part of a bigger application and I wasn't sure how to extract the bit I was working on into a usable piece. I was also looking into using GIOChannels to see if I could make that work. Thanks for the example. I'll work through it and see if I can get that working in my project. Sincerely, Vicki Quoting James Scott Jr [EMAIL PROTECTED]: Vicki, Here is a more complete example of how to resolve your issue. Compile with this command '# gcc -Wall -g -O2 `pkg-config --libs --cflags gtk+-2.0 glib-2.0 gthread-2.0` gprogress.c' -- Invent your own San Diego at sandiego.com! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: timeout function not called
Vicki, Here is a more complete example of how to resolve your issue. Compile with this command '# gcc -Wall -g -O2 `pkg-config --libs --cflags gtk+-2.0 glib-2.0 gthread-2.0` gprogress.c' BEGIN-CODE #include gtk/gtk.h /* no globals */ typedef struct _INSTANCE_VALUES { GtkWidget *progressbar; GThread *tid_growPart; gboolean b_pulse_control; gint i_growPart_rc; } STEMP, *PST; #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #define EXIT_SUCESS 0 #endif static gpointer fn_growPart (PST pInstance); static gboolean fn_progress_update (PST pInstance); static void cb_push_button_clicked (GtkButton *button, PST pInstance); int main (int argc, char *argv[]); int main (int argc, char *argv[]) { GtkWidget *window = NULL; GtkWidget *widget = NULL; GtkWidget *box = NULL; PSTpInstance = NULL; g_thread_init (NULL); gdk_threads_init (); gtk_init (argc, argv); pInstance = g_new0 (STEMP, 1); g_return_val_if_fail (pInstance != NULL, -1); /* create app window */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, delete-event, gtk_main_quit, NULL); gtk_window_set_title (GTK_WINDOW (window), GrowPart Thread Example); box = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER(window), box); pInstance-progressbar = gtk_progress_bar_new (); gtk_progress_bar_set_text (GTK_PROGRESS_BAR(pInstance-progressbar), Not Running!); gtk_box_pack_start (GTK_BOX(box), pInstance-progressbar, TRUE, TRUE, 0); widget = gtk_button_new_from_stock (GTK_STOCK_APPLY); g_signal_connect (G_OBJECT(widget), clicked, G_CALLBACK(cb_push_button_clicked), pInstance); gtk_box_pack_end (GTK_BOX(box), widget, TRUE, TRUE, 0); gtk_widget_show_all (GTK_WIDGET(window)); /* * enter the GTK main loop */ gdk_threads_enter (); gtk_main (); gdk_threads_leave (); g_free (pInstance); return 0; } static void cb_push_button_clicked (GtkButton *button, PST pInstance) { g_return_if_fail (pInstance != NULL); pInstance-b_pulse_control = TRUE; gtk_progress_bar_set_text (GTK_PROGRESS_BAR(pInstance-progressbar), Please Wait!); g_timeout_add(100, (GSourceFunc)fn_progress_update, pInstance); pInstance-tid_growPart = g_thread_create ( (GThreadFunc)fn_growPart, pInstance, TRUE, NULL); } static gboolean fn_progress_update (PST pInstance) { g_return_val_if_fail (pInstance != NULL, FALSE); if (pInstance-b_pulse_control) { gtk_progress_bar_pulse (GTK_PROGRESS_BAR(pInstance-progressbar)); return TRUE; } else { pInstance-i_growPart_rc = GPOINTER_TO_INT( g_thread_join (pInstance-tid_growPart) ); gtk_progress_bar_set_text (GTK_PROGRESS_BAR(pInstance-progressbar), Not Running!); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(pInstance-progressbar),0.0); return FALSE; } } /* * gthread routine * -- never do any gtk calls from this thread - NEVER */ static gpointer fn_growPart (PST pInstance) { gint i_index = 0; if (pInstance == NULL) { g_thread_exit( GINT_TO_POINTER(EXIT_FAILURE) ); } /* do work */ /* growPart(); */ while (i_index++ 40) { g_usleep (25); /* 1/4 second * 40 = 10 seconds */ } pInstance-b_pulse_control = FALSE; g_thread_exit( GINT_TO_POINTER( EXIT_SUCESS ) ); return NULL; } END-CODE James, On Thu, 2007-10-04 at 13:27 -0700, [EMAIL PROTECTED] wrote: Thanks James for giving me my first experience with Thread programming! I tried the code you sent me, but unfortunately, I still can't get the progress_update function to run, looks like it never gets called. Any idea why this might be happening? growPart still runs. Thanks, Vicki [Hide Quoted Text] GTK program before. The ret=wait(null) causes execution to stop at that point and wait for growPart() to finish. A way to get around the logistics of fork() is to use threads directly. Consider the following; /* globals */ gboolean b_pulse_control = FALSE GThread *grow_thread_id = NULL; gint global_ret = 0; b_pulse_control = TRUE; timer = g_timeout_add(50, (GSourceFunc) progress_update, (gpointer)progressbar); grow_thread_id = g_thread_create ( growPart_thread, b_pulse_control, TRUE, NULL); static gboolean progress_update (gpointer progressbar) { if (b_pulse_control) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); return true; } else { global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread) ); return FALSE; } } static gpointer growPart_thread(gpointer b_pulse) { /* do work */ growPart(); *b_pulse = FALSE; g_thread_exit( GINT_TO_POINTER( 1 ) ); } I would do the passing of control values via a structure to avoid the use of globals, but this
Re: timeout function not called
Thanks James for giving me my first experience with Thread programming! I tried the code you sent me, but unfortunately, I still can't get the progress_update function to run, looks like it never gets called. Any idea why this might be happening? growPart still runs. Thanks, Vicki [Hide Quoted Text] GTK program before. The ret=wait(null) causes execution to stop at that point and wait for growPart() to finish. A way to get around the logistics of fork() is to use threads directly. Consider the following; /* globals */ gboolean b_pulse_control = FALSE GThread *grow_thread_id = NULL; gint global_ret = 0; b_pulse_control = TRUE; timer = g_timeout_add(50, (GSourceFunc) progress_update, (gpointer)progressbar); grow_thread_id = g_thread_create ( growPart_thread, b_pulse_control, TRUE, NULL); static gboolean progress_update (gpointer progressbar) { if (b_pulse_control) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); return true; } else { global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread) ); return FALSE; } } static gpointer growPart_thread(gpointer b_pulse) { /* do work */ growPart(); *b_pulse = FALSE; g_thread_exit( GINT_TO_POINTER( 1 ) ); } I would do the passing of control values via a structure to avoid the use of globals, but this should work for you. -- Invent your own San Diego at sandiego.com! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: timeout function not called
On Thu, 2007-10-04 at 13:27 -0700, [EMAIL PROTECTED] wrote: Thanks James for giving me my first experience with Thread programming! I tried the code you sent me, but unfortunately, I still can't get the progress_update function to run, looks like it never gets called. Any idea why this might be happening? growPart still runs. Thanks, Vicki The code i offered is really high level - almost sudo code. I prefer to evaluate a fuller example, if you care to post the whole program - or email it to me and I will email it back. Things I would be interested in would be as follows; 1. did you do away with the fork() and wait() calls? 2. did you compile it with something like this - with gthread included? # gcc -Wall `pkg-config --libs --cflags gtk+-2.0 glib-2.0 gthread-2.0` program.c 3. Did you call g_thread_init() in main(). ? /* * Initialize GLib thread support and GTK */ g_type_init (); g_thread_init (NULL); gdk_threads_init (); gtk_init (argc, argv); /* create app window */ /* create progress bar dialog */ /* * enter the GTK main loop */ gdk_threads_enter (); gtk_main (); gdk_flush (); gdk_threads_leave (); return (0); 4. How long does growPart() run? longer than 100ms the g_timeout_add() is only for 50ms, and it waits 50ms before making the first call kinda short, try 250 or 400 5. Assuming your created a dialog box for the progress bar and thats is is visible it should have ran. Stick a g_debug(update); in the progress_update() routine after the call to gtk_progress_bar_pulse() 6. I'm thinking the most likely cause is how the program was compiled. send me some code to look at! James, [Hide Quoted Text] GTK program before. The ret=wait(null) causes execution to stop at that point and wait for growPart() to finish. A way to get around the logistics of fork() is to use threads directly. Consider the following; /* globals */ gboolean b_pulse_control = FALSE GThread *grow_thread_id = NULL; gint global_ret = 0; b_pulse_control = TRUE; timer = g_timeout_add(50, (GSourceFunc) progress_update, (gpointer)progressbar); grow_thread_id = g_thread_create ( growPart_thread, b_pulse_control, TRUE, NULL); static gboolean progress_update (gpointer progressbar) { if (b_pulse_control) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); return true; } else { global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread) ); return FALSE; } } static gpointer growPart_thread(gpointer b_pulse) { /* do work */ growPart(); *b_pulse = FALSE; g_thread_exit( GINT_TO_POINTER( 1 ) ); } I would do the passing of control values via a structure to avoid the use of globals, but this should work for you. -- Invent your own San Diego at sandiego.com! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: timeout function not called
On Tue, 2007-10-02 at 10:51 -0400, [EMAIL PROTECTED] wrote: I'm still muddling my way through my first GTK application (and I'm a relative newbie on all software matters). I have the following in one of my callbacks: timer = g_timout_add(50, (GSourceFunc) progress_update, (gpointer)progressbar); pid = fork( ); if (pid == 0) { growPart ( ); exit(0); } ret = wait(NULL); g_source_remove(timer); --- where progress_update is: static gboolean progress_update (gpointer progressbar) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); return true; } I was hoping that this would mean that the progress bar would pulse while growPart() was running, but instead it waits until after (is this because control hasn't been returned to gtk_main yet?) at which point it is removed. If I take out the g_source_remove it runs beautifullybut only after growPart has completed. How can I get around this? Thanks so much The use of FORK is a little odd, I don't think I've seen that used in a GTK program before. The ret=wait(null) causes execution to stop at that point and wait for growPart() to finish. A way to get around the logistics of fork() is to use threads directly. Consider the following; /* globals */ gboolean b_pulse_control = FALSE GThread *grow_thread_id = NULL; gint global_ret = 0; b_pulse_control = TRUE; timer = g_timeout_add(50, (GSourceFunc) progress_update, (gpointer)progressbar); grow_thread_id = g_thread_create ( growPart_thread, b_pulse_control, TRUE, NULL); static gboolean progress_update (gpointer progressbar) { if (b_pulse_control) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); return true; } else { global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread) ); return FALSE; } } static gpointer growPart_thread(gpointer b_pulse) { /* do work */ growPart(); *b_pulse = FALSE; g_thread_exit( GINT_TO_POINTER( 1 ) ); } I would do the passing of control values via a structure to avoid the use of globals, but this should work for you. James, This is an e-mail from General Dynamics Land Systems. It is for the intended recipient only and may contain confidential and privileged information. No one else may read, print, store, copy, forward or act in reliance on it or its attachments. If you are not the intended recipient, please return this message to the sender and delete the message and any attachments from your computer. Your cooperation is appreciated. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
timeout function not called
I'm still muddling my way through my first GTK application (and I'm a relative newbie on all software matters). I have the following in one of my callbacks: timer = g_timout_add(50, (GSourceFunc) progress_update, (gpointer)progressbar); pid = fork( ); if (pid == 0) { growPart ( ); exit(0); } ret = wait(NULL); g_source_remove(timer); --- where progress_update is: static gboolean progress_update (gpointer progressbar) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); return true; } I was hoping that this would mean that the progress bar would pulse while growPart() was running, but instead it waits until after (is this because control hasn't been returned to gtk_main yet?) at which point it is removed. If I take out the g_source_remove it runs beautifullybut only after growPart has completed. How can I get around this? Thanks so much This is an e-mail from General Dynamics Land Systems. It is for the intended recipient only and may contain confidential and privileged information. No one else may read, print, store, copy, forward or act in reliance on it or its attachments. If you are not the intended recipient, please return this message to the sender and delete the message and any attachments from your computer. Your cooperation is appreciated. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: timeout function not called
Thanks, I have tried to add gtk_main_iteration in various places but it still won't work. Also I just want the bar to pulse while growPart is running - just to show something is happening. After grow Part is finished, I want to run the ext2resize utility and have a progress bar pulsing through that also. I figure whatever solution I get for the growPart can then be applied to ext2resize. Thanks control hasn't been returned to gtk_main yet?) at which point it is removed. If I take out the g_source_remove it runs beautifullybut only after growPart has completed. How can I get around this? Thanks so much Hi, I think you can use gtk_main_iteration() to tell gtk handle some of the pending events. However, unless the progress of the bar is not related to the computation in growPart, wouldn't it be better to update the progress bar status from the inside of the growPart function? Cheers ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list This is an e-mail from General Dynamics Land Systems. It is for the intended recipient only and may contain confidential and privileged information. No one else may read, print, store, copy, forward or act in reliance on it or its attachments. If you are not the intended recipient, please return this message to the sender and delete the message and any attachments from your computer. Your cooperation is appreciated. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list