Skip Menu |

This queue is for tickets about the Tk-JComboBox CPAN distribution.

Report information
The Basics
Id: 12372
Status: resolved
Priority: 0/
Queue: Tk-JComboBox

People
Owner: Nobody in particular
Requestors: ken.prows#online-rewards.com
Cc:
AdminCc:

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



Subject: grab function in JComboBox makes it unusable in dialog boxes
I am using Tk::JComboBox 1.05 w/ Perl 5.8.6 on Fedora Core 2. I'm not sure if this would be classified as a bug but it may be something to add to the documentation at least. I have found that the grabRelease in &hidePopup and the grabGlobal in &showPopup make it inconvenient to use JComboBox in a custom dialog box. Let me elaborate: I created a custom dialog box using Tk::DialogBox. In the dialog I added a JComboBox widget. I then called grabGlobal on the dialog box so that the main window could not be effected until the DialogBox is closed. The problem is, as soon as I open the menu in the JComboBox widget, the global grab on the DialogBox is lost. The main window becomes active and can be manipulated from that point on. - Ken Prows Attached is a simple script that demonstrates this problem.
#!/usr/bin/perl -w use strict; use Tk; use Tk::DialogBox; use Tk::JComboBox; my $Main = MainWindow->new(); my $Btn = $Main->Button(-text=>"You can't click me until you open the JComboBox!")->pack; my $Dialog = $Main->DialogBox(-title => 'JComboBox/DialogBox Grab Test'); $Dialog->add('Label', -text=>'This demonstrates how the JComboBox interferes with a DialogBox\'s grab.')->pack; my $Jcb = $Dialog->add('JComboBox')->pack; $Jcb->addItem('Open me to enable the main window button.', -selected=>1); $Jcb->addItem('Main window should now be active..'); $Dialog->Show(); MainLoop();
Subject: fixed it!
From: ken.prows#online-rewards.com
I think I've found a solution to this. Here is a patch.. -------------------------- change &showPopup to this: -------------------------- sub showPopup { my $cw = shift; return if ($cw->popupIsVisible || $cw->getItemCount == 0); $cw->Callback(-popupcreate => $cw) if (ref($cw->cget('-popupcreate')) eq 'Tk::Callback'); my $popup = $cw->Subwidget('Popup'); $popup->deiconify; $popup->raise; $cw->Subwidget('Entry')->focus; # START PATCH CODE if ($cw->grabCurrent) { $Tk::oldGrab = $cw->grabCurrent; $Tk::oldGrabStatus = $Tk::oldGrab->grabStatus; } # END PATCH CODE $cw->grabGlobal; } -------------------------- change &hidePopup to this: -------------------------- sub hidePopup { my ($cw) = @_; my $popup = $cw->Subwidget('Popup'); if ($popup->ismapped) { $popup->withdraw; $cw->grabRelease; # START PATCH CODE if ($Tk::oldGrab and $Tk::oldGrabStatus) { if ($Tk::oldGrabStatus eq 'local') { $Tk::oldGrab->grab; } if ($Tk::oldGrabStatus eq 'global') { $Tk::oldGrab->grabGlobal; } undef($Tk::oldGrab); undef($Tk::oldGrabStatus); } # END PATCH CODE } } - Ken Prows
[guest - Thu Apr 21 15:59:41 2005]: Show quoted text
> I think I've found a solution to this. Here is a patch.. > > -------------------------- > change &showPopup to this: > -------------------------- > sub showPopup > { > my $cw = shift; > return if ($cw->popupIsVisible || $cw->getItemCount == 0); > > $cw->Callback(-popupcreate => $cw) > if (ref($cw->cget('-popupcreate')) eq 'Tk::Callback'); > > my $popup = $cw->Subwidget('Popup'); > $popup->deiconify; > $popup->raise; > $cw->Subwidget('Entry')->focus; > > # START PATCH CODE > if ($cw->grabCurrent) > { > $Tk::oldGrab = $cw->grabCurrent; > $Tk::oldGrabStatus = $Tk::oldGrab->grabStatus; > } > # END PATCH CODE > > $cw->grabGlobal; > } > > -------------------------- > change &hidePopup to this: > -------------------------- > sub hidePopup > { > my ($cw) = @_; > my $popup = $cw->Subwidget('Popup'); > > if ($popup->ismapped) > { > $popup->withdraw; > $cw->grabRelease; > > # START PATCH CODE > if ($Tk::oldGrab and $Tk::oldGrabStatus) > { > if ($Tk::oldGrabStatus eq 'local') > { > $Tk::oldGrab->grab; > } > if ($Tk::oldGrabStatus eq 'global') > { > $Tk::oldGrab->grabGlobal; > } > undef($Tk::oldGrab); > undef($Tk::oldGrabStatus); > } > # END PATCH CODE > > } > } > > - Ken Prows
Ken, Thanks very much for not only reporting the problem, but coming up with a solution as well. I will patch the code, kick the tires a bit, and then push out a new version within a week or so. I appreciate it. I'm glad the widget has been useful for you. Rob