Re: [gtk-list] gtk_widget_show() outside gtk_main()
- From: Erik Mouw <J A K Mouw its tudelft nl>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] gtk_widget_show() outside gtk_main()
- Date: Thu, 29 Oct 98 18:47:34 +0100
On Thu, 29 Oct 1998 12:55:08 -0400 (AST), gtk-list@redhat.com (Aaron Campbell) wrote:
> I have a button widget in an application that is connected to a callback
> function which, among other things, starts a separate process via a
> standard fork() + execl() + waitpid() procedure. I want to display a note
> via a label notifying the user that files are transferring and to please
> wait.
waitpid() blocks your application, unless called with the WNOHANG option.
As long as your application blocks, the user interface will not be
updated.
> The button is connected to this callback with the gtk_signal_connect()
> function. The first part of the function just does some checking and
> setup. Right after that I put in my label and issued a
> gtk_widget_show(label). Unfortunately it doesn't update the display until
> the separate process completes (ie after the waitpid). I also tried
> putting the labelling part in a separate function that is called first,
> then another function to start the transfer. That also didn't work.
>
> I'm assuming the widget displays are only updated inside gtk_main()? Does
> anyone have any suggestions? I also tried gtk_widget_realize(), that
> didn't work either, obviously I don't yet understand what that feature is
> for. :)
A widget is indeed shown if its events are handled in gtk_main(). Try this
(from the GTK FAQ):
while (gtk_events_pending())
gtk_main_iteration();
after you gtk_widget_show()-ed your widget.
The correct loop will be something like:
pid_t pid;
int status;
int stop = 0;
gtk_widget_show(mywidget);
pid = fork(); /* some ancient systems prefer vfork() */
/* default fork + exec code */
/* child code */
/* parent does this: */
while(stop == 0)
{
if(waitpid(pid, &status, WNOHANG) != 0)
stop = 1;
while (gtk_events_pending())
gtk_main_iteration();
}
gtk_widget_hide(mywidget);
/* evaluate child status */
Note: I have not tested this code. Have a look at the book "Advanced
programming in the UNIX environment" by Richard Stevens for more
information on process control (or just read the friendly manual).
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2785859 Fax: +31-15-2781843 Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]