[Glade-devel] callbacks



Al,
    You might be interested in trying a library called libglade.  When 
you use libglade all you need is
the xml (.glade) file generated by glade when you click the save 
button.  A typical libglade
application might look like:
static void callback(GtkWidget, GladeXML *xml );
int main( int argc, char **argv )
{
  GladeXML *xml;
  gtk_init(&argc, &argv );
  xml = glade_xml_new( "mygladefile.glade", 0, 0);
  glade_xml_signal_connect_data( xml, "mysignal-name-from-glade",
                                                    G_CALLBACK( callback 
), xml );
  gtk_main();
    return 0;
}
void callback(GtkWidget, GladeXML *xml )
{
// get the progress bar
   GtkWidget *progressbar = glade_xml_get_widget( xml, "progressbar" );
  // do what ever you want with the progress bar widget
}

libglade api: http://developer.gnome.org/doc/API/2.0/libglade/index.html

todd

Al wrote:

Hi at all,

i followed a discussion about the callbacks with glade in witch people speaks 
about the possibility to change the inteface.c file, but i learned from the 
glade tutorial... 
http://www.kplug.org/glade_tutorial/glade2_tutorial/quick_tour2.html

...that i should not change that file, because it will be overwitten every 
time glade builds the code of my application.

I need a way to exchange pointers to widget between different callbacks 
function. Is there a way without declaring a global variable?

For example my actual callbacks.c is like this:

/*Initialized in main.c with the pointer to the main window*/
extern GtkWidget *Main;
[...]

void
on_connectFileMenuButton_activate      (GtkMenuItem     *menuitem,
                                       gpointer         user_data)
{
 GtkWidget *progress=lookup_widget(Main,"progressbar");
 short int i;
 gdouble fraction;
 GtkWidget *connecting=create_Connecting();
 for(i=0;i<=100;i++)
   {
     fraction=((gdouble)i)/100;
     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress),fraction);
     sleep(0.9);
   }
 gtk_widget_show(connecting);

}


in this case i cannot obtain a pointer to the progressbar placed into the main 
window, because the menuitem is a little window that contains: "File, Edit" 
and so on... (therefore an approach like:   
lookup_widget(menuitem,"progressbar"), or 
lookup_widget(gtk_widget_get_toplevel(menuitem),"progressbar") does not 
work).
My problem will be addressed if i could pass data into 
user_data variable, but i don't know how to do that without changing the 
interface.c
Can someone help me?

Thanks 

Alberto

_______________________________________________
Glade-devel maillist  -  Glade-devel lists ximian com
http://lists.ximian.com/mailman/listinfo/glade-devel
 







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