It helps to reference vars within subroutines (my ( $kernel, $session,
$heap ) = @_[ KERNEL, SESSION, HEAP ];). Perhaps @_[HEAP] alone would
have worked, but chars are cheap.
$|++;
use strict;
use diagnostics;
use warnings;
use Tk;
use POE;
use Win32::Sound;
use POE::Component::SubWrapper;
POE::Session->create
( inline_states => {
_start => \&ui_start,
intro => \&welcome,
learn => \&ui_lesson,
demo => \&ui_demo,
}
);
$poe_kernel->run();
exit 0;
sub ui_start {
my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];
$_[HEAP]->{wl} = 1;
$poe_main_window->Label( -text => "Reading Teacher", -font =>
['arial', '36', 'bold'])->pack;
$poe_main_window->Button( -command => $session->postback("learn"),
-background => "green",
-activebackground => "green",
)->pack(
-ipadx => 75,
-ipady => 75,
-side => 'left',
-fill =>"x",
-expand => 1);
$poe_main_window->Button( -command => $session->postback("demo"),
-background => "red",
-activebackground => "red" )->pack(
-ipadx => 75,
-ipady => 75,
-side => 'left',
-fill =>"x",
-expand => 1);
POE::Component::SubWrapper->spawn('intro');
$kernel->delay( "intro", 1);
}
sub ui_demo {
my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];
$heap->{wl} = 0;
print "demo\n";
}
sub welcome {
my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];
if ($heap->{wl}) {
Win32::Sound::Play("rt.wav");
$kernel->delay("intro", 10);
}
}
sub ui_lesson {
my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];
$heap->{wl} = 0;
print "lesson\n";
}
Jpolache wrote:
> I am prototyping an application that (I hope) will teach people to
> read. As such, the interface will not use text. Instead, sound files
> will prompt the user. I decided to use Perl because Perl is what I
> normally use and have the most experience in.
>
> I am working on a Win32 platform because that is what I have and what I
> expect those I demo the application to would have. My only other
> experience with GUI app development was a trivial interface I banged
> out using Spectix.
>
> As of now, I am using Perl::Tk, Win32::Sound and POE. For starters, I
> am trying to set up a two button window (red for instructions and green
> to begin the lesson). I can get the window to come up and the intro
> wav file to play once, but I want the wav file to play in a loop (with
> a reasonable delay) until a button get clicked. I'm not sure how to
> pass messages (data, events, whatever) from one session (I think
> they're sessions) to another. Below is the code with my best guess as
> to what should be going on. Please not <something> on lines 36 and 55.
>
> Thanks for your help.
>
> - Jon
>
> $|++;
>
> use Tk;
> use POE;
> use Win32::Sound;
> use POE::Component::SubWrapper;
>
>
> POE::Session->create
> ( inline_states => {
> _start => \&ui_start,
> intro => \&welcome,
> lesson => \&ui_lesson,
> }
> );
>
> $poe_kernel->run();
> exit 0;
>
> sub ui_start {
> my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];
>
> $poe_main_window->Label( -text => "Reading Teacher", -font =>
> ['arial', '36', 'bold'])->pack;
>
> $poe_main_window->Button( -command => $session->postback("lesson"),
> -background => green,
> -activebackground => green,
> )->pack(
> -ipadx => 75,
> -ipady => 75,
> -side => 'left',
> -fill =>x,
> -expand => 1);
>
> $poe_main_window->Button( -command => {<something>} ,
> -background => red,
> -activebackground => red )->pack(
> -ipadx => 75,
> -ipady => 75,
> -side => 'left',
> -fill =>x,
> -expand => 1);
>
> POE::Component::SubWrapper->spawn('intro');
>
>
> $kernel->delay( "intro", 1);
> }
>
> sub ui_lesson {
> print "lesson\n";
> }
>
> sub welcome {
> while (<something>) {
> Win32::Sound::Play("rt.wav");
> $kernel->delay("", 15);
> }
> }