fileevent problem 
Author Message
 fileevent problem

Hi,

This may be a very simply problem but it sure has me stumped.
I would like to read a directory which has a large number of files, from
a tkperl script. Problem is that I do not want the application to freeze
during reading of directory. I tried using the fileevent method after
opening directory (opendir) but get error " Cannot get file from DIR at
readmydir line 19". Can any one tell me what I am doing wrong?

I am beginning to think that fileevent only works with filehandles from
regular files. If this is the case, how can I perform a directory read
without blocking/freezing Tk app. Any help/guidiance will be
appreciated.

============================== cut ===============================

use TK;
use Tk::IO;
use English;

# Initialize Tk

        my $tmp = '';
        my $src_dir = './';

        my $top = MainWindow->new();
        my $lb = $top->ScrlListbox(-relief => 'sunken',-scrollbars =>
'rse',-label => $ltitle, -height => 25);
        $lb->configure(-labelRelief => 'raised');
        $lb->pack(-side => 'left',-expand => 1, -fill => 'both'  );

        opendir(DIR,"$src_dir") or die "Nope: $OS_ERROR";;
        my $fh = Tk::IO->new('DIR');
        $top->fileevent(DIR,'readable',\&doline);

#        for $tmp  (sort readdir(DIR)){
#                  $lb->insert('end',$tmp) if $tmp =~ /^\w/;
#                  #$top->update;
#        }
#        close(DIR);

        MainLoop;

sub doline
{
 my $line = <DIR>;
 if (!defined $line)
  {
   $mw->fileevent(DIR,'readable','');
   $mw->destroy;
  }
 else
  {

  }

Quote:
}



Mon, 16 Nov 1998 03:00:00 GMT  
 fileevent problem

Quote:

> Hi,

> This may be a very simply problem but it sure has me stumped.
> I would like to read a directory which has a large number of files, from
> a tkperl script. Problem is that I do not want the application to freeze
> during reading of directory. I tried using the fileevent method after
> opening directory (opendir) but get error " Cannot get file from DIR at
> readmydir line 19". Can any one tell me what I am doing wrong?

> I am beginning to think that fileevent only works with filehandles from
> regular files. If this is the case, how can I perform a directory read
> without blocking/freezing Tk app. Any help/guidiance will be
> appreciated.

It does indeed seem that opendir does not create something that
you can use with fileevent. Maybe new IO:: hierachy in perl will
help.

However, despite the name (which I copied from Tcl/Tk) fileevent
is not much use for files on disk. They are _always_ readable till EOF.
So even if fileevent worked it would still freeze TK display.

What you need to do is loop on readdir but put a DoOneEvent
or 'update' in the loop to give TK a share of the CPU.

Quote:

> ============================== cut ===============================

> use TK;
> use Tk::IO;
> use English;

> # Initialize Tk

>         my $tmp = '';
>         my $src_dir = './';

>         my $top = MainWindow->new();
>         my $lb = $top->ScrlListbox(-relief => 'sunken',-scrollbars =>
> 'rse',-label => $ltitle, -height => 25);
>         $lb->configure(-labelRelief => 'raised');
>         $lb->pack(-side => 'left',-expand => 1, -fill => 'both'  );

>         opendir(DIR,"$src_dir") or die "Nope: $OS_ERROR";;
>         my $fh = Tk::IO->new('DIR');
>         $top->fileevent(DIR,'readable',\&doline);

> #        for $tmp  (sort readdir(DIR)){
> #                  $lb->insert('end',$tmp) if $tmp =~ /^\w/;
> #                  #$top->update;
> #        }
> #        close(DIR);

>         MainLoop;

> sub doline
> {
>  my $line = <DIR>;
>  if (!defined $line)
>   {
>    $mw->fileevent(DIR,'readable','');
>    $mw->destroy;
>   }
>  else
>   {

>   }

> }



Wed, 18 Nov 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. A fileevent problem

2. fileevent problem on Redhat8.0

3. TK800.010 fileevent problem

4. HELP: Tk800.010 & fileevent problems

5. fileevent problem

6. FILEEVENT PROBLEM

7. fileevent problems in Tk800

8. Fileevent problem

9. Fileevent Problem

10. Again:Fileevent problem in Tk800.008 ? AND:How to put port events and user events together

11. Problem with fileevent and pipes

12. [Fwd: Re: fileevent/DoWhenIdle timing problem changing data?]

 

 
Powered by phpBB® Forum Software