Re: Prevent window from being destroyed?




On Sep 13, 2005, at 9:21 PM, Daniel Kasak wrote:

How do I stop a window from being destroyed? For example, if someone clicks the window's close button, how do I prevent the window from closing immediately? I can run code when this happens ( by connecting to the window's destroy signal ), but by the time my code runs, it's too late - the window is already gone.

Connect to the delete-event signal of the toplevel window. The default handler for the signal destroys the window; if you return true from your handler, the default handler will not run.

For example:

  use strict;
  use Gtk2 -init;

  my $window = Gtk2::Window->new;
  $window->add (Gtk2::Label->new ("I'm a banana!"));
  $window->show_all;

  $window->signal_connect (delete_event => sub {
          return ! ask ($_[0], "Really quit?");
  });

  $window->signal_connect (destroy => sub { Gtk2->main_quit });
  Gtk2->main;

  sub ask {
          my ($parent, $question) = @_;
my $msgbox = Gtk2::MessageDialog->new ($parent, [], 'question',
                                                 'yes-no', $question);
          my $response = $msgbox->run();
          $msgbox->destroy;
          return $response eq 'yes';
  }



--
Brian: If i recall correctly, this is the physics department.
Chris: That explains all that gravity.
    -- Family Guy, "The Story on Page One"




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