Tabbing to a button in a DialogBox popup window and keying '<RETURN>'
always causes it to return the Default button text, not the button that
was actually selected. This could cause the program that called the
DialogBox to take the wrong action based on the return code. The
problem is caused by the line in the Populate routine of DialogBox.pm
that binds the '<RETURN>' key to the default key for the whole DialogBox
widget. Unfortunately, that binding overrides the earlier binding in the
foreach loop of '<RETURN>' to invoke the buttons, whichever one is tab
selected at the time. The attached code shows that unbinding the
'<RETURN>' key fixes the problem and doesn't cause any other problems.
TO reproduce the problem, just comment out line 31 in the file:
$protoBox->bind('<Return>' => []);
I have tested this problem and fix in Windows XP SP3 with Activestate
perl, and in Ubuntu 9.10 and Kubuntu 8.04 with perl-tk installed and
versions '4.015' and '4.016' of DialogBox.pm
Please let me know if I can provide any additional information
Subject: | tk-db-bug.pl |
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::DialogBox;
my $mw = MainWindow->new(-height =>400, -width =>1000,
-title => 'Calendar Utility');
# Assign function buttons
my $calCreateBut = $mw->Button(-width => 40,
-text => "Launch application segment", -command =>\&appCreate);
$calCreateBut->pack(-side =>'top', -padx => 6, -pady => 2);
my $donebut = $mw->Button(-width => 9,
-text => "Quit", -command =>sub{exit});
$donebut->pack(-side =>'bottom', -padx => 6, -pady => 2);
my $protoBox = $mw->DialogBox(-title => "Application segment",
-cancel_button => "Cancel",
-buttons => ["OK", "Cancel"],
# -callbacks => [\&protoOkCheck, '', \&protoSsupCheck],
-default_button => 'Cancel'
);
# If we don't do this, hitting the 'RETURN' key always invokes the cancel
# button, not the button that is selected by the TAB key. If this line is
# removed, the OK button seems to work when you TAB to it and hit the 'RETURN'
# key but it returns 'Cancel' instead of 'OK'. Clicking on the OK button
# returns 'OK' whether you unbind '<RETURN>' from the DialogBox or not.
$protoBox->bind('<Return>' => []);
# This would not be necessary if the line:
# $cw->bind('<Return>' => [ $b, 'Invoke']);
# was removed from the Populate routine of DialogBox.pm This is the line that
# binds the default button to '<Return>' the Dialog widget ($cw), not the line
# that binds each individual button to '<Return>' in the 'foreach' loop.
MainLoop;
sub appCreate {
my $dButton = $protoBox->Show(-popover => $donebut,
-popanchor => 'nw',
);
print "User pressed <" . $dButton .
"> button, causing the DialogBox to exit\n";
return;
}