in reply to POE, Tk, Simultaneous problem!
Part of your problem is that you are starting up two event loops which don't seem to be yielding control to each other. Using Tk under POE ia a different kettle of fish from using it directly. You need to constantly be aware what part of the event loop has control and to delegate control to the appropriate event handlers when necessary.
Maybe this will help illustrate. Here's a contrived example. A text widget is constantly being filled with random numbers while being searched for strings of 12 odd digits in a row. When one is found, it pauses until you tell it to search again.
use warnings; use strict; use Tk; use POE; POE::Session->create ( inline_states => { _start => \&startApplication, search_again => \&search_again, search => \&searchUpdate, } ); $poe_kernel->run(); exit 0; sub startApplication { my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ]; $poe_main_window->Label( -text => 'Search for at least 12 odd random digits in a row' )->pack; $heap->{text} = $poe_main_window->Text->pack(-expand => '1', -fill + => 'both'); $heap->{text}->tagConfigure('highlight', -background => 'orange'); $heap->{search_run} = 1; $heap->{search_index} = '1.0'; $poe_main_window->Button( -text => "Search Again", -command => $session->postback('search_again') )->pack; $kernel->yield('search'); } sub searchUpdate { if ($_[HEAP]->{search_run}){ my $count; my $search_index = $_[HEAP]->{text}->search( '-regexp', -count => \$count, '--', '[13579]{12,}', $_[HEAP]->{search_index}, $_[HEAP]->{search_index}.' lineend' ); if ($search_index){ $_[HEAP]->{text}->tagAdd('highlight', $search_index, $sear +ch_index." +$count".'c'); $_[HEAP]->{search_run} = 0; $_[HEAP]->{search_index} = $_[HEAP]->{text}->index($search +_index."+$count".'c'); } if ($_[HEAP]->{search_run}){ my $line; for (0..69){ $line .= int rand 10; } $_[HEAP]->{text}->insert('end',"$line\n"); if ($_[HEAP]->{text}->index('end') > 25){ $_[HEAP]->{text}->delete('1.0','1.0 lineend +1c'); $_[HEAP]->{search_index} = '1.0'; } } } $_[KERNEL]->yield('search'); } sub search_again { $_[HEAP]->{text}->tagRemove('highlight', '1.0', 'end'); $_[HEAP]->{search_run} = 1; $_[KERNEL]->yield('search'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: POE, Tk, Simultaneous problem!
by Ace128 (Hermit) on Sep 28, 2005 at 21:21 UTC |