Re: Consulta GTK+



On 17/08/05, Juan Carlos Inostroza <jci codemonkey cl> wrote:
> On Wed, 2005-08-17 at 17:15 -0400, Mario Gonzalez wrote:
> > gboolean button_clicked( GtkWidget *windget, gpointer *data)
> > {
> >         g_print ("Button clicked \n");
> >         return TRUE;
> > }
> >  [.....]
> >         button1         = gtk_button_new_from_stock(GTK_STOCK_OK);
> >         g_signal_connect(G_OBJECT(button1), "clicked",
> >                         G_CALLBACK(button_clicked), NULL);
> >         button2         = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
> >         g_signal_connect(G_OBJECT(button2), "clicked",
> >                         G_CALLBACK(button_clicked), NULL);
> >        Entonces, como saber si fue el button1 o el button2 el cual
> > activo el "clicked"??
> 
> Pregunta por el widget *widget que pasas al callback :)
> (nota : antes, ponle un nombre al widget y de ahi puedes preguntar por
> el).
> un pequeño codigo de ejemplo
>
>         button1         = gtk_button_new_from_stock(GTK_STOCK_OK);
>         g_signal_connect(G_OBJECT(button1), "clicked",
>                         G_CALLBACK(button_clicked), NULL);
>         gtk_widget_set_name(button1, "boton1");
> 
>         button2         = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
>         g_signal_connect(G_OBJECT(button2), "clicked",
>                         G_CALLBACK(button_clicked), NULL);
>         gtk_widget_set_name(button2, "boton2");
> 
  Ok gracias, eso es lo que esperaba!!   Saludos igualmente, nos vemos!

> Y luego, en la funcion de callback 
> static void
> button_clicked(GtkWidget * widget,
>                 gpointer data)
> {
>         printf("Boton : %s\n", gtk_widget_get_name(widget));
> }
> 
> Nota :
> "clicked"   void        user_function      (GtkButton *button,
>                                             gpointer user_data);
> 
> la señal "clicked" acepta una funcion de tipo void solamente.
> 
  mmhh, la funcion que retorna un gboolean lo saque del tutorial de
gtk.org pero quizas esta demas, voy a probar. En ese caso se podria
reemplazar el gboolean por gpointer verdad??



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