LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   GUI front-end for Perl script: opinions? (http://www.linuxquestions.org/questions/programming-9/gui-front-end-for-perl-script-opinions-541904/)

trashbird1240 03-30-2007 10:05 AM

GUI front-end for Perl script: opinions?
 
Dear Forum,

I still consider myself a novice in programming, even though I'm familiar with programming concepts. I've written a Perl script that takes statistical output and formats it for LaTeX. ONe of my colleagues expressed interest in using it on Windows, and suggested that I work up a way to do so. I'm the only one in my office that uses Linux, and most everybody else uses OS X.

Another friend of mine has just finished working up a rather elaborate GUI frontend in Java, so she's familiar with this subject. She suggested Java and that she would gladly help me with this.

The GUI would probably only consist of a dialog box, with an OK button and two boxes for the input file and the output file names. A splash screen would be fun but totally unnecessary.

Here's my level of programming skill:
*studied a little bit of Python, a little bit of C, a little bit of Scheme, enough Perl to write this program I'm already talking about.
*spend most of my days programming in Stata, a scripting language for a statistical software platform that is superficially similar to C
*I'm interested in Ruby, but have no compelling reason to study either Ruby or Python
*Have never written a GUI, or had any interest until now (I do most everything from the command line anyway)

My own opinions:
*I would rather not learn Java, as it seems like a deep subject; I would rather learn C first
*Ideally this GUI should function across platforms, although I'd be willing to tweak it to get it to go
*I would need an installer, too; these people are not fond of CLI

What should I use?
Joel

weibullguy 03-30-2007 11:06 AM

Quote:

Originally Posted by trashbird1240
ONe of my colleagues expressed interest in using it on Windows, and suggested that I work up a way to do so. I'm the only one in my office that uses Linux, and most everybody else uses OS X.

Tell your colleague it would be easier to switch to Linux. ;)

Quote:

Originally Posted by trashbird1240
Another friend of mine has just finished working up a rather elaborate GUI frontend in Java, so she's familiar with this subject. She suggested Java and that she would gladly help me with this.

This is the reason I voted for Java. If you choose something else that you're really not familiar with will you have support staff near by or will you need to use LQ? Something to think about. Your GUI is pretty simple so you wouldn't need to learn Java that deeply I would guess.

Or you could tell your Windows colleague to get R (with the GUI) and use the toLatex function.:D

trashbird1240 03-30-2007 12:10 PM

Quote:

Originally Posted by Arow
Tell your colleague it would be easier to switch to Linux. ;)

He already told me he "wants to, but..." and that was without prompting. He's a smart guy, around here we call him "the world's top-ranked psychologist," (because he is, so it's not really a joke), but he still feels the pressure of the simple-minded software world.

Quote:

This is the reason I voted for Java. If you choose something else that you're really not familiar with will you have support staff near by or will you need to use LQ? Something to think about. Your GUI is pretty simple so you wouldn't need to learn Java that deeply I would guess.
Except that I actually know nothing about Java. There's plenty of people I could turn to with Java, but I don't know if that thoroughly justifies it, since I learned plenty of Perl without telling anybody what I was doing.

Quote:

Or you could tell your Windows colleague to get R (with the GUI) and use the toLatex function.:D
I'm not running the show, I'm just the star of it. They all know it would be better to do things my way, but they are stubborn and proud of their inefficient ways. If they did things my way, they'd have to stop saying "Who has time for all these meetings!"

BTW, the reason I wrote this program was to produce the kind of tables that we use here; they are quite different from what Stata or even R considers useful. There are many programs in Stata that will transfer things into TeX or LaTeX, but they only transform the output that Stata already produces, which is fairly useless to me. My program saves the time that I used to spend (and many of my colleagues still spend) of transcribing the results into a table. Most of them use Microsoft Word, but I think this may be a first step to convince them to try another option.

Joel

taylor_venable 03-30-2007 12:16 PM

Since you're already forcing them to have Perl on their machine, you might as well write it in Perl/Tk. It's cross platform, requires no installer, and has support in the default Perl bundle for whatever OS you want to run it on. Tk is also very simple to program, so you won't waste much time (though you wouldn't have to spend any time at all if those Windows weenies would just learn to type some text at the command-line).

trashbird1240 03-30-2007 02:59 PM

So, better to force them to have Perl, rather than forcing them to have Perl, Ruby, Python and a computer built after 1994 (Java)? That would be rather oppressive ...

Joel

KenJennings 03-30-2007 03:11 PM

"None of the above" does not appear on your poll.

trashbird1240 03-30-2007 03:21 PM

Quote:

Originally Posted by KenJennings
"None of the above" does not appear on your poll.

Is that object-oriented?
Joel

trashbird1240 03-30-2007 04:06 PM

Just to clarify one thin about Perl/Tk: does the user (i.e., not me) need to have Perl/Tk installed?

Joel

taylor_venable 03-30-2007 05:15 PM

Quote:

Originally Posted by trashbird1240
Just to clarify one thin about Perl/Tk: does the user (i.e., not me) need to have Perl/Tk installed?

Yes, but Perl/Tk is part of almost all Perl distributions. For example, ActivePerl on Windows includes it, as do most Linux distros in their package system. AFAIK, only a few (for example, Debian) split it out into a separate package.

paulsm4 03-30-2007 05:57 PM

Perl/Tk is probably a great choice!
 
Hi -

Since you're comfortable with Perl; Perl/Tk would probably be an excellent choice. Additionally, anything you learn about Tk using the Perl interface would also be applicable to Python, Ruby or other open source languages you might wish to experiment with in the future.

Here's a tutorial that might help increase your comfort/confidence level:
http://www.perl.com/pub/a/2001/03/gui.html

From the same site, here's another alternative you might want to look at:
http://www.perl.com/pub/a/2001/09/12/wxtutorial1.html

'Hope that helps .. PSM

PS:
Here is one other Perl/Tk tutorial you might like:
http://www.bin-co.com/perl/perl_tk_t...ello_world.php

cyb0rg777 04-01-2007 08:41 PM

Here is a perl/tk script I wrote a few months ago.I just started using perl so it could probably be improved.I just took a bunch of examples and put them together really.
It is for converting ascii text to binary or hex and back again.
Later I may add more features such as encryption or morse code.
It's fun to play with.
Code:

#!/usr/bin/perl -w
use Tk;
use strict;

my $box;
my $dataout;
my $datain;
my $from='ascii';
my $to='bin';
my $mw = new MainWindow;
my $tin =$mw->Text(-background =>'white')->pack();
my $fromradio;
my $toradio;
my $fromascii=$mw->Radiobutton(-command=>\&notsameto ,-variable=>\$fromradio,-value=>1,-text=>'ascii');
my $fromhex=$mw->Radiobutton(-command=>\&notsameto,-variable=>\$fromradio,-value=>2,-text=>'hex');
my $frombin=$mw->Radiobutton(-command=>\&notsameto,-variable=>\$fromradio,-value=>3,-text=>'bin');
my $toascii=$mw->Radiobutton(-state=>'disabled',-variable=>\$toradio,-value=>1,-text=>'ascii');
my $tohex=$mw->Radiobutton(-state=>'disabled',-variable=>\$toradio,-value=>2,-text=>'hex');
my $tobin=$mw->Radiobutton(-state=>'disabled',-variable=>\$toradio,-value=>3,-text=>'bin');

$fromascii->pack(-side=>'left');
$frombin->pack(-side=>'left');
$fromhex->pack(-side=>'left');
$toascii->pack(-side=>'right');
$tobin->pack(-side=>'right');
$tohex->pack(-side=>'right');

$tin->delete('1.0','end');
$tin->insert('end','test');


my $response = $mw -> Button(-text=>"Convert",-command => \&convert)->pack();

MainLoop;

sub notsameto{
if($fromradio==1){
        $toascii->configure(-state=>'disabled');
        $tobin->configure(-state=>'normal');
        $tohex->configure(-state=>'normal');
        return;
        }
if($fromradio==2){
        $tohex->configure(-state=>'disabled');
        $tobin->configure(-state=>'normal');
        $toascii->configure(-state=>'normal');
        return;
        }
if($fromradio==3){
        $tobin->configure(-state=>'disabled');
        $tohex->configure(-state=>'normal');
        $toascii->configure(-state=>'normal');
        return;
        }
}


sub b2ascii
{
my $l=length $_[0];
my $a=+pack "B$l",$_[0];
return $a;
}

sub a2hex
{
    (my $str = shift) =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
    return $str;
}
sub h2ascii
{
    (my $str = shift) =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;
    return $str;
}

sub a2bin
{
        my $l=(length $_[0])*8;
        my $a=+unpack "B$l",$_[0];
        return $a;
}

sub convert(){
if(!$toradio){return;}
$datain=$tin->get('1.0','end');
$tin->delete('1.0','end');
if ($fromradio==1){
    if ($toradio==3){$dataout=a2bin($datain);}
    if ($toradio==2){$dataout=a2hex($datain);}
    }
if($fromradio==2){
if($datain!~/[a-fA-F0-9]/)
    {
        $box = $mw->DialogBox( -buttons => ["OK"])->pack();
    return;
        }
        if($toradio==1){$dataout=h2ascii($datain);}
    if($toradio==3){$dataout=a2bin(h2ascii($datain));}
    }
if($fromradio==3){
    if ($datain!~/01/)
        {
        $box = $mw->DialogBox( -buttons => ["OK"])->pack();
    return;
        }
    if($toradio==1){$dataout=b2ascii($datain);}
    if($toradio==2){$dataout=a2hex(b2ascii($datain));}
    }
$tin->insert('end',$dataout);
return;
}

I don't want to debate personal preference ,but for me perl is more like c ,so it was easier to learn. And it's a script which I prefer over compiled language like java.

chrism01 04-02-2007 03:36 AM

Logically, as above, if you're already using Perl to do the processing, (& therefore will have to install it anyway), you might as well go with Perl/Tk.
Potentially, if you fancy a server/client situation, write a web page in CGI Perl... Only need to keep 1 copy of code updated....

wolfger 04-02-2007 07:32 AM

I love Perl. Absolutely love it. And I fairly well loathe Java. But Perl/Tk as the "ideal language to create a GUI"??!? What are you people smoking? I find Perl/Tk to be moderately hideous, with no good WYSIWYG editors to assist in design. Yeah, sure, it's nice to work with a scripted language over a compiled language, but I'd take Java with a good IDE over Perl/Tk for GUI creation any day of the week.

That being said, it sounds like the task at hand could be much easier done with HTML/CSS and a web browser. For simple GUIs, it's all that's really needed.

trashbird1240 04-02-2007 10:39 AM

Thanks for all the excellent and helpful replies.

I installed Perl/Tk on Friday. I thought that my distribution did not have it, since I got the following error:

Code:


Can't locate Tk.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/i486-linux /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/i486-linux /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl .) at tk line 2.
BEGIN failed--compilation aborted at tk line 2.

After running an example from a Perl/Tk tutorial.

So, then I installed Perl/Tk and got the same error message. I reckon @INC is a hash, but where is it and how would I edit it?

[edit: this is because I installed Tk from CPAN as a user, not as root; I have since corrected this and the trial script works]

Joel


All times are GMT -5. The time now is 04:20 PM.