problems destroying Gtk2::Window

View: New views
4 Messages — Rating Filter:   Alert me  

problems destroying Gtk2::Window

by Tomáš Bažant :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi
 i working an a small application which uses one main Gtk2::Window. i
have connected the destroy-event and delete-event to it, but after
clicking on X close button of the window manager, the window disappears
and i have no chance to manage it any further.

any idea how to make it obey?

--
Tomáš Bažant <tbazant@...>
Novell, SUSE Linux s.r.o.

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: problems destroying Gtk2::Window

by Kenneth Swanson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://gtk2-perl.sourceforge.net/doc/pod/Gtk2/main.html#Gtk2_main_quit

Basically, you need to call 'Gtk2->main_quit' somewhere in your program to make the event loop stop processing.  A good place is to connect to
your window's delete event and call it in the callback, like this tutorial shows:

http://forgeftp.novell.com//gtk2-perl-study/documentation/html/c403.html

-Ken

On 09/17/2009 03:40 AM, Tomáš Bažant wrote:
> hi
>  i working an a small application which uses one main Gtk2::Window. i
> have connected the destroy-event and delete-event to it, but after
> clicking on X close button of the window manager, the window disappears
> and i have no chance to manage it any further.
>
> any idea how to make it obey?
>
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: problems destroying Gtk2::Window

by Kevin Ryde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Kenneth Swanson <kswanson@...> writes:
>
> delete event ... like this tutorial shows:
> http://forgeftp.novell.com//gtk2-perl-study/documentation/html/c403.html

Actually the 'destroy' signal may be preferable in general, as it also
catches explicit $window->destroy calls from the application.  Not that
there are any of those of course unless you put one yourself.

There's some crib notes at the start of the Gtk2::Window docs (and a bit
more with Gtk2::Dialog on closing dialogs).  Tries not to duplicate the
gtk docs, but the gtk docs aren't fantasticly clear in various areas. :)
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: problems destroying Gtk2::Window

by muppet-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Sep 17, 2009, at 4:40 AM, Tomáš Bažant wrote:

> hi
> i working an a small application which uses one main Gtk2::Window. i
> have connected the destroy-event and delete-event to it, but after
> clicking on X close button of the window manager, the window  
> disappears
> and i have no chance to manage it any further.
>
> any idea how to make it obey?

Depends on what you want to do.  Are you wanting to catch the user  
clicking the "x" so you can prompt before closing the window?

The delete-event signal has a return type, and what you return from  
delete-event is important!


Here's one that does pretty much everything and should give you a feel  
for it.  You connect to destroy to kill the main loop so that the main  
loop stops no matter how the window is destroyed.  You connect to  
delete-event to trap the user trying to kill the window via the window  
manager (including shortcuts like Alt+F4, etc).  There's really no  
reason to connect to destroy-event.



#!/usr/bin/env perl
use strict;
use warnings;
use Gtk2 -init;
use Glib ':constants';


my $window = Gtk2::Window->new;
$window->set_title ("I do stuff.");

my $want_prompt_check =
     Gtk2::CheckButton->new ("Ask before closing via window manager  
kill");

my $kill_me_button = Gtk2::Button->new ("I demand that you shoot me  
now");

$kill_me_button->signal_connect (clicked => sub {
     print "Clicky!  Killing the window directly.\n";
     $window->destroy;
});

$window->signal_connect (delete_event => sub {
     print "Window manager kill event!\n";
     my $should_prompt = $want_prompt_check->get_active;
     print "  User " . ($should_prompt ? "wants" : "does not want")
         . " to be prompted first.\n";

     if ($should_prompt) {
         my $dialog = Gtk2::MessageDialog->new
             ($window, [], 'question', 'none',
              "Do you really want to kill the window?");
         $dialog->add_buttons ( "No, just kidding" => 'cancel',
                                "Yes, kill it" => 'accept');
         my $response = $dialog->run;
         $dialog->destroy;

         if ($response ne 'accept') {
             print "User didn't say yes, returning TRUE to say we  
handled the"
                 . "event\nand inhibit the default event actions.\n";
             return TRUE;
         }
     }

     print "Returning FALSE from delete-event will let the default  
action happen.\n"
         . "(The default action is to destroy the window.)\n";
     return FALSE;
});

$window->signal_connect (destroy => sub {
     print "Woe betide me, i art dead.  I will stop main loop now.\n";
     Gtk2->main_quit;
});


my $vbox = Gtk2::VBox->new;
$vbox->pack_start ($want_prompt_check, FALSE, FALSE, 0);
$vbox->pack_start ($kill_me_button, FALSE, FALSE, 0);
$window->add ($vbox);
$window->show_all;

Gtk2->main;

print "Main loop finished!\n";

__END__

--
Santa ate all the cookies!
   -- Zella's first, indignant words on Christmas morning, '07.

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list