RE: [tcltk-perl] scalar($w->getOpenFile)
Brought to you by:
hobbs
From: Konovalov, V. <vko...@sp...> - 2004-04-21 14:37:47
|
> If you try the following program: > > #!/usr/bin/perl -w > > use Tcl::Tk qw(:perlTk); > > my $mw = MainWindow->new; > my $label = $mw->Label(-text => "Hello")->pack; > if (my $file = $mw->getOpenFile) { > $label->configure(-text => "File [$file]"); > $mw->after(5000, sub { $mw->destroy }); > } > > MainLoop; > > and then hit "Cancel" to the dialog that pops up, then we fill in the > field with something like "File [ARRAY(0x8141ad8)]". Apparently > tk_getOpenFile returns a list instead of string, but this is not > documented. Since there is no semantic difference between a list and > a string this does not really matter to Tcl, but for perl with the > current Tcl.pm behaviour it does. I think we should make $tcl->Eval > and $tcl->call behave as I describe in the quoted text above. That > would fix this problem and in general make things sane. > > Is there a way to make an automatic test case out of this? I guess > I'm asking if there is a way to make the program above hit the > "Cancel" button by itself. I think this is not possible, as it is Modal window and this is not doable at C level (I almost sure about on Win32). I'll add few notes about wantarray/scalar context that needs to be fixed: following code: use Tcl::Tk qw/:perlTk/; $mw = tkinit; $t = ' te st frfrjfr ****** '; $e = $mw->Entry(-textvariable=>\$t)->pack; #$mw->Button(-text=>'test',-command=>sub{ print "[",$e->get,"]\n"; #})->pack; #MainLoop; prints [testfrfrjfr******] because "$e->get" is under wantarray and we receive a list with spaces thrown away. Replacing to print "[",scalar($e->get),"]\n"; normalizes things. That said, we must use list context only in some few functions, and mostly call 99% of functions in scalar context. Vadim. |