Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thanks all,
I put the following together using the tips from perldoc -q "tail -f". As a POE user I was under the impression that the Tk tail would fail on Win32 due to the lack of fileevent - I haven't used it recently so it may be fixed.

This first version hangs onto the filehandle as you say so it needs some thought to emulate --follow=name.

#! perl use strict; use warnings; use Tk; # my $file = "C:\\openejb-0.8.3\\openejb.log"; # my $title = "Tk Tail"; my $version = "1.0"; my $mw = new MainWindow( -title => $title ); # Nicer fixed-width font... $mw->fontCreate( 'listboxfont', -family => 'courier', -size => '8' ); my $fr = $mw->Frame()->pack( -expand => 1, -fill => 'both' ); # $fr->Label( -text => "File to tail" )->pack; $fr->Entry( -textvariable => \$file, -width => '50', -font => 'listboxfont', )->pack; $fr->Button( -text => 'GO', -command => \&gopush )->pack; my $listbox = $mw->Scrolled( 'Listbox', -setgrid => '1', -height => '10', -width => '50', -font => 'listboxfont', -selectmode => 'extended', -scrollbars => 'se', -bg => 'black', -fg => 'green', ); $listbox->pack( -expand => 'yes', -fill => 'both', -pady => '3' ); my $fr_statusbar = $mw->Frame( -relief => 'sunken', -borderwidth => '1', )->pack( -fill => 'x' ); #~ $fr_statusbar->Label( -image => $smallicon )->pack(-side => 'left') +; $fr_statusbar->Label( -text => "Version: $version" )->pack( -side => ' +left' ); # sub gopush { close F; open F, '<', $file or die $!; timerstart(); } # repeating actions... my $timerid; sub timerstart { &timerstop(); $timerid = $mw->repeat( 1000, \&timerproc ); } sub timerstop { if ($timerid) { $timerid->cancel; } } sub timerproc { while (<F>) { chomp; my $text = $_; $listbox->insert( 'end', $text ); $listbox->see('end'); $mw->update(); } seek( F, 0, 1 ); } MainLoop();

In reply to Re: POE, was Re: Tk tail -f - How? by msemtd
in thread Tk tail -f - How? by msemtd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (4)
    As of 2020-10-30 13:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (279 votes). Check out past polls.

      Notices?