grab_default doesn't seem to grab.

Hi All,

Trying to understand why grab_default doesn't seem to work like the
way I interpreted the documentation.
Can somebody run this script and see if the issue is explicable ?

use strict;
use warnings;

use Gtk2 '-init';
use Glib ':constants';

my $window = Gtk2::Window->new( 'toplevel' );
$window->signal_connect( destroy => sub {Gtk2->main_quit(); } ) ;
my $vbox = Gtk2::VBox->new( TRUE, 5);
$window->add( $vbox );
my $first_button = Gtk2::Button->new_with_label( "First Button" );
$vbox->pack_start( $first_button, TRUE, TRUE, 10 );

my $close_button = Gtk2::Button->new_from_stock( 'gtk-close' );
$close_button->signal_connect_swapped( clicked => sub{ $_[0]->destroy;
}, $window ) ;
$vbox->pack_start( $close_button, TRUE, TRUE, 10 );

$close_button->can_default( TRUE );


As I understand the documentation, a widget with grab_default should
be activated when the user presses "Enter". So if the widget is a
close button, a button with this as the default
should close when the user hits "enter".

I can only get this to work as described if i get the close button to
grab the focus as well.

Also, the I've noticed the problem replicates on a C version of the same script.

Is this a problem with a depreciated function, ( I can't find anything
to say it is depreciated),
or a problem with the way I've implemented it?
or a problem with my understanding of the documentation?


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