Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

Amlark.het, ncurses font change, www.xxx, rolan@hotmail.com, WwwXXX, fork a shell ksh, Policy reject, 550 5.7.1, cygwin ftol, 192.168.1.41:8000, Wwwxxxxcon

Links

XODOX
Impressum

#1: write, print, & Tk::Text

Posted on 2006-11-23 14:24:20 by JohnCortland.Morgan

------_=_NextPart_001_01C70F02.AF523BD2
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi All,

I'm writing a perl application using Tk for the gui, and wish to write
formatted
output to a logging window within the gui. But I cannot get write to do
as I wish,
and think that I don't really understand filehandles so well. Any
insight on them=20
would be greatly appreciated.

I have the following (shortened) code that illustrates my problem,
when run=20
from the command line (Unix or Win). I can print to the logging window,
but not write=20
(formatted output) to it. Is it that Tk::Text doesn't give a true
filehandle? Any way
to do this using only standard modules (those that come by default with
Perl)?

Thanks,

John

------------------------------------------------------------ ------------
-------

#!/usr/local/PERL_5.005_03/bin/perl -w

use Tk;
use FileHandle;

$mw =3D new MainWindow;

$report =3D $mw->Button(-text=3D>'Report',-command=3D>\&report);
$e =3D $mw->Button(-text=3D>'Exit',-command=3D>sub{exit 0;});
$report->pack($e);

$log =3D $mw->Text()->pack();
tie (*LOG, 'Tk::Text', $log);

MainLoop();

exit 0;

#--------------------------------------------------

sub report() {
my ($f1, $f2, $f3) =3D ('F1','F2','F3');

format SOURCES_TOP =3D
field1 field2 field3
------ ------ ------
..

format SOURCES =3D
@||||| @||||| @|||||=20
$f1, $f2, $f3
..
=20
$ofh =3D *LOG; # using this instead of *STDOUT gives command
line errors
# $ofh =3D *STDOUT;

select($ofh);
$ofh->format_name("SOURCES");
write $ofh;

&logit("wrote to $ofh");

}

#--------------------------------------------------
sub logit() {
return unless $log;

# this always prints to Tk::Text widget correctly
for (@_) { print LOG $_, "\n"; }=20
}



------_=_NextPart_001_01C70F02.AF523BD2--

Report this message

#2: Re: write, print, & Tk::Text

Posted on 2006-11-24 17:21:50 by unknown

Post removed (X-No-Archive: yes)

Report this message

#3: RE: write, print, & Tk::Text

Posted on 2006-11-28 12:48:42 by JohnCortland.Morgan

Hi,

Thanks for your reply, but still questions... You're right about this:

>> $ofh =3D *LOG; # using this instead of *STDOUT gives command
line errors

> Well you don't open LOG anywhwere. STDOUT, STDIN, AND STDERR are
predefined filehandles, so you can get away with it.
=20
I don't open LOG anywhere, I only tie to it after creating the Tk::Text
widget (actually,a Tk::Scrolled widget).

tie (*LOG, 'Tk::Text', $log);

But if it is not an open filehandle, why does my subroutine work?

#--------------------------------------------------
sub logit() {
return unless $log;

# this always prints to Tk::Text widget correctly
for (@_) { print LOG $_, "\n"; }
}
#--------------------------------------------------

and if it is an open filehandle, why doesn't this work:

$ofh =3D *LOG; # using this instead of *STDOUT gives command line
errors

As I said, maybe it's not a true filehandle???

> I'm a little confused as to what you are trying to do.=20
> Are you trying to monitor an external log file, or are you trying to
substitute the text widget for the log file?

Started out as just a way to show debugging info in the gui, instead of
on command line.=20
Then went to writing a report to the gui. But now I'd just like to
understand why=20
print will print to LOG but write will not write to it.

Thanks,

John




-----Original Message-----
From: Linux@lists.develooper.com [mailto:Linux@lists.develooper.com] On
Behalf Of zentara
Sent: Friday, November 24, 2006 5:22 PM
To: beginners@perl.org
Subject: Re: write, print, & Tk::Text

On Thu, 23 Nov 2006 14:24:20 +0100, JohnCortland.Morgan@ericsson.com
("John Cortland Morgan \(ZG/ETK\)") wrote:

>Hi All,
>
>I'm writing a perl application using Tk for the gui, and wish to write=20
>formatted output to a logging window within the gui. But I cannot get=20
>write to do as I wish, and think that I don't really understand=20
>filehandles so well. Any insight on them would be greatly appreciated.

> $ofh =3D *LOG; # using this instead of *STDOUT gives command
line errors

Well you don't open LOG anywhwere. STDOUT, STDIN, AND STDERR are
predefined filehandles, so you can get away with it.

I'm a little confused as to what you are trying to do.=20
Are you trying to monitor an external log file, or are you trying to
substitute the text widget for the log file?

If you are just looking to write formatted text to the text widget, you
could forget about the format_name("SOURCES") ,and just avoid the
filehandle mixup, by a=20

$temp=3Dsprintf("%-55s %-30s %-10s %-16s %-10s\n", $i,$j,$k,$m,$n);
&disp($temp);

sub disp {
my $message=3Dshift;
$txt -> insert('end',$message);
print "$message";
}


You could also try asking this on comp.lang.perl.tk if you really want
to use Filehandle's format_name.
Some smart Text gurus hang out there.



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org For additional
commands, e-mail: beginners-help@perl.org <http://learn.perl.org/>
<http://learn.perl.org/first-response>



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#4: Re: write, print, & Tk::Text

Posted on 2006-11-28 20:02:47 by unknown

Post removed (X-No-Archive: yes)

Report this message