#!/usr/bin/perl
use strict; # https://perlmonks.org/?node_id=11130955
use warnings;
use Tk;
use Path::Tiny;
my $code;
my $file;
my $execute;
my $mw = MainWindow->new;
my $button = $mw->Button(-text => 'Execute', -command => \&execute,
-state => 'disabled',
)->pack(-side => 'bottom');
my $frame = $mw->Frame->pack(-fill => 'both', -expand => 1);
$frame->Label(-text => 'Perl Script', -fg => 'blue',
)->grid(-row => 1, -column => 1, -sticky => 'ew');
$frame->Label(-text => 'Data File', -fg => 'blue',
)->grid(-row => 1, -column => 2, -sticky => 'ew');
my $codelist = $frame->Scrolled(Listbox => -scrollbars => 'osoe',
-exportselection => 0,
)->grid(-row => 2, -column => 1, -sticky => 'nsew');
my $filelist = $frame->Scrolled(Listbox => -scrollbars => 'osoe',
-exportselection => 0,
)->grid(-row => 2, -column => 2, -sticky => 'nsew');
$frame->gridRowconfigure( 2, -weight => 1 );
$frame->gridColumnconfigure( $_, -weight => 1 ) for 1, 2;
$codelist->bind('<ButtonRelease-1>' =>
sub {$code = $codelist->get($codelist->curselection); ready() } );
$filelist->bind('<ButtonRelease-1>' =>
sub {$file = $filelist->get($filelist->curselection); ready() } );
sub execute
{
$execute++;
$mw->destroy;
}
sub ready { $code && $file and $button->configure(-state => 'normal')
+}
$codelist->insert(end => sort grep -x, path('.')->children(qr/\.pl$/)
+);
$filelist->insert(end => sort +path('.')->children(qr/\.d$/) );
MainLoop;
$execute or exit;
$code or die "no code selected";
$file or die "no file selected";
print "exec $code $file\n";
#exec 'perl', $code, $file; ### FIXME testing - uncomment to actually
+run
die "exec failed $!";
|