http://qs321.pair.com?node_id=913229

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

Hi All,

I have developed a perl GUI application using Wx::Perl. The front end was developed using wxGlade and the application is working as expected when I run it from Padre or cmd. Now I want to build an exe of my application. So I used PAR::Packer (pp) to build the exe. After many attempts I was able to built an exe (I got many missing dll and Wx module error and I added them all manually).

Now I have got two issues:

1. The generated exe is not showing the GUI. It just exists after hanging for few seconds. No errors, nothing. After a long debugging/rebuilding I was able to find the cause. My main program is as bellow (It was generated by xwGlade)

package main; unless(caller){ local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $provisioning = provisioningChecklist->new(); $app->SetTopWindow($provisioning); $provisioning->Show(1); $app->MainLoop(); }

I found out that the exe is not entering the 'unless' block. If I comment out the 'unless' condition and rebuild the exe, GUI works.

So what is this 'caller' and why is it not running when I pack it using PAR::Packer, but works fine if it is run as normal perl script?

2. My Application uses a Marquee style progress bar while it populates the data in background. It is implemented using two threads. The logic is as below:

THREAD 1 enters a loop, generates an EVENT and sleeps for few milliseconds. The loop is controlled by a shared variable. The main program catches the EVENT and fires Wx::Gauge->Pulse;

THREAD 2 does the actual work and result is set in shared variable. An EVENT is fired and the main program catches it and populates the grid with the result. After all the work is done, shared variable is set to stop the THREAD 1 loop and an EVENT is generated to destroyed the progress bar.

This works fine when I run the script from cmd or Parde. But when I run the exe, progress bar window appears but the gauge is not moving. However the grid is populated with data. I am confused with the behaviour and dont know how to debug the exe. Any help on how to proceed further is greatly appreciated.

English is not my native language, hence forgive me for any mistakes and for the long post.

"Experience is the child of thought, and thought is the child of action."

Replies are listed 'Best First'.
Re: wxperl + PAR::Packer + GUI not working
by awwaiid (Friar) on Jul 07, 2011 at 19:48 UTC

    I don't know about the rest -- but for the 'caller' bit: caller() returns information about the sub that called the current sub. In the code that you gave, caller would normally return nothing when called as a regular script because nothing _called_ this code, instead this code is where everything starts.

    What must be happening is that in PAR there is some script that kicks off, and then does a 'do' or similar on your script.

    You might be able to illustrate this to yourself by dumping out a stack trace. Just above your 'unless', put:

    use Carp qw( cluck ); cluck('Dumping stacktrace!');

    That will print out the whole callchain. Now run your program directly, and then again from a PAR exe, and note the difference.

      Hello awwaiid,

      Yes, you are correct. I performed the step you told and following are the result:

      Stack output when the script is run normally

      Dumping stacktrace! at C:\Users\VPS3159Admin\Desktop\New folder\checkl +ist.pl line 897 Dumping stacktrace! at C:\Users\VPS3159Admin\Desktop\New folder\checkl +ist.pl line 899 Subroutine Wx::App::OnInit redefined at C:\Users\VPS3 +159Admin\Desktop\New folder \checklist.pl line 903.

      Stack output when from exe

      Dumping stacktrace! at script/checklist.pl line 897 require main called at C:/strawberry/perl/vendor/lib/PAR.pm li +ne 636 PAR::_run_member('Archive::Zip::ZipFileMember=HASH(0x329f3bc)' +, 1) cad at script/main.pl line 26 require main called at C:/s +trawberry/perl/vendor/lib/PAR.pm line 636 PAR::_run_member('Archive::Zip::ZipFileMember=HASH(0x329f58c)' +) callet C:/strawberry/perl/vendor/lib/PAR.pm line 428 PAR::import('PAR') called at -e line 953 eval {...} called at -e line 209 __par_pl::BEGIN() called at script/checklist.pl line 0 eval {...} called at script/checklist.pl line 0 Dumping stacktrace! at script/checklist.pl line 899 require main called at C:/strawberry/perl/vendor/lib/PAR.pm li +ne 636 PAR::_run_member('Archive::Zip::ZipFileMember=HASH(0x329f3bc)' +, 1) ca d at script/main.pl line 26 require main called at C:/strawberry/perl/vendor/lib/PAR.pm li +ne 636 PAR::_run_member('Archive::Zip::ZipFileMember=HASH(0x329f58c)' +) callet C:/strawberry/perl/vendor/lib/PAR.pm line 428 PAR::import('PAR') called at -e line 953 eval {...} called at -e line 209 __par_pl::BEGIN() called at script/checklist.pl line 0 eval {...} called at script/checklist.pl line 0

      When the script is run normally there is no caller, but when then the exe is executed main.pl calls my main program

      Thank you for your valuable input

      I am still debugging my second issue and will update here if I am able to fix it

      "Experience is the child of thought, and thought is the child of action."
Re: wxperl + PAR::Packer + GUI not working
by Anonymous Monk on Jul 07, 2011 at 21:40 UTC

      Hi

      I was able to fix my second issue by setting a gauge range.

      Initially the gauge range was set to 0, and there was no issue when the script is run normally like 'perl script.pl', but in the exe format gauge will not move with the pulse function call. The gauge area shows nothing.

      I set the gauge range to 100 after creating the object and now the gauge works, but it brought a new issue, the gauge style changed. If I run the script normally like 'perl script.pl', a small bar moves to and fro along the gauge area, but in the exe format bar first fills the entire gauge area and retrieves. I asked about it in the wxperl mailing list ( here ) and they said it could be due to an application manifest.

      I will try to fix it and will post here if I get a solution. May be it will be a help for someone else.

      Thank you for your valuable feedbacks Monks

      "Experience is the child of thought, and thought is the child of action."