CC: | slaven [...] rezic.de |
Subject: | [Update] Tie Stdout, Tk::Text and syswrite |
Dear,
Example :
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw = MainWindow->new;
my $Scrolled = $mw->Scrolled(
"Text",
-height => 10,
-wrap => "none",
-relief => "solid",
-background => "white",
-scrollbars => "osoe",
)->pack(qw/ -side bottom -pady 15 -padx 15 -fill both -expand 1 /);
tie *STDOUT, $Scrolled, $Scrolled->Subwidget('scrolled');
for ( 1 .. 15 ) {
print "Hello Text World!\n";
my $toto = sprintf( "%.3f", 123.456789 );
syswrite( *STDOUT, "$toto\n",-3 );
}
print "End Tie\n";
untie *STDOUT;
print "After Tie\n";
MainLoop;
1- Small update in Tk::Text.
tie *STDOUT, ref $text, $text; work only if we use print and printf method.
It's possible to add method sprintf and syswrite ? Else we have this
error message :
Can't locate auto/Tk/Text/WRITE.al in @INC (@INC contains:
C:/Perl/site/lib C:/Perl/lib .) at C\test.pl line 23
That is a Perl code to resolv this problem, you can add it in Text.pm
sub WRITE {
my ($w, $scalar, $length, $offset) = @_;
unless ( defined $length ) { $length = length $scalar; }
unless ( defined $offset ) { $offset = 0; }
$w->PRINT( substr($scalar,$offset,$length) );
}
I have test and it work well :
tie *STDOUT, 'Tk::Text', $Scrolled->Subwidget('scrolled');
or
tie *STDOUT, $Scrolled, $Scrolled->Subwidget('scrolled');
2- Update in Tk::Text POD
Can you add that this in section TIED INTERFACE
To Tie in text scrolled widget, don't forget to use Subwidget method.
tie *STDOUT, 'Tk::Text', $Scrolled->Subwidget('scrolled');
3- Bug untie
If I want to untie, It's work but I have an error message :
untie attempted while 13 inner references still exist at ...
Best Regards
Djibril Ousmanou