Re: Blocking Main Window destroy siginal



On Sun, 2004-09-19 at 09:33, Kevin C. Krinke wrote:
On Sun, 2004-09-19 at 08:52, Jasun Wurster wrote:
Hi,

I would like to prevent my app from being closed by the user during some 
database writes and data transfers.

Is there a way to block the Window destroy signal so that if the 'x' button in 
the main window is clicked it is ignored and the app keeps running?

Der, that example doesn't work because of a silly apostrophe... this one
is better and will work when highlighted then middle-clicked into a
terminal:

<code>
/usr/bin/perl -e '
use strict;
use Glib qw( TRUE FALSE );
use Gtk2 -init;

my $block = FALSE;
my $window = new Gtk2::Window ( "toplevel" );
my $button = new Gtk2::Button ( "toggle block" );
$window->add( $button );
$button->signal_connect( clicked => sub {
                             my ( $w, $bl ) = ( @_ );
                             # invert the state
                             $$bl = ( $$bl == TRUE ) ? FALSE : TRUE;
                             # report the current state
                             if ( $$bl == TRUE ) {
                                 print STDERR "BLOCKED\n";
                             } else {
                                 print STDERR "UNBLOCKED\n";
                             }
                         }, \$block );
$window->signal_connect( "delete-event" => sub {
                             my ( $w, $e, $bl ) = ( @_ );
                             # unless we are blocked, quit:
                             unless ( $$bl == TRUE ) {
                                 main_quit Gtk2;
                             }
                             return( $$bl );
                         }, \$block );
$window->show_all();
main Gtk2;
'
</code>

Yea yea yea... so I like to correct my mistakes regardless of how
trivial they are.

Enjoy.

-- 
Kevin C. Krinke <kckrinke opendoorsoftware com>
Open Door Software Inc.




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