Closing a window to trigger the 'delete_event' signal



Hi,

I would like to do a check before my Gtk2::Window is closed and so I
created it like this:

  $window = Gtk2::Window->new;
  $window->signal_connect(destroy => sub { Gtk2->main_quit; });
  $window->signal_connect(delete_event => sub {
      $attempts++;
      if ($attempts < 2) {
          print "Can't exit yet, keep on trying.\n";
          return 1;
      } else {
          print "Alright, you can go now.\n";
          return 0;
      }
  });

Now if I close it using the standard window controls, the delete_event
signal is triggered and the window will only close the second time.

My question is how do I programmatically delete this Gtk2::Window
object if I want the delete_event signal to be called ?

I have tried the following:

  $quit = Gtk2::Button->new("Quit");
  $quit->signal_connect(clicked => sub {$window->destroy();});
  $window->add($quit);

but the window is destroyed automatically without calling the
delete_event signal.

I have also tried :

  $window->signal_emit('delete_event', undef);

but it doesn't work and I can't find any documentation as to what the
second parameter is supposed to be.

Any suggestions/pointers?

Thanks,

Francois



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