Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Folks-

Can anyone use perlapp and successfully build a working *.exe for any perl script that uses both POE and Tk?

I can't, and am very confused and frustrated.

Step 1: Get a working Perl/POE/Tk program not written by me (...well mostly)

The POE Cookbook is the most logical place to find something. Unfortunately the existing sample program doesn't work on either MacOS or Windows right out of the box (the GUI window never shows up). I had to add some (poe_main_window->update)'s in it to give it basic functionality. I also added a check to error out if poe_main_window is not defined (for reasons that will become apparent later on). This version seems to work fine:
# http://poe.perl.org/?POE_Cookbook/Tk_Interfaces # # This sample program creates a very simple Tk counter. Its interface # consists of three widgets: A rapidly increasing counter, and a # button to reset that counter. use warnings; use strict; # Tk support is enabled if the Tk module is used before POE itself. use Tk; use POE; # Create the session that will drive the user interface. POE::Session->create ( inline_states => { _start => \&ui_start, ev_count => \&ui_count, ev_clear => \&ui_clear, } ); # Run the program until it is exited. $poe_kernel->run(); exit 0; sub ui_start { my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ]; if(! defined($poe_main_window)) { die "\$poe_main_window not defin +ed" }; $poe_main_window->Label( -text => "Counter" )->pack; $heap->{counter_widget} = $poe_main_window->Label( -textvariable => \$heap->{counter} )->p +ack; $poe_main_window->Button ( -text => "Clear", -command => $session->postback("ev_clear") )->pack; $poe_main_window->update; $kernel->yield("ev_count"); } # Handle the "ev_count" event by increasing a counter and displaying # its new value. sub ui_count { $_[HEAP]->{counter}++; $poe_main_window->update; sleep(1); $_[KERNEL]->yield("ev_count"); } # Handle the "ev_clear" event by clearing and redisplaying the # counter. sub ui_clear { $_[HEAP]->{counter} = 0; }

Step 2: Figure out how to use perlapp on it

This wasn't as easy as I thought it should be. At first, I just simply kept on adding modules using the --add module command-line options for perlapp. I ended up with this:
perlapp --add "POE::Wheel" --add "POE::Loop::Tk" --add "POE::Loop::Sel +ect" --add "POE::Resource::Aliases" --add "POE::Resource::Events" --a +dd "POE::Resource::Extrefs" --add "POE::Resource::FileHandles" --add +"POE::Resource::SIDs" --add "POE::Resource::Sessions" --add "POE::Res +ource::Signals" --add "POE::Resource::Statistics" --add "POE::Session +" --add "POE::Driver::SysRW" --add "POE::Filter::Line" --verbose --cl +ean --force --lib lib --exe tst121.exe tst121.pl
Which will successfully create a windows executable for me.

However, anytime it is run it will die claiming that poe_main_window is not defined (remember the error check I added?). Oh, and also note that the *.pl script works fine and the *.exe doesn't on the same machine. Grrrrr.

Step 3: Google

As is typical for me, I resort to finding others who've solved the same problems that I'm experiencing. Hmmm, not a lot of useful stuff here. Lots of old links talking about using the POE::Preprocessor which doesn't seem to be around anymore (according to this web page).

In fact, I have already asked about this problem here at perlmonks, without really knowing it is a poe_main_window problem. In that code, you'll notice I did a sneaky thing with the lines:

# WHY DO I HAVE TO DO THIS???? my $top = $poe_main_window || MainWindow->new();
In Rocco's response he questioned this, but I never followed up (Note-to-self: NEVER use MainWindow->new() when POE is in the mix...).

Step 4: Perlmonks

Ask the experts.

So... it it possible to do this, and if so, how?

Many thanks!

-Craig


In reply to POE & Tk totally confound perlapp (or am I missing something?) by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found