Closing a Gtk::Dialog - How?

From: Martin Schulze (joey@infodrom.org)
Date: Sat Jun 29 2002 - 16:26:07 CEST

  • Next message: Bruce Perens: "Wrong version of Debian on InfoMagic CD"

    Hi!

    I wonder if somebody on this list can give me assistence with Gtk-Perl
    and closing a Gtk::Dialog properly.

    The main window in the application will create info dialog boxes on
    demand which looks like the code below.

    My question is how do I make the »Close«-button work properly, using
    the Gtk-Perl way[tm] and witout wasting memory.

    I currently know about three ways to get this done visually, but all
    three of them, doesn't free memory again.

    The three methods of visually closing the dialog windows (i.e. so they
    are not visible anymore) are:

        $button->signal_connect ("clicked", sub { $dialog->hide; });

        $button->signal_connect ("clicked", sub { $dialog->destroy; });

        $button->signal_connect ("clicked", sub { destroy $dialog; });

    This is tested using this method:

     1. opening some 15 info windows
     2. check memory use
     3. closing all info windows
     4. check memory use
     5. opening some five info windows
     6. check memory use

    Interestingly, the memory use from 2 and 4 are similar, and 6 shows an
    even higher memory consumption. Hence, I assume that for some reason
    memory is not freed after closing the windows, and it's not even
    reused, so it's not placed and marked "unused" in a garbage collector.

    So what's the Gtk-Perl way for achieving this?

    The tutorial somehow forgot to contain this bit of information. The
    »Close« button is created and added to the dialog, but no Close
    functionality is added, dunno why. Here's the link
    <http://personal.riverusers.com/~swilhelm/gtkperl-tutorial/dialog.html>

    Please copy your answer to me, since I'm not (yet) subscribed to this
    list (use joey@debian.org, if you should use a broken mail server).

    Thanks in advance,

            Joey

    sub open_info_window
    {
        my $fruit = shift;

        my $dialog = new Gtk::Dialog();
        $dialog->title ($fruit);
        $dialog->set_usize( 300, 300 );

        my $button = new Gtk::Button( "Close" );
        # connect signal to button
        $dialog->action_area->add( $button );
        $button->show();

        my $frame = new Gtk::Frame ("Description");
        $frame->border_width (3);

        $Text::Wrap::columns = 1000;
        my $realtext = Text::Wrap::fill ("", "", $info{$fruit});
        
        my $text = new Gtk::Text (undef, undef);
        $text->set_editable ($false);
        $text->set_word_wrap ($true);
        $text->insert (undef, $text->style->black, undef, $realtext);

        $frame->add( $text );
        $dialog->vbox->add( $frame );

        $dialog->show_all();
    }

    -- 
    If nothing changes, everything will remain the same.  -- Barne's Law
    

    Please always Cc to me when replying to me on the lists.



    This archive was generated by hypermail 2.1.4 : Sat Jun 29 2002 - 16:37:10 CEST