LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2008, 06:50 AM   #1
scorpion77
Member
 
Registered: Sep 2003
Distribution: Slackware64 current
Posts: 95

Rep: Reputation: 15
[GTK+] Problem with images loaded in sequence


Hello everyone,
I have a problem with a GTK+ program that I am writing. I thought to put a progress bar that so many seconds increases a little. So I used ten images .png (progress1.png, progress2.png, etc.) indicating the status of progress. The problem is that if I create a window with the first image, if I put a function that blocks the implementation of the program of 5 seconds, the program draws the window after 5 seconds. I do not know if I make myself clear.
Example:

in the window appears progress1.png

XX

after 5 seconds becomes so (progress2.png)

XXXX

after another 5 seconds (progress3.png)

XXXXXX

and so forth. For each step, the image with the progress bar is overwritten by another. At least should do so, instead draws only the last, progress10.png, waiting for 45 seconds (9 sleep of 5 seconds each).

This is the portion of code that places images with bar progression:


Fix = gtk_fixed_new ();
image = gtk_image_new_from_file ( "progress1.png");
Gtk_fixed_put (fix, image, 230, 340);
Gtk_container_add (GTK_CONTAINER (win), fix);
Gtk_widget_show_all (Win);

System ( "sleep 5s");

Gtk_container_remove (GTK_CONTAINER (win), fix);
Fix = gtk_fixed_new ();
image = gtk_image_new_from_file ( "progress2.png");
Gtk_fixed_put (fix, image, 230, 340);
Gtk_container_add (GTK_CONTAINER (win), fix);
Gtk_widget_show_all (Win);

System ( "sleep 5s");

Gtk_container_remove (GTK_CONTAINER (win), fix);
Fix = gtk_fixed_new ();
image = gtk_image_new_from_file ( "progress3.png");
Gtk_fixed_put (fix, image, 230, 340);
Gtk_container_add (GTK_CONTAINER (win), fix);
Gtk_widget_show_all (Win);


First I place the beginning progress image, then I remove the container and put the image of progress No. 2 and so on until 10.
If I want that between a picture and another pass 5 seconds, I thought to use the bash command "sleep 5s." The same thing happens if put a for cycle that take few seconds. But this does not appear immediately the window. You'll see the window after 5 seconds, making appear progress10.png, bypassing progress1.png and the other images. So I can not make the ladder progress1.png - 5 seconds - progress2.png - 5 seconds - progress3.png, etc.
Is it possible drawing the window, wait time with the window and objects appeared before remaking the container with new objects inside?

Thanks in advance for helping me.

Scorpion77
 
Old 06-08-2008, 04:50 PM   #2
scorpion77
Member
 
Registered: Sep 2003
Distribution: Slackware64 current
Posts: 95

Original Poster
Rep: Reputation: 15
I solved with function g_timeout_add(). But I noticed a strange behavior: if I use g_timeout_add(240, time_handler, NULL), my function (time_handler) is called every 240 milliseconds, and it's ok. But after 242 seconds, the timeout function expires. If I set an interval of 100 milliseconds, after 102 seconds the timeout is destroyed and will not be called again. If I set an interval of 50 milliseconds, after 52 seconds the timeout is destroyed and will not be called again, and so on. It seems that timeout is destroyed after interval time transformed into seconds + 2.

Why this happens?
 
Old 06-09-2008, 02:37 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
From http://library.gnome.org/devel/glib/...#g-timeout-add
Quote:
The function is called repeatedly until it returns FALSE, at which point the timeout is automatically destroyed and the function will not be called again.
Maybe you are returning FALSE?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gtk problem: gkrellm images got bigger? [wierd] broxys Linux - Software 3 05-06-2011 03:49 AM
How do I check sequence of and re-arrange modules loaded at startup? SP7 Linux - Software 5 05-24-2008 01:41 AM
C++/SDL: Images moving too slowly. Images loaded once, etc. Why? RHLinuxGUY Programming 2 05-26-2007 05:11 PM
gtk and C, draw a grid and place images leosgb Programming 1 04-12-2006 06:35 PM
Corrupt Images when loaded through FTP tumana Linux - Newbie 10 09-08-2004 04:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration