in reply to Creating new ptk windows with POE?
#!/usr/bin/perl use warnings; use strict; # Tk support is enabled if the Tk module is used before POE itself. use Tk; use Tk::ROText; use POE; use POE::Wheel::FollowTail; my $FILENAME = "z"; open (TAIL,">$FILENAME") or die; select(TAIL); my $ID; my $tl; POE::Session->create ( inline_states => { _start => \&ui_start, gotline => \&ui_read, ev_clear => \&ui_clear, writeline => \&ui_write, stopwrite => \&ui_stop, } ); $poe_kernel->run(); exit 0; sub ui_start { my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ]; $heap->{text_widget} = $poe_main_window->Scrolled('ROText',-scrollbars=>'ose' )->pack; $poe_main_window->Button ( -text => "Write to File", -command => $session->postback("writeline") )->pack; $poe_main_window->Button ( -text => "New Toplevel", -command => sub {my $tl = $poe_main_window->Toplevel(); $tl->geometry('300x100+100+100'); $tl->title( "Toplevel" ); } )->pack; $poe_main_window->Button ( -text => "Stop Writing to File", -command => $session->postback("stopwrite") )->pack; $poe_main_window->Button ( -text => "Clear Widget", -command => $session->postback("ev_clear") )->pack; $heap->{tail} = POE::Wheel::FollowTail->new ( Filename => $FILENAME, InputEvent => 'gotline'); } sub ui_read { $_[HEAP]->{text_widget}->insert('end',$_[ARG0]); $_[HEAP]->{text_widget}->insert('end',"\n"); $_[HEAP]->{text_widget}->see('end'); } sub ui_clear { $_[HEAP]->{text_widget}->delete('1.0','end'); } sub ui_write { $ID->cancel if ($ID); $|=1; $ID = $_[HEAP]->{text_widget}->repeat(1000,sub { print TAIL scalar gmtime,"\n"}); } sub ui_stop { return unless ($ID); $ID->cancel if ($ID); $ID = undef; $_[HEAP]->{text_widget}->insert('end',"Writing stopped....!!!!!\n\ +n"); } ######################################
|
|---|