Hi!

I have written a small Tk GUI that follows some log files. I would like to
add the possibility to add and remove files on-the-fly. 
To do this, I added a menu where a user is provided with two menu items for
this:

[snip]
    my $logfiles = [ ... ]; # my personal list of files

    my $log_file_types = [
        ['Log Files',       ['.log', '.txt']],
        ['All Files',        '*',           ],
    ];

    my $menuitems = [
        [Cascade => "~Datei", -menuitems =>
            [
                [Button => "~Add file", -command => sub{
                    my $file = $poe_main_window->getOpenFile(-filetypes =>
$log_file_types);
                    if( $file ) {
                        # A file has been selected to be followed
                        push @{$logfiles}, $file;
                        add_file_to_watchlist( $heap, $file );
                    }
                    return 1;
                }],
                [Button => "~Remove file", -command => sub{
                        my $ident = magic_way_to_get_this();
                        delete $heap->{wheel}->{$ident};
                    }
                    return 1;
                }],
                [Separator => ""],
                [Button => "~Exit program", -command => sub{ exit(0); return
1; }],
            ],
        ],
    ];
    my $menu = $poe_main_window->Menu(-menuitems => $menuitems);
    $poe_main_window->configure(-menu => $menu);

sub add_file_to_watchlist {
    my ($heap, $logfile) = @_;
    
    # this ethod is called during the initial set-up, too.
    # some stuff here...

    # -- create new wheel
    $heap->{wheel}->{$logdatei} = POE::Wheel::FollowTail->new(
        Filename   => $ logfile,
        InputEvent => 'got_line',
        ErrorEvent => 'got_error',
        SeekBack   => 1024,
    );
    
    return;
} # /add_file_to_watchlist
    [/snip]

However, when I remove a file and add it again, it's not followed. If I add
another file, it's not followed either.
How do I do this? Is it possible?

The code (the uncut version) works fine when the program starts up. Only
adding files after the event loop has started doesn't work. Why?

What is the proper way of saying: "hey Perl, stop following that file" and
"hey Perl, start following this file" while the POE event loop is running?

Best regards,
Alex

Reply via email to