Dialog hide/destroy

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Dialog hide/destroy

Juan José 'Peco' San Martín
Hello all.

In order to understand how the window widgets works, I created a minor
application.
One windows with two buttons in order to hide or show another window.
All is correct! :-)

Now, I'm trying to do the same but using a main window with Menu widget
that calls a new "dialog" window. All seems to be ok, but if I close
dialog window (delete_event) and try to re-open again (clicking on the
menu of the main one) I get:

Gtk-CRITICAL **: gtk_container_foreach: assertion `GTK_IS_CONTAINER
(container)' failed at ...

when I try to show the dialog again.

BTW, what it's the different between of using "hide"/"show" or directly
"destroy" to control de windows behaviour?. It is always recommended one
way to do it?. Is it faster vs memory-lesser?

Thanks!
Peco

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Dialog hide/destroy

muppet-6

On Jul 4, 2005, at 10:40 AM, Juan José 'Peco' San Martín wrote:

> Now, I'm trying to do the same but using a main window with Menu  
> widget
> that calls a new "dialog" window. All seems to be ok, but if I close
> dialog window (delete_event) and try to re-open again (clicking on the
> menu of the main one) I get:
>
> Gtk-CRITICAL **: gtk_container_foreach: assertion `GTK_IS_CONTAINER
> (container)' failed at ...
>
> when I try to show the dialog again.

This typically means that you're trying to call ->show on a dead  
widget.  In your delete-event handler, what are you doing?  If your  
handler returns FALSE, the default handler will destroy the window;  
to hide from delete event, you must set up your handler like this:

   $window->signal_connect (delete_event => sub {
         $_[0]->hide;  # hide the window
         return TRUE;  # tell gtk+ that we handled this event, and
                        # that it should *not* destroy the window.
   });



> BTW, what it's the different between of using "hide"/"show" or  
> directly
> "destroy" to control de windows behaviour?. It is always  
> recommended one
> way to do it?. Is it faster vs memory-lesser?

gtk_widget_hide() unrealizes the widget, which takes it off of the  
screen, but does not kill it.  gtk_widget_destroy() hides and then  
renders unusable the widget; the destroy is explicit in order to  
break reference count cycles.

Whether you reuse or recreate widgets is entirely up to you and the  
architecture of your application.  If it takes a lot of work to  
create a widget, or it should retain state between showings, then  
it's likely a good idea to use hide instead of destroy.  Destroying  
the widget will obviously be the more memory-friendly approach.  
There is no "best" way,  in my experience; the answer is, "try both  
and see which better satisfies your goals".



--
To me, "hajime" means "the man standing opposite you is about to hit  
you with a stick".
   -- Ian Malpass, speaking of the Japanese word for "the beginning"

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Dialog hide/destroy

Juan José 'Peco' San Martín

> This typically means that you're trying to call ->show on a dead  
> widget.  In your delete-event handler, what are you doing?  If your  
> handler returns FALSE, the default handler will destroy the window;  
> to hide from delete event, you must set up your handler like this:
>
>    $window->signal_connect (delete_event => sub {
>          $_[0]->hide;  # hide the window
>          return TRUE;  # tell gtk+ that we handled this event, and
>                         # that it should *not* destroy the window.
>    });
>

You're completly right. Thanks!

> gtk_widget_hide() unrealizes the widget, which takes it off of the  
> screen, but does not kill it.  gtk_widget_destroy() hides and then  
> renders unusable the widget; the destroy is explicit in order to  
> break reference count cycles.

Ok

> Whether you reuse or recreate widgets is entirely up to you and the  
> architecture of your application.  If it takes a lot of work to  
> create a widget, or it should retain state between showings, then  
> it's likely a good idea to use hide instead of destroy.  Destroying  
> the widget will obviously be the more memory-friendly approach.  
> There is no "best" way,  in my experience; the answer is, "try both  
> and see which better satisfies your goals".

Ok!

Thanks again.
Peco
>
>
> --
> To me, "hajime" means "the man standing opposite you is about to hit  
> you with a stick".
>    -- Ian Malpass, speaking of the Japanese word for "the beginning"

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list