CC: | <slaven [...] rezic.de> |
Subject: | Tk 'chooseDirectory' widget inoperative under Tk-804.028_501 on Cygwin 1.7 |
Date: | Tue, 1 Dec 2009 10:53:58 -0000 |
To: | <bug-Tk [...] rt.cpan.org> |
From: | Michael PARKER <michael.parker [...] st.com> |
I'm attempting to use the Tk 'chooseDirectory' widget on a Cygwin 1.7 platform, running Tk-804.028_501.
Invoking 'chooseDirectory', I see the following stacktrace:
Tk::Error: Odd number of args to Tk::Button->new(...)
Tk callback for .
Tk callback for .fbox.frame
Tk callback for .fbox.frame1
Tk callback for .fbox.frame2
Tk::Widget::new at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 165
Tk::Widget::__ANON__ at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 258
Tk::FBox::Populate at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/FBox.pm line 136
Tk::Derived::InitObject at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Derived.pm line 477
Tk::Widget::new at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 204
Tk::Widget::__ANON__ at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 258
Tk::DialogWrapper at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 372
Tk::FDialog at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 403
Tk::__ANON__ at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 271
Tk::chooseDirectory at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 352
Odd number of args to Tk::Button->new(...)
at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 204
This traces back to the Populate method of the FBox module, where cget's are being called on $f2_lab Label widget (line 136-146, FBox.pm). Looking at the contents of the $f2_lab hash in the debugger, it appears to be basically empty except for the a single key/data pair. There's certainly no data for the cget's to report back, causing the Button widget creation at line 136 to include undefined data for some values:
$w->{'typeMenuLab'} = my $typeMenuLab = $f3->Button
(-text => 'Files of type:',
-anchor => 'e',
-width => 14,
-underline => 9,
-bd => $f2_lab->cget(-bd),
-highlightthickness => $f2_lab->cget(-highlightthickness),
-relief => $f2_lab->cget(-relief),
-padx => $f2_lab->cget(-padx),
-pady => $f2_lab->cget(-pady),
-takefocus => 0,
);
As a workaround, I've inserted checks to see whether the cget's are defined before assigning them. If they're not defined, safe values are assigned:
$w->{'typeMenuLab'} = my $typeMenuLab = $f3->Button
(-text => 'Files of type:',
-anchor => 'e',
-width => 14,
-underline => 9,
-bd => (defined $f2_lab->cget(-bd) ? $f2_lab->cget(-bd) : 1),
-highlightthickness => (defined $f2_lab->cget(-highlightthickness) ? $f2_lab->cget(-highlightthickness) : 0),
-relief => (defined $f2_lab->cget(-relief) ? $f2_lab->cget(-relief) : "flat"),
-padx => (defined $f2_lab->cget(-padx) ? $f2_lab->cget(-padx) : 0),
-pady => (defined $f2_lab->cget(-pady) ? $f2_lab->cget(-pady) : 0),
-takefocus => 0,
);
Although the issue re. why the $f2_lab Label widget is essentially empty remains, the above hack appears to successfully workaround the issue. With this workaround in place, invoking 'chooseDirectory' now produces the following:
Tk::Error: Can't set -activebackground to `undef' for Tk::Menu=HASH(0x10b31b38): Cannot use undef value for object of type 'border' at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Configure.pm line 46.
at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Derived.pm line 294
Tk callback for .
Tk callback for .fbox.frame
Tk callback for .fbox.frame1
Tk callback for .fbox.frame2
Tk::Derived::configure at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Derived.pm line 306
Tk::Widget::new at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 206
Tk::Widget::__ANON__ at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 258
Tk::Menubutton::menu at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Menubutton.pm line 348
Tk::Menubutton::InitObject at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Menubutton.pm line 43
Tk::Widget::new at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 204
Tk::Widget::__ANON__ at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 258
Tk::FBox::Populate at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/FBox.pm line 150
Tk::Derived::InitObject at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Derived.pm line 477
Tk::Widget::new at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 204
Tk::Widget::__ANON__ at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Widget.pm line 258
Tk::DialogWrapper at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 372
Tk::FDialog at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 403
Tk::__ANON__ at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 271
Tk::chooseDirectory at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk.pm line 352
Can't set -activebackground to `undef' for Tk::Menu=HASH(0x10b31b38): Cannot use undef value for object of type 'border' at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Configure.pm line 46.
at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Derived.pm line 294
at /usr/lib/perl5/vendor_perl/5.10/i686-cygwin/Tk/Derived.pm line 306
This appears to have similar origins to the FBox problem, only this time a Menubutton widget is being configure'd with undefined data. As a workaround, I've added the following to the 'menu' sub of the Menubutton.pm module to filter out undefined properties:
sub menu
{
my ($w,%args) = @_;
my $menu = $w->cget('-menu');
if (!defined $menu)
{
require Tk::Menu;
$w->ColorOptions(\%args) if ($Tk::platform eq 'unix');
+> foreach my $key (keys %args)
+> {
+> delete $args{$key} if (!defined $args{$key});
+> }
$menu = $w->Menu(%args);
$w->configure('-menu'=>$menu);
}
else
{
$menu->configure(%args);
}
return $menu;
}
This now results in an apparently functional 'chooseDirectory' widget.
Mike