Should I be building GUI applications on Windows using Perl & Tk? - perl

I have a bunch of related Perl scripts that I would like to put together in one convenient place. So I was thinking of building a GUI and incorporating the scripts. I'm using Strawberry Perl on Windows XP and have just installed Tk from cpan about fifteen minutes ago. Before I go for it, I want some sound advice either for or against it.
My other option is to translate the Perl scripts into VB and use Visual Studio 2008, but that might be too much hassle for an outcome that might end up all the same had I just stuck with Perl & Tk.
I haven't looked yet, but maybe there is a module for Visual Studio that would allow me to invoke Perl scripts?
The main requirements are:
It must be able to communicate with MySQL
It must be able to fetch & parse XML files from the internet
It must be transportable, scalable, and sustainable
What direction would you take?

I've built Perl/Tk apps on Windows before and found it just fine, including using PAR to package everything up for distribution to others. It was nice being able to do most of my development on a proper Linux system and have things just magically work on Windows :) The only gotcha I encountered is that Tk doesn't play well with ithreads.

I personally would recommend wxPerl over Tk. It has native looking widgets, at least in my view leads to cleaner code and you can use wxGlade as a GUI designer.

If you haven't programmed with Perl/Tk I would think that Tkx (developed by Activestate) would be a better option. Tkx is a thin layer over Tcl/Tk, which gives it access to the new themed widgets in Tcl/Tk so your application would look better.
Perl/Tk has a lot more documentation around, but the module itself does not seem to be developed anymore. The documentation for Tkx is very sparse but by following the Tkx tutorial files on CPAN, it should be easy to get started.
WxWidgets (available for Perl via wxPerl) is an excellent graphical toolkit, but wxPerl only implements a subset of the available widgets.
PAR is convenient but if you go with Perl/Tk, the result will not run natively on OS X. (Users will need to run X11 first, which is problematic, especially with more recent version of OS X). If you go with Tkx, you can get native application on Mac OSX. Also, ActiveStates's PDK gives you a simple way to package everything to deploy to Windows, Linux, and OS X.
For reference, see the the software (AntConc and AntWordProfiler) at the following site http://www.antlab.sci.waseda.ac.jp/software.html, where AntConc was developed using Perl/Tk and AntWordProfiler was developed using Tkx.

The Process class allows to start new processes from a C# (WPF/Winforms) frontend.
I guess that way you can keep your Perl scripts and use the nice Visual Studio GUI builder.

Related

What module to use for perl GUI on linux? [duplicate]

I'd like to write some interactive GUIs in Perl. I've used TclTk but it looks dated. I've written QT code for C++, but the PerlTk module hasn't had a release in several years. Googling around I see other possible options.
What are good packages for this, including basic windowing, menus, drawing canvas, scrollbars, and so on.
Gtk2 has glade2 which can write out an XML file usable by Gtk2::GladeXML. Here is an example of how to bundle the XML with the app in the same file.
I misread the question at first. I thought you wanted a GUI editor for making GUIs (which is what glade2 is). You can also create GUIs using Gtk2 without glade2:
#!/usr/bin/perl
use strict;
use warnings;
use Gtk2;
Gtk2->init;
my $window = Gtk2::Window->new;
my $vbox = Gtk2::VBox->new;
my $label = Gtk2::Label->new("Hello World");
my $button = Gtk2::Button->new("Press me");
$window->add($vbox);
$vbox->add($label);
$vbox->add($button);
$window->set_default_size(200, 200);
$window->signal_connect(
destroy => sub {
Gtk2->main_quit;
}
);
my $i = 0;
$button->signal_connect(
clicked => sub {
$label->set_text("button pressed " . ++$i . " times");
}
);
$window->show_all;
Gtk2->main;
Try wxPerl!
From the web site:
wxPerl is an extension module allowing
the creation of GUI (Graphical User
Interface) from Perl; it is built as a
wrapper for the awesome wxWidgets C++
GUI toolkit.
Echoing Chas Owens, glade is quite usable with Gtk2 in Perl. In addition, Gtk2 also supports GtkBuilder files (which you can create the latest glade too).
The main problem with wxPerl (and wxWidgets itself) is that it doesn't let you install file event watchers into its main loop (it only has GUI, Socket and Timer events), unlike Tk and Gtk.
The Qt, Tk and Gtk2 event loops can be used in Perl with AnyEvent, and Gtk2 can be hooked into applications running the Event or Ev mainloop with Glib::Event and Glib::EV modules.
A GUI builder for WxPerl would be wxGlade or wxFormBuilder, both open-source.
I would probably use Gtk2, but Tk is definitely not dead. The lack of releases is due to the bugs being ironed out over the years. A lot of people still use it, and it generally works fine. (Tk's event loop is somewhat silly, but that is a detail that probably shouldn't concern you.) The only disadvantage is that your GUI looks like it is from 1996, but who cares?
(The gitk tool included with git showed that Tk GUIs look fine as long as they're useful.)
Recently I was made aware of another GUI toolkit for Perl called Prima. Its claim to fame is that it was written in C especially for Perl, not a port from TCL or bindings to something else. Assuming you have some rather standard libraries on your system, it will install directly from CPAN and its cross-platform!
David Mertens has been writing a new plotting library for PDL using it, and a REPL too!
Regarding quality of widgets, all three gtk2, wx and qt4 are equally good -- gtk2 is fastest, qt4 has best resolution, whereas wx is somewhere between the two in terms of both the parameters.
But tk is behind all the three both in terms of speed and resolution, but remains firstly because it is the original widget for all unix based interpreted languages, and secondly because it is native-widget of freebsd.
As on today in case of perl, documentation of perl-gtk2 is slightly more developed than both perl-qt4 which is in turn is more developed than wxperl. In fact, if you browse the web, you will find that tutorials for perl-gtk2 is more extensively available than even pygtk (which is also very well established) and ruby-gtk2. In case of python, wxpython documentation leads over PyQt and pygtk, whereas in case of ruby, ruby-qt4 leads over ruby-gtk2 and wxruby. However, others are developing very fast (e.g. ruby-gtk2) and after some time all nine will be equal in all aspects.
The perl-qt4 specific problem is: In case of non-kde desktops, perl-qt4 may not run. I tried running all in ubuntu and sabayon and found that perl-gtk2 and even wxperl (and wxruby also) runs fine whereas I'm not able to run even a single perl-qt4 programs in gnome-desktop where I have installed complete qt4 support without kde.
perl-qt4 asks for installation of not just qt4-libraries, but also kde-desktop libraries. This problem is uniquely perl-qt4-specific, does not exist in case of PyQt and rubyqt4 since they both run fine with qt4 runtime under gnome.
Hence, in this way eight (plus three tk) out of nine options did well (I havent tested PySide yet).
In case of perl-tk, widget is well developed and established and unlike tkinter, pmw and rubytk, its documentation is the best among all of these mentioned above.
But maybe after some time all the documentations become developed and any would become equally good.
After taking a balance between speed, clarity and cross-platform into consideration choose either perl-gtk2, or perl-qt4 or wxperl.
perl-tk, perl-gtk2 and perl-qt4 syntaxes nicely go well with perl programming language syntax, whereas wxperl syntax look more like proper c++ blended into perl which is different from the respective language syntax (just like in case of wxpython and wxruby).
But if you are already keeping in mind that wx code is uniquely different then you can straightaway begin with wxperl.
Otherwise, best way out is: begin with perl-tk, then switch over to perl-gtk2 then perl-qt4 or wxperl alike but make sure that you learn all four instead of only one (the same sequence should also apply to python and ruby too despite the fact that documentation support is reverse, but in case of perl even for this aspect it is same).
I don't have a real answer for you, but often you have to consider your deployment targets. Some of the GUI libraries are very nice, but only if you can get them to work on your operating system. I don't necessarily think that all frameworks need to be cross-platform compatible, a very laudable goal to work toward in a perfect world, as long as the one you choose doesn't lock out a significant portion of your users because the foundation GUIs libraries are hard to install or support on a particular platform.
I just want to let everyone know PerlQt is great and this site has a lot of tutorials on how to use it and lots of examples to download.
PerlQt Wiki tutorial
PerlQt is a very fast and easy way to create great looking GUI programs using the Qt drag and drop form designer and Perl. PerlQt is powerful enough for advanced developers and easy for beginners as well.
The solution I'm going with is Gtk-Perl. At first I had difficulty installing it, but in the end I found Camelbox Perl+Gtk2 in one package.
I have used Tk, but in the last few days I have been playing around with Continuity (CPAN entry), a stateful (persistent state per user) web application/server, and it could easily be a way to add "GUI" features into an application, while making it multi-user and portable at the same time.
Edit: At the time I wrote this, I was most interested in the fact that Continuity had its own built-in webserver. This is now true of other webframeworks for Perl as well. I have been using Mojolicious though I hear good things about Dancer too.

Are there Perl GUI builders, especially for WxPerl?

Are there good GUI builder for Perl GUI libraries, especially for WxPerl?
For Wx:
WxGlade
Any Wx tool that generates XRC files.
For Tk:
Zooz
SpeTcl
wxDesigner is the only one I know. I have never used it though.
It's still fairly new, but the Padre editor has an in-development Padre::Plugin::FormBuilder plugin that takes a wxFormBuilder project file and generates pure-Perl dialog classes.
Check out wxformbuilder. You can design your GUI there and generate an XRC file which wxPerl can then be configured to load.
There is The GUI Loft for Win32::GUI, but of course it's not portable off of Win32.
Of the GUI editors that I have tried briefly, wxGlade seems the most natural to use, but it still doesn't seem to have the "drag and drop" functionality that I grew to love when working with Java in Eclipse or Netbeans. Don't get me wrong, I love Perl, but would still really like to see a nice WYSIWYG GUI editor.
I would recommend simply using web-based interfaces for everything. If you went with this approach, you could even run a local (i.e. on a Desktop) web server for "standalone" applications.
In like manner, ActiveState decided to focus on Web-based development instead of continuing work on their GUI editor

Is Perl a good option for writing platform independent desktop applications?

Is Perl a good option for writing (possibly and partially) platform independent desktop applications? I know there are interesting widget libraries like GTK2 Perl and wxWidgets but I'm not familiar with development on Windows.
Is it possible to write a good application with Perl and those tools, maybe embedding everything needed to avoid asking the user to install external (and probably non conventional for many) libraries? Are there examples of this kind of apps around?
Sort of. You can certainly write Perl scripts that provide a Tk GUI that will work on any platform, and you can even package the libraries they need to work with PAR to put together an application that will run anywhere with an appropriate version of perl installed without requiring the end use to install a bunch of stuff from CPAN to get it to work.
However, an application that will run anywhere without requiring an existing perl installation (and it's probably not safe to assume the average Windows user will have perl) isn't really viable. One solution would be to distribute an "everywhere but Windows" version that simply uses PAR to include the necessary libraries, and a PAR::Packer-built version for Windows, which would be a fully-functional .exe including the perl interpreter and the libraries.
EDIT: following daotoad's response, it does appear that ActiveState's PerlApp can build cross-platform binaries for for Windows, Mac OS X, Linux, Solaris, and AIX; I haven't tried this but if it works as advertised it would seem to meet your requirements.
My employer uses ActiveState's PerlApp to produce executable versions of our apps with great success.
We tested PAR and PerlApp before selecting our packaging method. At that time, PerlApp had faster load times. Several versions of each tool have come and gone since then, so I would recommend testing with each before selecting a tool.
Executable packaging has been very effective for us.
There are a few portability issues issues with Perl, but if you pay attention to perlport, it's easy to avoid most issues. Our biggest problems are always with Win32. From time to time, some simple thing will require stupid, bizarre work-arounds or digging into Win32 API for a platform specific hack.
We have used both Wx and Tk guis.
Frozen Bubble is a well known and widely available app you can look at.
Check out PAR (available via CPAN) with respect to your bundling requirement.
Consider having a look at Padre for an example of a complex application written in perl using Wx.
So yes. All of your requirements are achievable, including portability.
I am working on the module XUL::Gui on CPAN, which uses Firefox to display cross platform gui apps from Perl. It is under development, but stable, and may be complete enough for your needs. You can build your gui in HTML and/or XUL (the Mozilla gui language that Firefox itself is written in), and then style everything with CSS. Let me know if you have any feature requests.

Is there a good tool to debug Perl-based web applications?

Is there a good tool to debug Perl-based web applications? Output to stderr or stdout don't count as tool.
Yup, I've got the perfect tool for you.
CGI::Inspect lets you inspect and debug a running Perl web application.
Read more about the module on the developer's website.
Or check out the slides from a presentation about it at YAPC::NA 2009.
The Komodo IDE supports remote debugging for just this sort of thing.
The EPIC plugin for Eclipse will also let you do this.
In CGI, you can
use CGI::Carp qw(fatalsToBrowser);
It will display any fatal message in your browser.
With Mason, leave the default error option, which outputs the call stack in your browser.
Let's not assume, like the first answer, that the module being used is CGI, but rather provide something that will work across anything that is supported by/supports PSGI/Plack.
Perhaps combine Plack::Middleware::Debug (to display information about the active request and response, perhaps adding the Log4perl panel) and Devel::hdb to debug the running code in a separate tab.
Also available (I haven't tried it though) is InteractiveDebugger
Anything you try should be run in a single process, non-forking server like HTTP::Server::PSGI or HTTP::Server::Simple::PSGI for development and debugging instead of something like Starman.
Late to the party on this one, but I felt some other tools should be called out in case anyone else stumbles upon this question.
The Perl command line debugger is perfectly serviceable, but occasionally hard to use, and has a fairly steep learning curve, especially for those who are used to GUI tools.
Devel::hdb is a great tool for this. It integrates with the existing debugging functionality in Perl, so you can start the application with -d:hdb as a flag, and then you can hit a web based endpoint to start stepping through the application easily. It supports breakpoints, watch expressions, and stepping, so it can help you figure out where an issue is on a somewhat live application.
As mentioned earlier, ActiveState's Komodo IDE (not Edit) has a built in graphical debugger, that can work on a local instance or against a remote server. The remote server must have some libraries installed, and activated within the code to work. It's not invasive, but it should be known. Also, Komodo costs money, but they do provide a trial period. It'll work on Windows, OS X or Linux. ActiveState's Perl Dev Kit has an independent debugger as well, but I haven't used it in years.

What are good interactive GUI builder packages for Perl?

I'd like to write some interactive GUIs in Perl. I've used TclTk but it looks dated. I've written QT code for C++, but the PerlTk module hasn't had a release in several years. Googling around I see other possible options.
What are good packages for this, including basic windowing, menus, drawing canvas, scrollbars, and so on.
Gtk2 has glade2 which can write out an XML file usable by Gtk2::GladeXML. Here is an example of how to bundle the XML with the app in the same file.
I misread the question at first. I thought you wanted a GUI editor for making GUIs (which is what glade2 is). You can also create GUIs using Gtk2 without glade2:
#!/usr/bin/perl
use strict;
use warnings;
use Gtk2;
Gtk2->init;
my $window = Gtk2::Window->new;
my $vbox = Gtk2::VBox->new;
my $label = Gtk2::Label->new("Hello World");
my $button = Gtk2::Button->new("Press me");
$window->add($vbox);
$vbox->add($label);
$vbox->add($button);
$window->set_default_size(200, 200);
$window->signal_connect(
destroy => sub {
Gtk2->main_quit;
}
);
my $i = 0;
$button->signal_connect(
clicked => sub {
$label->set_text("button pressed " . ++$i . " times");
}
);
$window->show_all;
Gtk2->main;
Try wxPerl!
From the web site:
wxPerl is an extension module allowing
the creation of GUI (Graphical User
Interface) from Perl; it is built as a
wrapper for the awesome wxWidgets C++
GUI toolkit.
Echoing Chas Owens, glade is quite usable with Gtk2 in Perl. In addition, Gtk2 also supports GtkBuilder files (which you can create the latest glade too).
The main problem with wxPerl (and wxWidgets itself) is that it doesn't let you install file event watchers into its main loop (it only has GUI, Socket and Timer events), unlike Tk and Gtk.
The Qt, Tk and Gtk2 event loops can be used in Perl with AnyEvent, and Gtk2 can be hooked into applications running the Event or Ev mainloop with Glib::Event and Glib::EV modules.
A GUI builder for WxPerl would be wxGlade or wxFormBuilder, both open-source.
I would probably use Gtk2, but Tk is definitely not dead. The lack of releases is due to the bugs being ironed out over the years. A lot of people still use it, and it generally works fine. (Tk's event loop is somewhat silly, but that is a detail that probably shouldn't concern you.) The only disadvantage is that your GUI looks like it is from 1996, but who cares?
(The gitk tool included with git showed that Tk GUIs look fine as long as they're useful.)
Recently I was made aware of another GUI toolkit for Perl called Prima. Its claim to fame is that it was written in C especially for Perl, not a port from TCL or bindings to something else. Assuming you have some rather standard libraries on your system, it will install directly from CPAN and its cross-platform!
David Mertens has been writing a new plotting library for PDL using it, and a REPL too!
Regarding quality of widgets, all three gtk2, wx and qt4 are equally good -- gtk2 is fastest, qt4 has best resolution, whereas wx is somewhere between the two in terms of both the parameters.
But tk is behind all the three both in terms of speed and resolution, but remains firstly because it is the original widget for all unix based interpreted languages, and secondly because it is native-widget of freebsd.
As on today in case of perl, documentation of perl-gtk2 is slightly more developed than both perl-qt4 which is in turn is more developed than wxperl. In fact, if you browse the web, you will find that tutorials for perl-gtk2 is more extensively available than even pygtk (which is also very well established) and ruby-gtk2. In case of python, wxpython documentation leads over PyQt and pygtk, whereas in case of ruby, ruby-qt4 leads over ruby-gtk2 and wxruby. However, others are developing very fast (e.g. ruby-gtk2) and after some time all nine will be equal in all aspects.
The perl-qt4 specific problem is: In case of non-kde desktops, perl-qt4 may not run. I tried running all in ubuntu and sabayon and found that perl-gtk2 and even wxperl (and wxruby also) runs fine whereas I'm not able to run even a single perl-qt4 programs in gnome-desktop where I have installed complete qt4 support without kde.
perl-qt4 asks for installation of not just qt4-libraries, but also kde-desktop libraries. This problem is uniquely perl-qt4-specific, does not exist in case of PyQt and rubyqt4 since they both run fine with qt4 runtime under gnome.
Hence, in this way eight (plus three tk) out of nine options did well (I havent tested PySide yet).
In case of perl-tk, widget is well developed and established and unlike tkinter, pmw and rubytk, its documentation is the best among all of these mentioned above.
But maybe after some time all the documentations become developed and any would become equally good.
After taking a balance between speed, clarity and cross-platform into consideration choose either perl-gtk2, or perl-qt4 or wxperl.
perl-tk, perl-gtk2 and perl-qt4 syntaxes nicely go well with perl programming language syntax, whereas wxperl syntax look more like proper c++ blended into perl which is different from the respective language syntax (just like in case of wxpython and wxruby).
But if you are already keeping in mind that wx code is uniquely different then you can straightaway begin with wxperl.
Otherwise, best way out is: begin with perl-tk, then switch over to perl-gtk2 then perl-qt4 or wxperl alike but make sure that you learn all four instead of only one (the same sequence should also apply to python and ruby too despite the fact that documentation support is reverse, but in case of perl even for this aspect it is same).
I don't have a real answer for you, but often you have to consider your deployment targets. Some of the GUI libraries are very nice, but only if you can get them to work on your operating system. I don't necessarily think that all frameworks need to be cross-platform compatible, a very laudable goal to work toward in a perfect world, as long as the one you choose doesn't lock out a significant portion of your users because the foundation GUIs libraries are hard to install or support on a particular platform.
I just want to let everyone know PerlQt is great and this site has a lot of tutorials on how to use it and lots of examples to download.
PerlQt Wiki tutorial
PerlQt is a very fast and easy way to create great looking GUI programs using the Qt drag and drop form designer and Perl. PerlQt is powerful enough for advanced developers and easy for beginners as well.
The solution I'm going with is Gtk-Perl. At first I had difficulty installing it, but in the end I found Camelbox Perl+Gtk2 in one package.
I have used Tk, but in the last few days I have been playing around with Continuity (CPAN entry), a stateful (persistent state per user) web application/server, and it could easily be a way to add "GUI" features into an application, while making it multi-user and portable at the same time.
Edit: At the time I wrote this, I was most interested in the fact that Continuity had its own built-in webserver. This is now true of other webframeworks for Perl as well. I have been using Mojolicious though I hear good things about Dancer too.