Re: [gtk-list] Buttons and Windows.



>>>>> "S" == Sean Cody <umcodysw@cc.UManitoba.CA> writes:

 S> Q1 - How would one change a button's label during run-time?

You can change a label with gtk_label_set_text.  See attached program.

 S> Q2 - How can I find out what window a button came from (from
 S> OnClickEvent) so I can destroy that window?  I don't want to make
 S> the window global as it's created at run time and hopefully
 S> disposed of then too. :)

I'm not quite sure about your question here, but see the attached
program for two possible solutions.

        /mailund

===File ~/tmp/foo.c=========================================
#include <gtk/gtk.h>

static void
set_label (GtkWidget *dummy, GtkWidget *label)
{
  static gboolean foo = TRUE;
  g_assert (GTK_IS_LABEL (label));
  if (foo) {
    gtk_label_set_text (GTK_LABEL (label), "BAR");
    foo = FALSE;
  } else {
    gtk_label_set_text (GTK_LABEL (label), "FOO");
    foo = TRUE;
  }
}

static void
destroy1 (GtkWidget *dummy, GtkWidget *win)
{
  g_assert (GTK_IS_WINDOW (win));
  gtk_widget_destroy (win);
}

static void
destroy2 (GtkWidget *button)
{
  GtkWidget *win;
  g_assert (GTK_IS_BUTTON (button));
  win = gtk_widget_get_toplevel (button);
  gtk_widget_destroy (win);
}


int
main (int argc, char *argv[])
{
  GtkWidget *win;
  GtkWidget *box;
  GtkWidget *label;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  box = gtk_vbox_new (TRUE, 5);
  label = gtk_label_new ("FOO");
  button = gtk_button_new ();

  gtk_container_add (GTK_CONTAINER (button), label);
  gtk_box_pack_start_defaults (GTK_BOX (box), button);
  gtk_container_add (GTK_CONTAINER (win), box);

  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (set_label),
		      (gpointer)label);

  button = gtk_button_new_with_label ("DESTROY1");
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (destroy1),
		      (gpointer)win);
  gtk_box_pack_start_defaults (GTK_BOX (box), button);

  button = gtk_button_new_with_label ("DESTROY2");
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (destroy2), NULL);
  gtk_box_pack_start_defaults (GTK_BOX (box), button);

  gtk_widget_show_all (win);

  gtk_main ();

  return 0;
}
============================================================



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