Re: Closing a window to trigger the 'delete_event' signal

On Jul 28, 2004, at 8:57 PM, Francois Marier wrote:

So is this the idiomatic way to do close a Window in GTK2 ?

  sub {
    unless ($window->signal_emit('delete_event',

i'm not very fond of emitting signals directly outside of a widget's implementation, so although this works, i generally avoid it.

I was somehow expecting to be able to do something like $window->close() and have it check the signal and do the right thing. All the tutorials I've seen either call $window->destroy() or Gtk2->main_quit directly, bypassing the delete_event completely.

if you really want the checking, what you do is put the checking into another function and call that function from both the delete-event handler and the button click.

  sub my_app_window_destroy {
     # do your custom stuff, and call destroy when you want it destroyed

  $window->signal_connect (delete_event => \&my_app_window_destroy);
  $button->signal_connect (clicked => \&my_app_window_destroy);

"that's it! you're a genius!" "yes. that's what i think. do you think i deserve a raise?"
        - dialogue from 'Godzilla versus Mothra', 1964

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