perlmeditation
Jouke
There have been quite a few questions and remarks concerning building
Windows-like programs in Perl. I don't know everything about all facets of this,
but I hope this thread will be a kind of a FAQ-like thread to prevent some
questions from being asked over and over again.<br><br>
<b>1. Can I build a GUI around my Perl program?<br></b>
-> Yes you can. There are several different options:<br>
a) [cpan://Tk]. Tk is the widest used GUI toolkit for Perl. O'Reilly has a book
on it (although I heard it is discontinued), and a lot of resources on it are
available. Tk is portable between Win32 and Unix variants.<br>
b) [cpan://Gtk]. Gtk does not run on Win32. But for Gnome minded people it's a
very nice GUI toolkit. It should be possible to port it to Win32 though. After
all the Gimp is ported to Win32, and Gtk is based on the Gimp's widgetset.<br>
c) [cpan://Win32::GUI]. Win32::GUI is (of course) only available on Win32. It's
a toolkit to access all of Windows GUI api.<br>
d) <a href="http://wxperl.sourceforge.net">wxPerl</a>. wxPerl is based on <a
href="http://www.wxwidgets.org">wxWidgets</a>, a crossplatform GUI api. It
really takes the look and feel of the platform it runs on, Win32, Motif, Gtk or
MacOS.<br>
e) <a href="http://perlqt.sf.net">Qt</a> is available with Perl support now too. KDE support is planned but not yet available.<br><br>
<b>2. Aren't there more GUI toolkits?<br></b>
-> Yes there are, but either old and (?) unmaintained, or very new:<br>
[cpan://X11::Fvwm] Last update 1997!<br>
[cpan://X11::Lib] Last update 1998!<br>
[cpan://X11::Protocol] Last update 1998!<br>
[cpan://X11::Xforms4Perl] Link does not work, but module can be found on CPAN (by-module)<br>
[cpan://Prima] Very new. Has anyone tried it?<br><br>
<b>3. Where are the FAQ's on the toolkits?</b><br>
-> Not every toolkit has a FAQ as far as I've found out:<br>
a) Tk's FAQ is at [http://www.cpan.org/authors/id/C/CL/CLAIRD/ptkFAQ.html] (<b>very outdated!</b>)<br>
b) Gtk's FAQ is nowhere to be found... <br>
c) Win32::GUI's FAQ is at [http://www.jeb.ca/faq/Win32-GUI-FAQ.html]<br>
d) wxPerl's FAQ is not yet written. There is however a <a href="http://wxperl.pvoice.org">wxPerl Wiki</a><br>
e) perlQt's FAQ is at [http://perlqt.sourceforge.net/index.php?page=faq]?<br><br>
<b>4. What GUI api is the best?<br></b>
-> That depends on your personal preferences. Tk is the oldest and normally the
most stable GUI available for Perl. It's also the best documented. Gtk is good
if you only want to run on Gnome platforms. Win32::GUI gives you access to all
of window's GUI functions and wxPerl is the most portable and the most Object
Oriented, for people who like that.<br><br>
<b>5. Are there any GUI builders available?<br></b>
-> Yes there are. To name at least one for every toolkit I mentioned:<br>
a) For Tk there is <a
href="http://keck.ucsf.edu/~kvale/specperl.html">SpecPerl</a> and
<a href="http://guido.sourceforge.net/">Guido</a> (alpha stage)<br>
b) for Gtk there is <a
href="http://www.glade.perl.connectfree.co.uk/index.html">Glade-Perl</a> and
<a href="http://perlcomposer.sourceforge.net">PerlComposer</a><br>
c) for Win32::GUI there is [jplindstrom]'s <a
href="http://www.bahnhof.se/~johanl/perl/Loft/">The GUI Loft</a> and <a
href="ftp://ftp.wh.whoi.edu/pub/gb109.zip">GB</a><br>
d) for wxPerl there is <a href="http://wxglade.sf.net">wxGlade</a>, a GUI designer for wxPerl, wxPython and others. wxPerl support for wxGlade was added by [PodMaster] aka [crazyinsomniac].<br />
Then there's also the (non-free) <a
href="http://www.roebling.de/">wxDesigner</a><br>
e) for perlQt there is <a href="http://perlqt.sourceforge.net/dist/current/doc/en/index.html#rad%20prototyping%20with%20qt%20designer%20and%20puic">Puic</a><br><br>
<b>6. Can I compile my Perl program?<br></b>
-> Yes you can. However, except for <code>perlcc</code> (see below) none of the mentioned methods will really compile your code to machine code. The mentioned tools merely wrap up your code with the nessecary modules and the Perl interpreter and put them inside a standalone executable.<br />
Therefore it's not suitable for hiding your sourcecode, but it's very useful when you want to distribute your script without having your end-users installing Perl and a bunch of CPAN modules<br />
I think the best option for this these days is [cpan://PAR]. PAR is portable (runs on Win32 and (as far as I know) all Unix-like OSses), and using the 'pp' tool you can create standalone executables.<br />
Then there's also:<br />Perl ships with <code>perlcc</code> which needs a C-compiler to
actually do the final compilation, but it works most of the time for simple
programs.<br>
Then there is <a href="http://www.perl2exe.com">Perl2Exe</a> which can do more
than just build the 'exe' for a Win32 environment. It's available for many other
platforms, including Linux, Solaris and AIX.<br>
Also <a href="http://www.activestate.com">Activestate</a> has its <a
href="http://www.ActiveState.com/Products/Productivity/Perl_Dev_Kit/">Perl
Development Kit</a>, which includes PerlApp. PerlApp can build binary executables
for Win32 (though the compilation itself has to be done on an NT platform, not
Win95/98), Linux and Solaris.<br><br>
<b>7. Can I create some nice distribution like a MSI or an Installshield wizard?<br></b>
-> Activestate's Perl Development Kit includes PerlMSI. I haven't used it, but
according to the description on the website it is possible to create MSI's
easily with that.<br>
Besides that there is <a href="http://www.jrsoftware.org/isinfo.htm">InnoSetup</a> a
free, Open Source Installshield clone. It is *very* easy to use and allows you
to build a nice installer around your program.<br><br>
Another free tool (just like the previous one not related to Perl in any way) is <a href="http://nsis.sourceforge.net/home/">NSIS</a>, the NullSoft Scriptable Install System. As far as I've heard you can do even more with this than with InnoSetup, but I've never used it so far.<br><br>
<b>8. When I run my GUI script, a console window pops up and stays there until I close my program. How can I prevent this?</b><br />
-> There are two options: either use wperl.exe instead of perl.exe (wperl.exe is distributed with ActiveState's Perl), or compile your code using one of the tools mentioned in answer 6 using the --gui option.<br /><br />
<b>9. When I <code>warn</code> or <code>die</code> all messages go to the console window or aren't displayed at all. How can I see what warnings or errors my GUI script gives?</b><br />
-> When you 'compiled' your script with PAR, PerlApp or Perl2Exe so it doesn't display a console window (the --gui option), warnings and errors aren't displayed anywhere. This is also the case when you use wperl.exe (distributed with ActiveState Perl) to run your script<br />
However when you're using wxPerl, you can use [cpan://Wx::Perl::Carp] by [PodMaster] which captures your errors and warnings and displays them in a GUI dialog.<br />
For Tk, there's [Tk::Carp], and for Win32::GUI there's [Win32::GUI::Carp] (both by [bbfu])<br /><br />
<b>10. Do you have any useful outside links?<br></b>
-> Here are a few. If you have any additions to these, please /msg me and I'll add them<br>
<a href="http://www.perltk.org/">Perl Tk homepage</a><br>
<a href="http://www.gtkperl.org/">Gtk Perl homepage</a><br>
<a href="http://wxperl.sourceforge.net/">wxPerl homepage</a><br>
<a href="http://dada.perl.it/">Win32::GUI homepage</a><br>
<a href="http://homepage.tinet.ie/~jmcnamara/perl/dfm2gui.html">[jmcnamara]'s dfm2gui</a><br>
<a href="http://www.perl.com/pub/a/2001/03/gui.html">Writing GUI Applications in Perl/Tk (Perl.com article)</a><br>
<a href="http://personal.riverusers.com/~swilhelm/gtkperl-tutorial/">Gtk Perl Tutorial</a><br>
<a href="http://www.perl.com/pub/a/2001/09/12/wxtutorial1.html">first wxPerl tutorial on Perl.com</a>
<b>Updates:</b>
<ul><li>fixed the link to InnoSetup (thx [mirod]!)</li>
<li>corrected the name of The GUI Loft (thx [jplindstrom!])</li>
<li>(2001/09/03) Added info on Guido</li>
<li>(2001/09/03) Added info on PerlComposer</li>
<li>(2001/09/03) Added 6th question</li>
<li>(2001/09/04) Added 'Other GUI toolkits'</li>
<li>(2001/09/04) Reshuffled the questions</li>
<li>(2001/09/04) Added outside links</li>
<li>(2001/12/10) Added outside link to wxPerl tutorial</li>
<li>(2004/04/05) Added link to perlQt</li>
<li>(2004/04/05) Added link to wxGlade</li>
<li>(2004/04/05) Added info about PAR</li>
<li>(2004/04/05) Added question 8 and 9</li>
<li>{2004/05/11) Changed wxWindows to wxWidgets (new name)</li>
<li>(2004/07/27) Fixed the link for wxGlade</li>
</ul>
<br><br>
<i>Jouke Visser, Perl 'Adept'</i><br>
<small>Using Perl to help the disabled: <a href="http://www.pvoice.org">pVoice and pStory</a>