GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

image from file

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
alen121
Familiar Face


Joined: 28 Sep 2007
Posts: 23

PostPosted: Sat Mar 29, 2008 3:29 pm    Post subject: image from file Reply with quote

look at the following codes
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#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;
}


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 ?
Back to top
alen121
Familiar Face


Joined: 28 Sep 2007
Posts: 23

PostPosted: Sat Mar 29, 2008 8:54 pm    Post subject: Reply with quote

gtk_image_set_from_file not work until loop is end!!and solution?
Back to top
Wolfgang
Familiar Face


Joined: 05 Feb 2008
Posts: 37

PostPosted: Mon Mar 31, 2008 4:01 am    Post subject: Reply with quote

try to use g_add_timeout_add() or another timer function
Back to top
alen121
Familiar Face


Joined: 28 Sep 2007
Posts: 23

PostPosted: Mon Mar 31, 2008 1:33 pm    Post subject: Reply with quote

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 ?
Back to top
Wolfgang
Familiar Face


Joined: 05 Feb 2008
Posts: 37

PostPosted: Tue Apr 01, 2008 5:10 am    Post subject: Reply with quote

Until handler returns control to main loop, no one event will be processed. Including repaint events!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP