in reply to Redraw windows

What you can do to get a continuous output from a process is tie a filehandle to a ROText box. Below is something that I hacked together just now - it opens a perl script and prints the comment lines to the ROText box. It sets up a file handle (WINDOW) and ties that to the ROText box. The ROText box will update whenever any print is done to that file handle. By placing the functionality of your sub "go" in the "addText" sub and printing to the filehandle WINDOW, the text will be updated continously. You just have to have some kind of event (like the button below) to trigger the callback to the sub.

If you haven't used the ROText box, it functions just like a normal Tk text box, but is read only.

#!/usr/bin/perl use strict; use Tk; use Tk::ROText; ####################################################### # MAIN ####################################################### my $mw = MainWindow->new(-title=>'Tie Test'); my $appROText = $mw->Scrolled('ROText', -relief=>'ridge', -width=>100, + height=>30)->pack(); my $goButton = $mw->Button(-text => 'Add text to window', command=>\&a +ddText)->pack(); tie(*WINDOW, 'Tk::ROText', $appROText); MainLoop; sub addText { open(FILE, "<someapp.pl") or die "Couldn't open file"; while(<FILE>) { print WINDOW $_ if (m/^\#/); } close(FILE); }

Rich36
There's more than one way to screw it up...

Replies are listed 'Best First'.
Re: Re: Redraw windows
by NaSe77 (Monk) on May 06, 2002 at 14:06 UTC
    Thanks - it wasn't really what i searched for but it helped my find the answer - using fileevent:
    #!/usr/bin/perl -w use Tk; open(CHILD, "perl script.pl|") or die "Nope: $!"; my $mw = new MainWindow; my $t = $mw->Text(-width => 80, -height => 25, -wrap => 'none'); $t->pack(-expand => 1); $mw->fileevent(\*CHILD, 'readable', [\&fill_text_widget, $t]); MainLoop; sub fill_text_widget { my($widget) = @_; $_ = <H>; $widget->insert('end', $_); $widget->yview('end'); }
    NaSe

      Cool. Didn't know about that one. That seems a little more general in that it looks like it can be tied to a variety of widgets.


      Rich36
      There's more than one way to screw it up...