Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Simple Hash gui (useful!)

by Luca Benini (Scribe)
on Nov 20, 2004 at 17:42 UTC ( [id://409270]=CUFP: print w/replies, xml ) Need Help??

Using dialog(1) this snippet allow users to use a GUI to configure options.
#!/usr/bin/perl use IPC::Open3; use File::Temp qw/ :mktemp /; my $options={ 'height'=>30, 'menuheight'=>20, 'width'=>50, 'title'=>"My dialog", }; my $val={ 'Options1'=>30, 'String_Options'=>30, 'Another_Options'=>30, 'Another_again'=>"My dialog", }; perlog_run($options,$val); sub create_cmd_line() { my ($hropt,$hrentry)=@_; my $cmdline="dialog --nocancel --inputmenu \"$hropt->{'title'}\" $ +hropt->{'height'} $hropt->{'width'} $hropt->{'menuheight'}"; foreach(sort keys %$hrentry) { $cmdline .= " \"$_\" \"$hrentry->{$_}\""; } return $cmdline; } sub perlog_run() { my ($hropt,$hrentry)=@_; my $d; for(;;) { open OLDERR, ">&", \*STDERR; close(STDERR); (*STDERR,$filename)=mkstemp("perllogXXXXXX"); my $c=&create_cmd_line($hropt,$hrentry); system("$c"); close (STDERR); open STDERR, ">&", \*OLDERR; close (OLDERR); open IN,"<$filename"; $_=<IN>; close(IN); unlink $filename; (/[^\s]+\s([^\s]+)\s(.+)$/)?$hrentry->{$1}=$2:last; } }
New version (FULL ini format supported!)
use Getopt::Long; my $val={'height'=>30,'menuheight'=>20,'width'=>50,'title'=>"My dialog +",}; my $path="config/ini/"; my $file,$help; my %iniopts=('case'=>'sensitive'); GetOptions ("conf=s"=> \$file, "path=s"=> \$path); if($file eq "") { print RESET "**************"; print GREEN "PER"; print RESET "[L][DIA]"; print GREEN "LOG by Luca Benini - 2004 - GPL"; print RESET "**************\nUsage:\n\t"; print BLUE "$0 [--path=/path/to/ini/file] [--conf=inifile]\n" +; print RESET "Default path:\n\t"; print BLUE "$path"; print RESET "\n"; exit(0); } $val->{'title'}="$file | Luca Benini Configure"; my $Config = ReadINI("$path$file",%iniopts) or die "[READ] Unable to o +pen $path$ file: $!"; foreach(keys %$Config) { my $t=$Config->{$_}; foreach(keys %$t) { delete $t->{$_} if (/#/); } } my $i=perlog_config($val,$Config); WriteINI("$path$file",$Config) or die "[WRITE] Unable to open $path$fi +le: $!"; sub perlog_config() { my ($hropt,$hrentry)=@_; while(1) { my $i=perlog_run_select($hropt,$hrentry); return if ($i eq ""); perlog_run_rename($hropt,$hrentry->{$i}); } } sub create_cmd_line_menu() { my ($hropt,$hrentry)=@_; my $cmdline="dialog --nocancel --menu \"$hropt->{'title'}\" $h +ropt->{'he ight'} $hropt->{'width'} $hropt->{'menuheight'}"; foreach(sort keys %$hrentry) { $cmdline .= " \"$_\" \"$_\""; } return $cmdline; } sub create_cmd_line_imenu() { my ($hropt,$hrentry)=@_; my $cmdline="dialog --nocancel --inputmenu \"$hropt->{'title'} +\" $hropt- >{'height'} $hropt->{'width'} $hropt->{'menuheight'}"; foreach(sort keys %$hrentry) { $cmdline .= " \"$_\" \"$hrentry->{$_}\""; } return $cmdline; } sub perlog_run_select() { my ($hropt,$hrentry)=@_; my $d; open OLDERR, ">&", \*STDERR; close(STDERR); (*STDERR,$filename)=mkstemp("perllogXXXXXX"); my $c=&create_cmd_line_menu($hropt,$hrentry); system("$c"); close (STDERR); open STDERR, ">&", \*OLDERR; close (OLDERR); open IN,"<$filename"; $_=<IN>; close(IN); unlink $filename or die ; return $_; } sub perlog_run_rename() { my ($hropt,$hrentry)=@_; my $d; for(;;) { open OLDERR, ">&", \*STDERR; close(STDERR); (*STDERR,$filename)=mkstemp("perllogXXXXXX"); my $c=&create_cmd_line_imenu($hropt,$hrentry); system("$c"); close (STDERR); open STDERR, ">&", \*OLDERR; close (OLDERR); open IN,"<$filename"; $_=<IN>; close(IN); unlink $filename or die ; (/[^\s]+\s(.+)\s([^\s]+)$/)?$hrentry->{$1}=$2:last; } }

Replies are listed 'Best First'.
Re: Simple Hash gui (useful!)
by zentara (Archbishop) on Nov 20, 2004 at 19:35 UTC
    Reminds me of Slackware installs. :-)

    I'm not really a human, but I play one on earth. flash japh
      Well this a snippet of a script i'm working on for GUI configutation on file with ini format. Do you think is good?
        Yeah, it looks nice. It dosn't do much, so I can't say whether it's good or not. But you have a good start. I like it.

        I'm not really a human, but I play one on earth. flash japh
Re: Simple Hash gui (useful!)
by simonflk (Pilgrim) on Nov 24, 2004 at 14:05 UTC
      THANKSTHANKSTHANKSTHANKSTHANKS I love u ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://409270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-19 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found