Re: Changing a Label Presentation



The reason that the label isn't drawn is that the graphics context
isn't flushed. This may be done simply by calling gtk_flush(). But
there is a more fundemental problem with your program, and it has 
to do with the concept of event driven programming. In your callback
you are doing an operation which is taking a very long time. This
is basically a no-no, as you are taking away the control from the
gtk_main() loop. What you should do in such a case is to fork off
a child that runs the backup process in the background. (If you want
to you can read stdout from the standard output and put it e.g. in
a text view widget). When the child process is terminated it sends
to its parent a SIG_CHILD unix signal. By catching this unix signal
you can figure out that your child process is finished and change
the value of your label.

I hope this helps.

Regards,
Dov

On Sun, May 19, 2002 at 02:14:20AM -0400, Ruben I Safir wrote:
> Hello
> 
> I'm trying to write a program which changes a label from a callback and it's not working.
> 
> rmbackup.c
> 
> #include <stdio.h>
> #include "tarlib.h"
> #include "backprog.h"
> 
> int main(int argc, char **argv){
> 	struct s1 window1;
> 	gtk_init(&argc, &argv);
> 	window1 = screen1();
> 	gtk_main();
> 	exit(0);
> }
> 
> backprog.c
> 
> struct s1 maketoggles(){
> 	static struct s1 handle;
> 	GtkWidget *button;
> 	GtkWidget *vbox;
> 	GtkWidget *label;
> 	
> 	vbox = gtk_vbox_new(TRUE, 0);
> 	
> 	label = gtk_label_new("Choose an Option");
> 	
> 	gtk_widget_show(label);
> 	
> 	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE,3);
> 	
> 	button = gtk_toggle_button_new_with_label("Create Backup");
> 	gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, FALSE, 0);
> 	gtk_widget_show(button);
> 	gtk_signal_connect(GTK_OBJECT(button), "clicked",
> 			GTK_SIGNAL_FUNC(startbackup), 
> 			label );
> 
> ........
> 
> void startbackup( GtkWidget *widget, GtkWidget *lab){
> 	gint ret;
> 	gtk_label_set_text(GTK_LABEL(lab), "CREATING BACKUP");  <-----Not changing
> 	ret = createbackup();
> 	g_print("%d",ret);
> 	g_print("\n");
> 	gtk_label_set_text(GTK_LABEL(lab), "Choose an Option");
> 	
> }
> 
> 
> -- 
> __________________________
> 
> Brooklyn Linux Solutions
> __________________________
> http://www.mrbrklyn.com - Consulting
> http://www.brooklynonline.com - For the love of Brooklyn
> http://www.nylxs.com - Leadership Development in Free Software
> http://www.nyfairuse.org - The foundation of Democracy
> http://www2.mrbrklyn.com/resources - Unpublished Archive or stories and articles from around the net
> http://www2.mrbrklyn.com/mp3/dr.mp3 - Imagine my surprise when I saw you...
> http://www2.mrbrklyn.com/downtown.html - See the New Downtown Brooklyn....
> 
> 1-718-382-5752
> 
> 
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list

-- 
                                                        ___   ___
                                                      /  o  \   o \
Dov Grobgeld                                         ( o  o  ) o   |
The Weizmann Institute of Science, Israel             \  o  /o  o /
"Where the tree of wisdom carries oranges"              | |   | |
                                                       _| |_ _| |_
 



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