GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 5:14 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: image from file
PostPosted: Sat Mar 29, 2008 3:29 pm 
Offline
Familiar Face

Joined: Fri Sep 28, 2007 10:59 am
Posts: 46
look at the following codes
[code=]
#include <gtk/gtk.h>
#include <unistd.h>

GtkWidget *image[5];

void click_button()
{
for (int j=0 ; j<5 ; j++)
{
sleep(2);
gtk_image_set_from_file(GTK_IMAGE(image[j]),"images3.png");
}
}

int main(int argc , char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window;
GtkWidget *vbox ;
GtkWidget *togglebutton[5];
GtkWidget *button=gtk_button_new_with_label("start");

window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window,300,300);
vbox=gtk_vbox_new(TRUE,0);
gtk_container_add(GTK_CONTAINER(window),vbox);
for(int i=0 ; i<5 ; i++)
{
togglebutton[i]=gtk_toggle_button_new();
gtk_box_pack_start_defaults(GTK_BOX(vbox),togglebutton[i]);
image[i]=gtk_image_new();
gtk_container_add(GTK_CONTAINER(togglebutton[i]),image[i]);
}
gtk_box_pack_start_defaults(GTK_BOX(vbox),button);
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(click_button),NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[/code]

I want one pic to be in the image widget in each run time of for loop in click_button function . but at the run time , for loop
do not run 5 times and do not finish , the pictures dont place in the image widgets . what should I do to have 1 pic in the image widget at each loop run ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 29, 2008 8:54 pm 
Offline
Familiar Face

Joined: Fri Sep 28, 2007 10:59 am
Posts: 46
gtk_image_set_from_file not work until loop is end!!and solution?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2008 4:01 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
try to use g_add_timeout_add() or another timer function


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2008 1:33 pm 
Offline
Familiar Face

Joined: Fri Sep 28, 2007 10:59 am
Posts: 46
click_button function should be run and trend of program running return in to main function and reach to gtk_main() function in order to display the pictures . it dosent relate to sleep func . what should I do to slove this problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 5:10 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
Until handler returns control to main loop, no one event will be processed. Including repaint events!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group