Developing and Distributing wxPerl Applications on Windows: Difference between revisions

From Perl Guilds - Getting Medieval with Perl
Jump to navigation Jump to search
No edit summary
No edit summary
Line 43: Line 43:
https://www.python.org/ftp/python/3.12.8/python-3.12.8-amd64.exe ([https://www.python.org/downloads/windows/ linked here])
https://www.python.org/ftp/python/3.12.8/python-3.12.8-amd64.exe ([https://www.python.org/downloads/windows/ linked here])


=== Step 2 - Download and unzip wxGlade ===
=== Step 2 - Install wxPython ===
 
# open up the Windows CMD window
# use pip,
 
<big><code>C:\> pip install wxPython</code></big>
 
'''Note''': if this fails, you may need to reinstall pip; but it should be available in the CMD window. Based on experience, pip doesn't seem to be available via the Strawberry Perl terminal, so be sure to get a standard Windows CMD window to do this part.
 
=== Step 3- Download and unzip wxGlade ===
https://github.com/wxGlade/wxGlade/archive/refs/tags/v1.1.0.zip
https://github.com/wxGlade/wxGlade/archive/refs/tags/v1.1.0.zip



Revision as of 15:35, 24 January 2025

Introduction

This article is about installing wxPerl under Strawberry Perl for application development and distribution as a Windows executable.

wxPerl GUI running on Windows as a double-clicable EXE file!
wxPerl GUI running on Windows as a double-clicable EXE file! Created using RAD-ish tool, wxGlade. See more images on Github.

Instructions are provided with the versions detailed below. If there are newer versions of any of the modules, you may try it out (of course); but understand they have not been tried out and shown to work like version combinations below.

Installation

Step 1 - Install Strawberry Perl

Install via following link,

https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/download/SP_54001_64bit_UCRT/strawberry-perl-5.40.0.1-64bit.msi

Step 2 - Install Alien::wxWidgets (v 0.70)

Once Perl is installed, look in the Start menu for the Perl "cmd" window or open up PowerShell

  • go to "Start menu" > Strawberry Perl > "Perl (command line)"
  • click the Start menu item, it'll open up a Windows CMD window (traditional black DOS prompt)

Type the command at the "C:" prompt,

C:\> cpanm --verbose https://github.com/sciurius/wxPerl/releases/download/R3.004/Alien-wxWidgets-0.70.tar.gz

Step 3 - Install Wx (v 3.005)

C:\> cpanm --verbose https://github.com/sciurius/wxPerl/releases/download/R3.005/Wx-3.005.tar.gz

Verify Installation

Install Wx::Demo

Wx::Demo is nice demonstration application, highlight many (if not all) of the wxWidget features available via xPerl.

C:\> cpanm --verbose Wx::Demo

.. then once installed, run it with this command (which is available in the PATH already),

C:\> wxperl_demo.pl

Install wxGlade

wxGlade is a GUI builder for wxWidgets applications. It is written in Python, but critically supports outputing Perl code. It is actively developed, the developer is very responsive on Github to bugs and feature requests. It is the closest thing we have in Perl to a RAD (rapid application development) environment (e.g., Lazarus for FreePascal).

Step 1 - Install Python 3.12 for Windows

Install via following link,

https://www.python.org/ftp/python/3.12.8/python-3.12.8-amd64.exe (linked here)

Step 2 - Install wxPython

  1. open up the Windows CMD window
  2. use pip,

C:\> pip install wxPython

Note: if this fails, you may need to reinstall pip; but it should be available in the CMD window. Based on experience, pip doesn't seem to be available via the Strawberry Perl terminal, so be sure to get a standard Windows CMD window to do this part.

Step 3- Download and unzip wxGlade

https://github.com/wxGlade/wxGlade/archive/refs/tags/v1.1.0.zip

Via Windows CMD terminal, navigate to the unzip'd directory and run the command,

C:\> python wxglade.py

Development Workflow Notes

Packaging and Distributing Windows Executables

This section is more of a work in progress since a reliable method of distributing single file executables (or developing installation packages for Windows) is still an open question, there is hope that this will end up being a relatively smooth process. Needless to say, it is critical for Perl developer to be able to distribute Perl based GUI applications as single file (.exe) or via installation on Windows. The client should NOT need to be running through any of the instructions above to run a program that you would like to sell them for actual money.

Below are the initial instructions for generating an EXE file.

Step 1 - Install PAR::Package and Wx::Perl::Packager

C:\> cpanm --verbose PAR::Package Wx::Perl::Packager

Step 2 - Generate the EXE

Assuming you have a Perl script generated either via wxGlade (see above) or one you have created/updated by hand, the command is as follows:

C:\> wxpar YOURPROGRAM.pl -o YOURPROGRAM.exe

Important Notes About wxGlade Generated Code

  1. earlier versions of wxGlade introduced an improper idiom at the bottom of the generated Perl script that caused a problem when running via a PAR::Packed packed executable. TLDR; remove the "unless(caller)" block and just run the Wx event loop unfettered. For more information, please read the PAR::FAQ.
  2. earlier versions of wxGlade also used a non-Exporter import tage that wxpar could not properly follow; see the code "before" and "after" below:
use Wx qw[:allclasses];
use strict;

...

package main;

unless(caller){
    my $local = Wx::Locale->new("English", "en", "en"); # replace with ??
    $local->AddCatalog("app"); # replace with the appropriate catalog name

    my $app = MyApp->new();
    $app->MainLoop();
}

Should be modified to look like the following:

use Wx qw;
use strict;

...

package main;

my $local = Wx::Locale->new("English", "en", "en"); # replace with ??
$local->AddCatalog("app"); # replace with the appropriate catalog name

my $app = MyApp->new();
$app->MainLoop();

See this Github issue for wxGlade, where both were fixed. At the time of this writing, the changes. have not been put out in an official release; but they are applied in the master branch.