[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: destroying widgets and Gtk2::GladeXML
- From: James Curbo <hannibal adtrw org>
- To: Gtk-Perl-List <gtk-perl-list gnome org>
- Subject: Re: destroying widgets and Gtk2::GladeXML
- Date: 03 Aug 2003 14:19:36 -0500
On Sun, 2003-08-03 at 10:00, Ross McFarland wrote:
> the following code:
> ##############################################
>
> use Gtk2 '-init';
> use Gtk2::GladeXML;
>
> $gld = Gtk2::GladeXML->new('glade_test.pl.glade');
>
> $gld->signal_autoconnect_from_package('main');
>
> $btn = $gld->get_widget("button1");
>
> sub on_button1_clicked
> {
> my $dialog = new Gtk2::Dialog;
> $dialog->set_title("New Dialog");
> # create ok button, connect signals etc
> $dialog->run;
>
> $dialog->destroy;
> }
>
> Gtk2->main;
> ##############################################
> seems to behave as would be expected. i created a trivial glade-2
> project with 1 button and added a clicked callback.
>
Yes, I would think so, since you aren't creating the widget with
libglade.
> it also seems to work when i remove the signal handler from the glade-2
> project and grab the button myself and connect the callback
>
> $btn = $gld->get_widget("button1");
> $btn->signal_connect( clicked => \&on_button1_clicked );
>
Same situation, just handling the callback yourself.
> i click the button as many times as i wish and it seems to pop up the
> dialog and it goes away at the destroy, the next time around it's all
> new and works as expected
>
> so the way you used to do it works, but as for the glade stuff my best
> explanation is that it creates the widget when new is called. it then
> destroys the widget when you call destroy. destroy does just that after
> called it will no longer exist so the next time you try use it nothing
> is there to use. it's somewhat of a problem with glade and the way
> dialogs work. hide is probably the best workaround, but won't suffice in
> all situations, mainly when you would want to have a completely new
> dialog without the changes made last time.
Yes, it seems libglade creates all widgets at startup. muppet emailed me
but forgot to CC it to the list:
(muppet said:)
> a quick perusal of the C source for libglade shows that
> glade_xml_get_widget is implemented as a call to g_hash_table_lookup
> --
> there's no magic to re-create dead widgets. all the widgets are
> created by glade_xml_new. thus, when you call ->destroy on it, it's
> gone... so, eh, don't do that. ;-)
So yeah, it seems that calling destroy is a bad thing, because you get
all your widgets at the beginning.
> another possible workaround, but not ideal is to define the dialog in a
> separate glade file and in the button clicked handler create a new glade
> object that is a dialog. this has lots of issues though, but could be
> done. it would only be worth it if you had a really fancy complicated
> dialog that is way to hard to create by hand, well that you don't want
> to anyway.
>
Indeed, I would rather create a highly complex dialog myself.
> sorry, probably left you with more questions than you started, but
> hopefully it helped a little. i guess if nothing else, hide is about the
> best way to deal with the less than perfect situation.
>
No, I'm satisified. I'm still trying to figure out the best thing to do
in a lot of situations and this helps.
> personally i would suggest using glade for prototyping apps, and then
> reimplementing them the long way if you're going to be using them in any
> kind of real environment. i think you need the control of the long way
> if you're going to be trying to get all of the bugs and issues out of a
> real app, but that's just me.
>
Indeed. I'm just using it for a small for-myself application so I don't
see it as being a big deal, however, were I writing a large app I would
probably do as you say. Glade is great for figuring out how you want
things to look, and has made me far more productive at GTK programming.
> -rm
Thanks for the response.
--
James Curbo <hannibal adtrw org>
http://www.raspberryheaven.net/~hannibal/
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]