After moving almost entirely to Ubuntu (I haven't booted Windows on my home computer for almost a month now :)), I searched for ways to create little applications which I can use at my workplace (in a mostly Windows environment). For command line scripts Perl worked out great (just a reminder to everyone, including myself: Perl has a module for everything including joining path parts in a platform dependent way, you just have to search CPAN), but I wanted to do a simple sticky-notes kind of program, so I looked around for GUI toolkits which work with Perl. Here are my findings:
- Perl/Tk - is well supported with packages available for both Linux and Windows (including through the PPM, because CPAN can be a pain in the rear end to use on Windows). Has some good articles and presentations about it, however I couldn't find a visual designer for it (I did find this, however I never managed to get it working). Also a lesser (but still existing) problem is that the controls don't look the way native controls look on any platform.
- wxPerl - the Wx toolkit. No Windows version of the Perl bindings (or at least not through the PPM), so this one is out.
- Gtk2-Perl - This is the one I ended up using. While not perfect (see below the list of problems and solutions I found), it works cross platform and has a visual editor.
Under Linux it's pretty much preinstalled if you use a Gnome based desktop (like Ubuntu does). If not, you should install the
libgtk2-perl package with
apt-get (or Synaptic) rather than trying to install it using CPAN. To install the interface designer, mark the
glade-gnome package for installation.
Under Windows it's a little more tricky: the first step is to add the gtk2-perl PPM repository (http://gtk2-perl.sourceforge.net/win32/ppm/) to your list of PPM repositories. Now try to install the Gtk2 package. It may complain about some unresolved dependencies. Go and manually mark them for installation (usually the PPM takes care of this, but for some mysterious reason it didn't do it for me this time, so you might encounter the same problem). Make sure to install the latest version of the Gtk2 package (1.100 at the moment of writing this article). Next you will need the the Gtk2 libraries for Windows. You can get it either at the GIMP Windows installer project page or at the Glade for Windows page. One very important detail (which I found out after several days of cursing) is the fact that the latest version of the Perl libraries which is available for Windows (1.100) is incompatible with the latest version of the Gtk2 toolkit. This issue has been resolved in version 1.120, but that isn't available currently as a PPM package. So make sure that you use the 2.6 branch of the Gtk2 toolkit for Windows to avoid headaches.
There are two ways to install the Gtk2 toolkit on windows: using the installer or downloading and extracting from the archive. The first is ok if you don't have other programs which rely on the latest version of Gtk2 (like GIMP or Gaim), but probably the second method is more safe: download the installer from the Gladewin site and extract it on a test computer. Copy the files from the installation location (
C:\GTK by default), then uninstall the products. Now do the following things: copy all the DLLs from the bin folder to the bin folder of your Perl installation (
C:\Perl\bin by default). Copy the the etc folder to your Perl directory (e.g. to
C:\Perl). Copy the lib folder to your Perl directory (which already contains a lib folder, but don't worry, there is nothing to overwrite since it should contain a single subfolder named pango). Congratulations! Now you have created a portable environment for your GUI scripts, which can be deployed with XCOPY (that is, copying the whole Perl folder to a new computer).
Some more tips
Bear in mind that I'm a beginner to, so these may contain errors or useless (or flat out wrong) advice:
- Use Glade to create your interface and the Gtk2::GladeXML module to load the design. It will save you a lot of trial and error (under Windows you will need to download libglade and place it in either the system directory or - the way I prefer it - where the Perl executable is located -
- Gtk2 arranges the controls itself much like Swing does and it can be confusing if you are used to the Delphi or Visual Studio designer. However once you get the hang of it, you will appreciate the fact that your form layout looks good even when the form is resized.
- There is an extensive documentation available, however it consists mostly of property listings without any additional explanations. It can also contain properties / methods which are not available in the older version of the library you are stuck with under Windows. There are also several tutorials, the best of which in my humble opinion is the Gtk2-Perl Study Guide.
- For some reason which is beyond me, unless you put an element in the designer in the ComboBox, the inner list representing the elements won't be created. So make sure to put an element in it and then remove it using the
remove_textmethod with the parameter
0. This may also apply to other elements.