NaSe77 has asked for the wisdom of the Perl Monks concerning the following question:

My dear fellow monks,

i'm quite sure, that this is quite an idiotic question but i just can't figger it out:

i have written a little frontend with Tk for another script of mine:

sub go{ open (CHILD,"-|")||exec "perl script.pl"; while (<CHILD>){ $main->update; next if m/^\s*$/; chomp; s/^\s*DEBUGG(.+):\s*(\S)/\U$2/; $status->configure(-text=>"$_"); } close CHILD; $status->configure(-text=>"Status area"); }
where :
- $main is my mainwindow
- $status is some Label in my stausbar

but as my "script.pl" doesn't have a permanet outputflow the update/redraw is not made continously ...

How can I cause a continous redraw - like all 0.5 sec or something like that?

NaSe

Replies are listed 'Best First'.
Re: Redraw windows
by Rich36 (Chaplain) on May 03, 2002 at 20:11 UTC

    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...

      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...