Re: How to know the name of Widgets ?



On Wed, 2001-09-19 at 03:04, Flávio Alberto Lopes Soares wrote:
> Hello again !
> 
> I need to know how to discover the name of the windows, I know that
> gtk_widget_get_name catch the type of widget ex: GtkWindow, GtkButton,
> etc, but now I need to view the name of my widget, ex : window_ihm is a
> window, window_senha is other widget window, etc.

Hmm...if it isn't the type names you want, I assume that it is the
variable names, and these aren't immediately available, but you can use
gtk_object_set/get_data to associate names with objects, as in the
attached program.

	/mailund

-- 
The philosophy exam was a piece of cake -- which was a bit of a
surprise, actually, because I was expecting some questions on a sheet
of paper.
#include <gtk/gtk.h>


static void
button_clicked (GtkWidget *button)
{
  const char *name = gtk_object_get_data (GTK_OBJECT (button), "name");
  g_print ("button \"%s\" was pressed\n", name);
}


int
main (int argc, char *argv[])
{
  GtkWidget *win;
  GtkWidget *vbox;
  GtkWidget *button1, *button2;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  vbox = gtk_vbox_new (TRUE, 0);
  gtk_container_add (GTK_CONTAINER (win), vbox);

  button1 = gtk_button_new_with_label ("Button 1");
  gtk_box_pack_start (GTK_BOX (vbox), button1, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button1), "clicked",
		      GTK_SIGNAL_FUNC (button_clicked), NULL);
  // setting name
  gtk_object_set_data (GTK_OBJECT(button1), "name", "button1");

  button2 = gtk_button_new_with_label ("Button 2");
  gtk_box_pack_start (GTK_BOX (vbox), button2, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button2), "clicked",
		      GTK_SIGNAL_FUNC (button_clicked), NULL);
  // setting name
  gtk_object_set_data (GTK_OBJECT(button2), "name", "button2");

  gtk_widget_show_all (win);

  gtk_main ();

  return 0;
}


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