Question on Text Widget Update 
Author Message
 Question on Text Widget Update

I am forking a program from a perl script and I want to send
the output of the program to a text widget (already created with
scroll bar). I am having a hard time synchronizing the output
of the program to the text widget. Any ideas how to do this in
a better way ? Here is what I have done. RunProg is the program
which output should go to the Text Widget $logText.

... <code to create main window and stuff...>

$logText = $root->Text (-borderwidth => '1', -height => '1', -width =>
'1' );

$textScroll = $root->Scrollbar( -borderwidth => '1',-relief => 'flat');

   $logText->configure(-yscrollcommand => ['set', $textScroll]);
   $textScroll->configure( -command => ['yview', $logText] );

FORK: {
   if ( $child = fork ) {
     ## Parent Does nothing
   } elsif (defined $child) {
       open TEXTF, "RunProg |";
       while(<TEXTF>) {
          $logText->insert(end, $_);
       }
       close(TEXTF);
   } elsif ($! =~ /No more process/) {
       sleep 5;
       redo FORK;
   } else {
       die "Can't fork: $!\n";
   }

Quote:
}

Thanks for your help.

Regards,
Krutibas Biswal



Mon, 13 Nov 2000 03:00:00 GMT  
 Question on Text Widget Update

I figured out a solution to this problem myself.

I used the filevent mechanism :

open TEXTF, "RunProg |";
$root->fileevent(TEXTF, 'readable', sub {
                     $tmpStr = <TEXTF>;
                     if (eof(TEXTF)) {
                         $root->fileevent(H, 'readable', '');
                     } else {
                         $logText->insert('end', $tmpStr);
                         $logText->yview('end');
                     }
              } );

If I don't check for the eof in the subroutine, it seems to be
getting into some kind of loop...

By the way, where is the documentation for PERL/TK Fileevent stuff ??
I could get only the TK filevent docs.

Regards,
Krutibas Biswal
Mountain View,
CA

Quote:

> $logText = $root->Text (-borderwidth => '1', -height => '1', -width =>
> '1' );

> $textScroll = $root->Scrollbar( -borderwidth => '1',-relief => 'flat');

>    $logText->configure(-yscrollcommand => ['set', $textScroll]);
>    $textScroll->configure( -command => ['yview', $logText] );

> FORK: {
>    if ( $child = fork ) {
>      ## Parent Does nothing
>    } elsif (defined $child) {
>        open TEXTF, "RunProg |";
>        while(<TEXTF>) {
>           $logText->insert(end, $_);
>        }
>        close(TEXTF);
>    } elsif ($! =~ /No more process/) {
>        sleep 5;
>        redo FORK;
>    } else {
>        die "Can't fork: $!\n";
>    }

> }



Tue, 14 Nov 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Question on Text Widget Update

2. Question on Text Widget Update

3. How update text in text widget when executing some other callback

4. Text widget updates

5. Updating Text widget in a while() loop

6. Simple question: Saving text widgets text

7. Question about dynamically updating a widget...

8. logic question for text file updates

9. Perl/Tk and updating Text question

10. Perl/Tk and updating Text question

11. Perl/Tk Questions About Text Widget

12. Listbox and Text widget questions

 

 
Powered by phpBB® Forum Software