Re: Closing a Glade Window



hi Cyril - you should keep gtk-perl-list on the loop;

On Mon, 2006-10-30 at 15:44 +0000, Cyril Cheneson wrote:
or, if you don't have Gtk2::Widget::hide_on_delete you can implement it
like this:

  $window->signal_connect(delete_event => sub { $window->hide(); TRUE; });

my $main = Gtk2::Window->new;
my $btn = Gtk2::Button->new('Click here');
$main->add($btn);
$btn->signal_connect( button_release_event => \&show_dlg );
$main->show_all;


Gtk2->main;

my $glade;
sub show_dlg {
    $glade = Gtk2::GladeXML->new('example.glade');
    $glade->signal_autoconnect_from_package('main');
    $glade->signal_connect(delete_event => sub { $glade->hide; 1} );
}

sub on_button1_clicked {
    print "In on_button1_clicked\n";
    $glade->hide;
}

Gtk2::GladeXML is not a widget - you can't call Gtk2::Widget methods
like hide() on it, as the Perl interpreter is trying to tell you:

So using Gtk2->main_quit is not what I need.
Using hide/destroy give me the following errors:
(this is for hide)
*** unhandled exception in callback:
***   Can't locate auto/Gtk2/GladeXML/hide.al in @INC (@INC contains:
/etc/perl /usr/local/lib/perl/5.8.7 /usr/local/share/perl/5.8.7
/usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8
/usr/local/lib/site_perl .) at ./example.pl line 25

you must get the widget from the glade object using its name, like:

  $window = $glade->get_widget('main-window');

and then connect the signals to the widget.  or you can add a callback
on the delete-event signal using Glade, like you did for the clicked
event of the button.

inside that callback you just call the hide_on_delete method:

  sub on_window_delete_event {
      my $window = shift;

      return $window->hide_on_delete();
  }

ciao,
 Emmanuele.




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