Re: [gtk-list] Refreshing



On Thu, 23 Apr 1998, Harjinder Dhudwar wrote:

> I am using gtk to display the output of five files. The values in these
> files are constantly changing, so the labels in the window need to be
> refreshed every 5(ish) seconds. I am using gtk_timer to call a function
> which updates the values, by deleting the labels and creating new labels.
> Without the timer, the screen is refreshed successfully everytime a button
> is clicked. But when using a timer, the labels are deleted, but the new
> labels do not appear. The function is initialised when a button is clicked,
> but it seems until the button returns to its original state the window
> will not be refreshed.

hm, you should use gtk_label_set instead of destroying/recreating the
labels, like so:

#include "gtk/gtk.h"

static GtkWidget *label;
void
update ()
{
  static guint i = 0;
  gchar buffer[32];

  sprintf (buffer, "tick %u", i++);

  gtk_label_set (GTK_LABEL (label), buffer);
}

int
main (int argc, char **argv)
{
  GtkWidget *window;

  gtk_init(&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  label = gtk_label_new ("init");
  gtk_container_add (GTK_CONTAINER (window), label);
  gtk_widget_show (label);
  gtk_widget_show (window);

  gtk_timeout_add (5 * 1000, update, NULL);

  gtk_main ();

  return 0;
}



> 
> Any clues? 
> 
> Thanks in advanced.
> 
> Harjinder Dhudwar
> h.dhudwar@curvalue.com 
> 

---
ciaoTJ



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