snailwinks has asked for the wisdom of the Perl Monks concerning the following question:

Hi, is there a way to design a GUI frontend that calls a "scalable" number of standalone perl scripts?

I have about 10 scripts presently, which process various engineering text files in various ways. Each file :

I would like to write a pTk graphical frontend to these scripts and combine everything into an .exe for my colleagues (they're not keen on cmd line stuff).

The general idea is :

[code to design the GUI] [drop-down listbox to select script to run] [display frame x if script x was selected] [accept extraction options if any] ... MainLoop ; [sub to call program 1] # different scripts are [sub to call program 2] # run depending which ... # buttons the user clicked [sub to call program N] # N < 100

I should be able to :

Modular programming doesn't seem to fit the bill exactly, since it would mean rewriting the scripts into modules and everything into subs, but I'm willing to try anything. I would appreciate any advice very much.

ps. I have been programming for less than a year (not much knowledge on modules and OOP), so pls bear with me :)

update : thanks everyone for your replies, they were very helpful.

Replies are listed 'Best First'.
Re: Program design with GUI interface
by GrandFather (Saint) on May 10, 2006 at 04:20 UTC

    The first step is to realise that you can use system to execute your existing scripts without changing them at all:

    #file sample.pl system "noname1.pl first argument";
    #file HelloWorld.pl my $arg = shift; print 'Hello World.'; print " param is $arg" if defined $arg;

    Prints:

    Hello World. param is first

    After that using any of various methods to get the list of scripts to run and using that list to populate a list control is fairly straight forward.

    I've not time to do it now, but if you don't get enough answer to do the GUI bit I'll provide a sample in a few hours.


    DWIM is Perl's answer to Gödel

      Thank you for your speedy reply, I have been enlightened :)

      I have read about system before, but didn't think of using it this way (/slaps himself on forehead).

      The sample code will not be necessary, I should be able to take it from here ;)

Re: Program design with GUI interface
by vkon (Curate) on May 10, 2006 at 05:46 UTC
    my script utilities at $work all use this approach: they all start with
    use Utl; # this is my module, where some 'magic' is hidden
    and all these utilities are able to either accept arguments from the command line, or, when I specify --g then Tk GUI is displayed, allowing me to comfortably fill in the values.

    If, for example, I specified --arg=value --g then in GUI that parameter will be initialized with that value, and user either agrees with it, or edit it.

    Boolean values (checkboxes), file location values, list selection values and so on are supported.

    Example screenshot.

    I wonder should I CPANize it?

      If the code is as good as the GUI in your screen-shot, run; do not walk; to CPANize it!   ++
        Well, code isn't extremely good, because, as I started it for my own convenience, it grows from small helper subs into something resembling the module (and that was really convenient for me, personally).
        But even namespace was not choosen.

        Additionally, before flooding CPAN with yet another option parsing module, in addition to, say, http://search.cpan.org/~srezic/Tk-Getopt-0.49/, there should be good argumentation for this.

        If you're still interesting, I can factor some sh*t out, will show the code, and prepare for some kind of RFC in Meditations section.

        Do you have an idea how to name it, given screenshot? :)

      No great names to suggest, vkon, other than something quite obvious like
       
            Tk::Getopt::Util.

      But an RFC, with code (scrubbed for any personal data, naturally), may produce suggestions from those of great wisdom and help you smooth any rough spots you would like to polish.

      ...and speaking of "wisdom," check out zentara's response to the OP. I'm not well qualified to evaluate the recommendations, but I am convinced that zentara's observations are noteworthy.
Re: Program design with GUI interface
by johngg (Canon) on May 10, 2006 at 08:31 UTC
    I have a script that does pretty much what you require. It was written some time ago so doesn't have best practices like use strict but that would be easy to fix. Here it is.

    I hope you find it useful.

    Cheers,

    JohnGG

Re: Program design with GUI interface
by zentara (Cardinal) on May 10, 2006 at 15:57 UTC
    Hi, I will just mention a couple of design considerations, after reading the other replies.

    First, system may not be the best option if you want to direct the output directly to a text box, you will need to use "piped opens" or "IPC::Open3"( or a similar method) along with Tk's fileevent to read the output. This will collect and display the output of long-running programs, without "blocking the gui". Additionally, this will allow you to run more than one command at a time. Backticks could be used to capture the output, if the command will complete quickly.

    A cool way to do this, would be with a Notebook widget, and a menu. The menu would allow you to select which command to run, and then it would open a new notebook page with the command name in the tab-text, and an entry widget for the extra options, and an output text widget on the page.

    Another ready to go module which will help you do this is the Tk::ExecuteCommand module. Here is a simple example, but you can launch commands as many as you want, and they will open in a new window.

    #!/usr/bin/perl -w use Tk; use Tk::ExecuteCommand; use Tk::widgets qw/LabEntry/; use strict; my $mw = MainWindow->new; my $top = $mw->Toplevel; $top->withdraw; my $ec = $top->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; $ec->configure(-command => 'date; sleep 10; date'); my $button = $mw->Button(-text =>'Do_it', -background =>'hotpink', -command => sub{ $top->deiconify; $top->raise; $ec->execute_command; $top->withdraw}, )->pack; MainLoop;

    I'm not really a human, but I play one on earth. flash japh