cmv has asked for the wisdom of the Perl Monks concerning the following question:

Folks-

My perl program creates a bunch of ptk top-level windows. Before using POE, I simply called MainWindow->new for each new window I wanted to create. Now that I'm using POE, I'm given a single Tk MainWindow, pointed to by $poe_main_window. How do I create more?

Using $poe_main_window->new creates some ugly error messages - that can't be right.

I can use MainWindow->new and do get the new windows created, but the scrollbars in them don't work correctly (I'm guessing this is one of the "undesired outcomes" alluded to by the POE::Kernel docs).

Obviously I'm missing something here.

Any help is appreciated!

Thanks

-Craig

Replies are listed 'Best First'.
Re: Creating new ptk windows with POE?
by zentara (Cardinal) on Jan 24, 2008 at 19:23 UTC
    I'm not familiar with POE, but from reading your post, it seems you want to create multiple Tk MainWindows. The MainWindow is associated with the Tk eventloop, so POE may be getting confused as to which Tk-eventloop it controls.. I would try creating 1 MainWindow, then create additional Tk windows as Toplevels instead of MainWindows. I just grabbed this POE-Tk file-tail code (by Jack D) to demonstrate. I added a Create Toplevel Button.
    #!/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"); } ######################################

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum