Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 57525
Status: open
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: johnm [...] topcit.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 804.028_503
Fixed in: (no value)



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; }
On Sun May 16 00:26:06 2010, jmainwar wrote: Show quoted text
> 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.
And unfortunately this binding is done on purpose. It is even documented: -default_button: Specifies the default Button that is considered invoked when user presses <Return> on the DialogBox. The trick is to use "Space" instead of "Return" to invoke the selected button. I agree that this is not intuitive, but it seems that this was the way GUIs worked like when Tk::DialogBox was written. My advice: use Tk::MsgBox instead of Tk::DialogBox. It looks somewhat more "modern" and does not have this problem. Maybe I can find a way to retain the -default_button behaviour and to act properly when the focus is over one of the dialog buttons. Show quoted text
> 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
Regards, Slaven
Subject: Re: [rt.cpan.org #57525]
Date: Fri, 28 May 2010 16:36:41 -0400
To: <bug-Tk [...] rt.cpan.org>
From: "John Mainwaring" <johnm [...] topcit.com>
Thanks for the Tk::MsgBox suggestion. Unfortunately I need the "top" area in Tk::DialogBox to display some widgets. What I did was hack DialogBox.pm to do what I wanted, with a parameter that defaults if undefined to make things work the way they worked before. I also figured out how to configure buttons in the "bottom" area to use callbacks. I wanted one of the buttons to do a consistency check, and leave the user in the DialogBox with to modify information in the widgets rather thann have to restart the dialog box and wnter all the information again. It's really nice that it's possible to do this sort of thing. I don't know if you'd be interested having in any of this. I see that Perl v5.10.xxx doesn't seem to have the Tk stuff in the library. Do you happen to know what I need to do to get it working? I want to put my application on some machines that don't have perl at the moment. The natural thing would be to install the latest version, but then I wouldn't get the Tk stuff by default. They seem to want people to move to Tkx, which might be wonderful but doesn't seem to be documented. For example, I have no idea how to find out what the basic widgets are in Tkx, let alone how to find and add new ones. Also, it looks like a pretty major effort to convert a working Tk application to Tkx. Don't know if you can help -- thanks anyway if not. I appreciate the stuff you're looking after in Tk. -------------------------------------------------- From: "Slaven_Rezic via RT" <bug-Tk@rt.cpan.org> Sent: Thursday, May 27, 2010 5:04 PM To: <johnm@topcit.com> Subject: [rt.cpan.org #57525] Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=57525 > > > On Sun May 16 00:26:06 2010, jmainwar wrote:
>> 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.
> > And unfortunately this binding is done on purpose. It is even documented: > > -default_button: Specifies the default Button that is considered invoked > when user presses <Return> on the DialogBox. > > The trick is to use "Space" instead of "Return" to invoke the selected > button. I agree that this is not intuitive, but it seems that this was > the way GUIs worked like when Tk::DialogBox was written. > > My advice: use Tk::MsgBox instead of Tk::DialogBox. It looks somewhat > more "modern" and does not have this problem. > > Maybe I can find a way to retain the -default_button behaviour and to > act properly when the focus is over one of the dialog buttons. >
>> 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
> > Regards, > Slaven > >