[Glade-users] Window availability and the need to put information into another window



On Mon, 2004-11-15 at 11:37, Louis Bouchard wrote:
Hello all,

I am running into a problem regarding the use of different windows.

I have 2 windows, window 1 and window 2. A call from pressing a button 
opens window2. When I press a button in window 2, there is an instance 
where I need to put data into the fields of window 1. When I try to do a 
lookup of window 1 in the callback from window 2 however, the lookup 
cannot find window 1.

Is there a way around this. I tried messing with window focus but to no 
avail.

The FAQ covers this:

4.6 How do I get a pointer to a widget in another window?
 
You need to keep track of pointers to all your toplevel windows.
For simple applications you can just use global variables to store these
pointers.
 
For more complicated applications you can use the gtk_object_set_data()
and
related functions to store a pointer to one window inside another
window.
For example, if you want to create a dialog which needs to access
widgets in
the main window you can do this:
 
  dialog = create_dialog1 ();  /* Call the function generated by Glade.
*/
  gtk_object_set_data (GTK_OBJECT (dialog), "main_window", main_window);
 
Then when you need to access the main window from within the dialog
code,
you can do this:
 
  main_window = gtk_object_get_data (GTK_OBJECT (dialog),
"main_window");
 
NOTE: You need to be careful to ensure that the pointer is always valid.
If the window being pointed to is destroyed, make sure you no longer use
the
pointer to it or your application may crash.



Damon






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