tags:

views:

251

answers:

3

I have a Perl command line program, for which a GUI is required. I see that this is mostly done using GTk.

However we would like to do this in Java as we would like to re-use for another desktop application.

Are there any issues in following the Java approach. What would you recommend?

+1  A: 

Perl is cross-platform, as is Gtk, but you will have to distribute the appropriate libraries and binaries to launch your application. THe Perl Foundation has a short article on the subject, but it's not very detailed.

Conspicuous Compiler
A: 

Note that there is some Perl / Java integration (see this tutorial for more info).

You can use this to invoke a Java Swing GUI on top of your Perl script.

Brian Agnew
+3  A: 

If you have Firefox installed on the target platforms, I have been working on the module XUL::Gui, on CPAN which uses Firefox to render its gui. It is still in development, but should be stable enough to use in most cases. While not Java, the HTML/XUL platform is a good solution for rapidly prototyping gui's in Perl. Or it could certainly host a java applet. However, I would imagine that if you plan to reuse the gui for a Java application, building it primarily in Java and creating/implementing a messaging protocol between the two languages would be easier to re-purpose than designing the gui from the Perl side. That said, here is a short example of creating a gui for a command line app:

use XUL::Gui;

display Window title => 'Foo Processor',
    Hbox(
        (map {
            my $id = $_;
            CheckBox id => $id,
                label   => "use $id",
                option  => sub {shift->checked eq 'true' ? " -$id" : ()}
          } qw/foo bar baz/
        ),
        TextBox( id => 'num', 
             type   => 'number', 
             option => sub {' -num ' . shift->value}
        ),
        Button( label => 'run', oncommand => sub {
            my @opts = map {$ID{$_}->option} qw/foo bar baz num/;
            $ID{txt}->value = `fooproc @opts`;
        }),
    ),
    TextBox( FILL, id => 'txt' );

XUL::Gui also uses familiar design technologies such as HTML and CSS which minimizes the learning curve. XUL is Mozilla's gui development language, which provides many useful widgets (and is the language that the Firefox gui itself is written in).

Eric Strom