 |
GTK+ Forums Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
|
|
|
| Author |
Message |
|
|
pablodecastillo
Joined: 11 Jan 2010 Posts: 4
|
Posted: Mon Jan 11, 2010 6:46 pm Post subject: Progressbar, |
|
|
Hello, i am trying to display a simple progressbar, doing 10 iterations but the progressbar just shown the last iteration, Anybody known what am i loosing?
Advanced thanks
Pablo
#include <time.h>
#include <iostream>
#include <gtk/gtk.h>
using namespace std;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int main( int argc,
char *argv[])
{
GtkWidget *align;
GtkAdjustment *adj;
GtkWidget *window;
GtkWidget *bar;
double myfrac;
int i;
GtkWidget *vbox;
gtk_init (&argc, &argv);
/* Allocate memory for the data that is passwd to the callbacks */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, TRUE);
gtk_window_set_title (GTK_WINDOW (window), "GtkProgressBar");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
vbox = gtk_vbox_new (FALSE, 5);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show(vbox);
/* Create a centering alignment object */
align = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);
gtk_widget_show(align);
/* Create a GtkAdjusment object to hold the range of the
* progress bar */
adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 100, 0, 0, 0);
/* Create the GtkProgressBar using the adjustment */
bar = gtk_progress_bar_new ();
// pbar = gtk_progress_bar_new_with_adjustment (adj);
gtk_container_add (GTK_CONTAINER (align), bar);
gtk_widget_show(bar);
// myfrac=0.5;
/* Add a timer callback to update the value of the progress bar */
//pdata->timer = gtk_timeout_add (100, progress_timeout, pdata->pbar);
//gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar), myfrac);
//gtk_progress_set_value (GTK_PROGRESS(pbar), 0.5);
int ncont=0;
for (i=1; i<=10; i++){
ncont++;
myfrac = double(i)/double(10);
wait(1);
cout << "llama la barra " << myfrac<<endl;
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar), myfrac);
}
gtk_widget_show (window);
gtk_main ();
return(0);
}
/* example-end */ |
|
| Back to top |
|
 |
dreblen Never Seen the Sunlight
Joined: 14 Jun 2007 Posts: 936 Location: Falun, WI USA
|
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group CodeBB 1.0 Beta 2
|