Re: [gtk-list] Re: Update progressbar without gtk_timeout_add



Owen Taylor wrote:
> 
> hihihi <hihihi@casema.net> writes:
> 
> > Is it possible to update a progressbar without using a gtk_timeout_add
> > ??
> > I want to update a progressbar when a spinbutton is changed.
> 
> FAQ question 5.11. (On www.gtk.org or in the GTK+ distribution)

It says :

while (gtk_events_pending())
  gtk_main_iteration();

But it still does not work for me.

I have tried the 'while ...' line in several places in
progressbar_da1(...) 
But no luck :-))

I have made a bar-minimum prog of my program.
See below..

Can anyone tell me where i should place the lines ??


#include <gtk/gtk.h>

  GtkWidget *window;
  GtkWidget *pbar;
  GtkWidget *fixed;
  int timer;
  GtkWidget *label;
  GtkWidget *label_da1;
  GtkWidget *spinbutton_da1;

gint progressbar_da1(gpointer data)
{
  gint new_val;
  gchar new_val_char[32];
  GtkAdjustment *adj;
  GtkSpinButton *spin;

  spin=GTK_SPIN_BUTTON(spinbutton_da1);
  new_val=gtk_spin_button_get_value_as_int(spin);

  sprintf(new_val_char,"%i",new_val);
  gtk_label_set_text(GTK_LABEL(label_da1),new_val_char);

  while(gtk_events_pending())
     gtk_main_iteration();

  adj=GTK_PROGRESS(data)->adjustment;
  gtk_progress_set_value(GTK_PROGRESS(data),new_val);

  return(TRUE);
}


int main(int argc, char *argv[])
{

  GtkWidget *button;
  GtkAdjustment *adj;

  gtk_init(&argc,&argv);
  window=gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_window_set_policy(GTK_WINDOW(window),FALSE,FALSE,TRUE);

  gtk_window_set_title(GTK_WINDOW(window),"version 0.08");

  gtk_signal_connect(GTK_OBJECT(window),"destroy",
    GTK_SIGNAL_FUNC(gtk_main_quit),NULL);

  gtk_container_set_border_width(GTK_CONTAINER(window),10);

  fixed=gtk_fixed_new();
  gtk_container_add(GTK_CONTAINER(window),fixed);
  gtk_widget_show(fixed);

  /* Add progressbars with spinbutton for DA1 and DAC 1-8 */

  label=gtk_label_new("DA1=");
  gtk_fixed_put(GTK_FIXED(fixed),label,180,122);
  gtk_widget_show(label);

  label_da1=gtk_label_new("");
  gtk_fixed_put(GTK_FIXED(fixed),label_da1,227,122);
  gtk_widget_show(label_da1);

  adj=(GtkAdjustment *) gtk_adjustment_new(0,0,255,0,0,0);
  pbar=gtk_progress_bar_new_with_adjustment(adj);
  gtk_progress_set_show_text(GTK_PROGRESS(pbar),TRUE);
  gtk_progress_set_format_string(GTK_PROGRESS(pbar),"%v [%l-%u]");
  gtk_fixed_put(GTK_FIXED(fixed),pbar,250,120);
  gtk_widget_show(pbar);

  adj=(GtkAdjustment *) gtk_adjustment_new(0,0,255,1,1,0);
  spinbutton_da1=gtk_spin_button_new(adj,0,0);
  gtk_signal_connect(GTK_OBJECT(adj),"value_changed",
          GTK_SIGNAL_FUNC(progressbar_da1),
          (gpointer) spinbutton_da1);
  gtk_fixed_put(GTK_FIXED(fixed),spinbutton_da1,410,120);
  gtk_widget_show(spinbutton_da1);

/*  timer=gtk_timeout_add(150,progressbar_da1,pbar);*/

  /* Add buttons */

  button=gtk_button_new_with_label(" Quit ");
  gtk_signal_connect_object(GTK_OBJECT(button),"clicked",
    GTK_SIGNAL_FUNC(gtk_widget_destroy),
    GTK_OBJECT(window));
  gtk_fixed_put(GTK_FIXED(fixed),button,10,480);
  gtk_widget_show(button);

  gtk_widget_show(window);
  gtk_main();
  return(0);

}
 



-- 
My webserver http://hihihi.penguinpowered.com
My home page at my provider http://www.casema.net/~hihihi



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