Perl

ID #1058

Using a GUI for Perl on Windows

Perl is great from the command line, sure... but if you need to create a utility script for a non-technical end-user, it's good to make it a bit more comfy-cozy than an old fashioned DOS prompt.., with windows, buttons, scroll bars and more!

For this you'll need two ingredients -- the Win32::GUI for programming your stuff, and something along the lines of the GUI-Loft to build your interface.

1. Get Win32::GUI

If you're using Perl on Windows, you're probably using ActiveState's ActivePerl. They have a neat little utility (written in perl, of course) called PPM (Perl Package Manager) that makes installing things a snap. You can still use cpan, of course, but when that doesn't work, try PPM.

First you'll need to find Win32::GUI, so go google for it. As of April 2008, the most modern version is at sourceforge.

You'll notice that there are several versions to choose from -- there's one for perl 5.6, another for perl 5.8 and yet another for perl 5.10. To find your version of perl, try this from the command line:

> perl -v
This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)

Our version of perl is 5.10, so we download the 5.10 instance of Win32::GUI.

It comes as a ZIP file; un zip the contents to the directory of your choice, then CD to that directory and:

C:\path\to\Win32-GUI-1.06-PPM-5.10> ppm install ./Win32-GUI.ppd
Unpacking Win32-GUI-1.06...done
Generating HTML for Win32-GUI-1.06...done
Updating files in site area...done
 322 files installed

Note that although you refer only to the *.ppm file on the command-line, there are other files that are needed to do the real work (notably the *.gz file):

> dir
04/02/2008  06:10 PM            57,406 Changelog.txt
04/02/2008  06:10 PM             8,717 Readme.html
04/02/2008  06:10 PM             5,530 Readme.txt
04/02/2008  06:10 PM               402 Win32-GUI.ppd
04/02/2008  06:10 PM         1,856,293 Win32-GUI.tar.gz
               5 File(s)      1,928,348 bytes

And with that, you should be ready to write GUI code:

> perl -MWin32::GUI -e 'print Win32::GUI::Version'
1.06

Success!

Now we need to get an niterface-builder working, and GUILoft might just be the ticket.

2. Get GUILoft

You might try googling for Gui Loft and wind up at a bad link, as there are lots of pointers still referring to the original site, which is now defunct. Instead -- as of April 2008 -- try http://www.darserman.com/Perl/Loft/ and you might have more luck.

Download the LOFT_BINARY.ZIP and read some of the docs there while you're at it. With the GUI Loft you'll be able to arrange windows, buttons, scroll bars, tabs, labels, list boxes and more... and your Win32::GUI code can make it dance!

Note that in order for a windows computer to be able to USE yuor gui-loft files, they must have gui-loft installed as well.

So:

  1. download the binary (zip) Gui Loft from http://www.darserman.com/Perl/Loft
  2. un-zip it
  3. open a command line, change to the directory where the new folder is and PPM INSTALL both the ADHOC modules and the LOFT:
    C:\Loft_binary\TheGUI Loft\PPM\AdHoc>ppm install Win32-GUI-AdHoc.ppd
    Unpacking Win32-GUI-AdHoc-0.04...done
    Generating HTML for Win32-GUI-AdHoc-0.04...done
    Updating files in site area...failed
    ppm install failed: File conflict for 'C:/Perl/html/site/lib/Win32/GUI/BitmapInline.html'.
        The package Win32-GUI has already installed a file that package Win32-GUI-AdHoc
        wants to install. Uninstall Win32-GUI, or use --force to allow files
        to be overwritten.
  4. It may gripe about file conflicts; to override normal paranoia and proceed with wild abandon, use "--force":
    C:\Loft_binary\TheGUI Loft\PPM\AdHoc>ppm install --force Win32-GUI-AdHoc.ppd
    Unpacking Win32-GUI-AdHoc-0.04...done
    Generating HTML for Win32-GUI-AdHoc-0.04...done
    Updating files in site area...done
      20 files installed
       2 files updated
  5. Now do the same for the Loft itself:
    C:\Loft_binary\TheGUI Loft\PPM\AdHoc>cd ..\Loft
    C:\Loft_binary\TheGUI Loft\PPM\Loft>ppm install --force Win32-GUI-Loft.ppd Unpacking Win32-GUI-Loft-0.23...done Generating HTML for Win32-GUI-Loft-0.23...done Updating files in site area...done 66 files installed 1 file updated
  6. Voila!

One more thing -- Install Win32::API as well

Most likely you will still run into errors...

C:\path\to\your\script> perl my-gui-script.pl
Can't locate Win32/API.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at C:/Perl/site/lib/Win32/GUI/AdHoc.pm
 line 30.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Win32/GUI/AdHoc.pm line 30.
Compilation failed in require at C:/Perl/site/lib/Win32/GUI/Loft/Control/Checkbox.pm line 22.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Win32/GUI/Loft/Control/Checkbox.pm line 22.
Compilation failed in require at C:/Perl/site/lib/Win32/GUI/Loft/Design.pm line 50.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Win32/GUI/Loft/Design.pm line 50.
Compilation failed in require at my-gui-script.pl line 7.
BEGIN failed--compilation aborted at my-gui-script.pl line 7.

That's something you can fix, no problem:

C:\path\to\your\script> ppm install Win32::API
Downloading ActiveState Package Repository packlist...not modified
Downloading Win32-API-0.50...done
Unpacking Win32-API-0.50...done
Generating HTML for Win32-API-0.50...done
Updating files in site area...done
  18 files installed

And there you go:

C:\path\to\your\script> perl my-gui-script.pl
[window displays, all nice and pretty]

Now you should be able to execute the *.gld files generated by the Gui Loft.

Last update: 2008-04-03 18:31
Author: will trillich
Revision: 1.0

Print this record Print this record
Send to a friend Send to a friend
Show this as PDF file Show this as PDF file
Export as XML-File Export as XML-File

Please rate this entry:

Average rating: 2.59 out of 5 (73 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry