The problem is with Tk, on Win32 Tk's fileevent does
not work at all, and I believe POE uses Tk's fileevent
in order to cooperate with Tk.
The solution is to poll for Tk events and use the
default POE select loop.
First, make sure to include Tk AFTER POE, so POE wont
try and use Tk's event loop:
use POE;
use Tk qw(:eventtypes exit);
Then you need to create a session to poll for Tk's
events:
POE::Session->create(
inline_states => {
_start => \&tk_start,
_refresh => \&tk_poll,
}
);
sub tk_start {
my ( $session, $kernel, $heap ) = @_[ SESSION,
KERNEL, HEAP ];
$heap->{seconds_inactive} = 0; #number of seconds
to wait for user input before switching to idle mode
$heap->{refresh_rate} = 20; # number of gui
updates per second
$heap->{idle_refresh_rate} = 1; # number of gui
updates per second when idle
$heap->{time_until_idle} = 5; # number of seconds
before a lack of events engages idle mode
$kernel->yield( '_refresh' );
}
sub tk_poll {
my ( $session, $kernel, $heap ) = @_[ SESSION,
KERNEL, HEAP ];
if (MainWindow->Count) {
my $interval = 1 / $heap->{refresh_rate};
if (Tk::DoOneEvent(DONT_WAIT|WINDOW_EVENTS)) {
$heap->{seconds_inactive} = 0;
while
(Tk::DoOneEvent(DONT_WAIT|WINDOW_EVENTS|IDLE_EVENTS)){}#$test++;}
} else {
if ( $heap->{seconds_inactive} <
$heap->{time_until_idle} ) {
$heap->{seconds_inactive} +=
$interval;
} else {
$interval = 1 /
$heap->{idle_refresh_rate};
}
while
(Tk::DoOneEvent(DONT_WAIT|IDLE_EVENTS)){}
}
$kernel->delay( _refresh => $interval );
} else {
exit;
}
}
----------8<---SNIP---8<----------------
This code may be a little bit more complex than
necessary, with the whole idle thing and all, but it
is what I use and I don't have time to make a new
simpler example.
--- Laurent Perez <[EMAIL PROTECTED]> wrote:
> Hello
>
> I wrote a cool Perl/TK irc client, using
> POE::Component::IRC. It works fine
> on linux and bsd hosts.
> However I would like to run it on Win32 platforms
> (98, 2K and XP).
>
> I installed ActiveState's Perl build 635 on my Win32
> comp, then installed
> POE 0.26, POE::Component::IRC and Tk modules, using
> CPAN.
> When I try to run the program, it simply freezes. I
> was told Win32
> platforms had problems with Tk blocking events, but
> I was hoping latest
> builds of POE and AS could fix that.
>
> I had a look at some old 'non-blocking tk events
> under win32' example (the
> comic strip one), from the Mastering Perl/TK
> O'Reilly book. I understood
> author's tricks to run his code flawlessly on Win32,
> but sadly I don't even
> have the slightest idea of how to write similar code
> within POE environment
> (given I want to use PoCo::IRC+Tk). Win32 Modules
> used in that example are
> also very hard to find nowadays, even with google
> cache (it seems these are
> not maintained anymore), and don't even install on
> AS.
>
> So should I give up trying to run network+tk code
> within POE on Win32
> platforms because of that blocking problem, or is
> anyone able to help me
> using alternative coding methods, or should I try
> using cygwin ? I had a
> mail contact with AS Tk maintainers, it looks like
> they simply don't care
> about POE, so I don't know if it's POE or AS
> 'problem'.
>
> Any help would be greatly appreciated
> Thanks
>
> Laurnt Perez
>
>
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com