Re: [gtk-list] Re: closing windows



[...]
>> > gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
>> >       GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer)window,
>> >       NULL);
>> >
>> > This will automatically destroy the window when you click on the button.
>>
>> And what will be the difference with:
>>
>>  gtk_signal_connect(GTK_OBJECT(button), "clicked",
>>        GTK_SIGNAL_FUNC(gtk_widget_hide), window);
[...]
>The same difference as beetwen "hide" and "destroy". With "hide", the window
>still exists and can be shown again with "show".  With "destroy", the window no
>longer exists, if you want it again, you have to re-create it.
[...]

In addition, the second piece of code you posted above will cause the button 
to be hidden, not the window, which I don't think is what you want.

A signal handler is called like this:

	signal_handler(object, userdata);

So in the above example, when you press the button this will happen:

	gtk_widget_hide(button, window)

Since gtk_widget_hide only takes one parameter, window will be ignored and 
it'll take button as the parameter.

You want gtk_signal_connect_object, which allows you to send a signal to an 
object other than the one that generated the event. In the very top-most piece 
of code, this is what happens:

	gtk_widget_destroy(window, NULL)

...which will have the desired effect.

...oh, yes. hide vs. destroy. If you hide the dialogue, you have to remember 
not to create it again the next time you want to display it, or you'll get a 
memory leak. This usually involves a global variable or something. I find that 
with simple things like About... dialogue boxes it's easier to just attach the 
gtk_widget_destroy signal to the OK button in Glade and do:

{
	/* Create dialogue box */

	gtk_widget_show(create_about_dialogue());

	/* All done! */
}

I know need to take no further action, it'll all take care of itself, 
including destroying itself on demand.

PS. Glade rules.

-- 
+- David Given ------------McQ-+ 
|  Work: dg@tao.co.uk          | All law is codified revenge.        
|  Play: dgiven@iname.com      | 
+- http://wiredsoc.ml.org/~dg -+ 




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