Re: [gtk-list] Re: Set Label Text



Hello if anybody would like to see how to change a label text for some
seconds here is now the code and thanks again for the help.

typedef struct
  {
    GtkLabel *label;
    gchar *text;
  }
TextLabel;

TextLabel *
create_textlabel (GtkLabel * label, gchar * text)
{
  TextLabel *tl;
  tl = (TextLabel *) g_malloc0 (sizeof (TextLabel));
  tl->label =  label ;
  tl->text = g_strdup(text);
  return tl;
}

void 
free_textlabel (TextLabel * tl)
{
  if (tl->text)
    g_free (tl->text);
  if (tl)
    g_free (tl);
}

static gint
redraw_again (gpointer label)
{
  TextLabel *tl=(TextLabel *)label;
  if (time_id)
    gtk_timeout_remove (time_id);
  gtk_label_set_text (tl->label, tl->text);
  gtk_widget_show (GTK_WIDGET (tl->label));
  free_textlabel(tl); 
  return TRUE;
}

void 
ndisplay_text (GtkWidget * label, gchar * text, guint sec)
{
  gchar *tmpstring;
  gchar *copystring;
  TextLabel *textlabel;
  gtk_label_get (GTK_LABEL (label), &tmpstring);
  copystring = g_strdup (tmpstring);
  textlabel = create_textlabel (GTK_LABEL (label), copystring);
  gtk_label_set (GTK_LABEL (label), text);
  time_id = gtk_timeout_add (1000 * sec, redraw_again, (gpointer) textlabel);
  g_free (copystring);
}

You can use this function with the following statement:
ndisplay_text(GtkLabel * label,gchar * text,guint sec);

Have fun
Andreas Scherf
+-------------------------------------------+
I EMail   : scherfa@fh-trier.de             I  
I Homepage: http://www.fh-trier.de/~scherfa I
+-------------------------------------------+




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