#!/usr/bin/env perl
use warnings;
use strict;
use Tk;
my %script_mod_for = (
Freeze => 'Pm_1148798_freeze_tk_mod',
Dummy => 'Pm_1148798_dummy_tk_mod',
);
my $mw = MainWindow::->new();
$mw->geometry("500x300+50+50");
my $script_F = $mw->Frame->pack(-side => 'bottom', -fill => 'x');
my $button_F = $mw->Frame->pack(-side => 'left', -fill => 'y');
my $text_ST = $mw->Scrolled('Text', -scrollbars => 'se'
)->pack(-expand => 1, -fill => 'both');
my @script_buttons;
push @script_buttons, $button_F->Button(-text => $_, -command => [
\&show_script_gui, $_, $script_mod_for{$_},
$script_F, $text_ST, \@script_buttons
])->pack(-fill => 'x') for keys %script_mod_for;
$button_F->Button(-text => 'Exit', -command => sub { exit }
)->pack(-fill => 'x');
MainLoop;
sub show_script_gui {
my ($script, $mod, $script_F, $text_ST, $script_buttons) = @_;
$text_ST->insert(end => "Running script: $script\n");
eval "require $mod";
$_->configure(-state => 'disabled') for @$script_buttons;
$mod->run($script_F, $text_ST, $script_buttons);
}
####
package Pm_1148798_freeze_tk_mod;
use strict;
use warnings;
require Tk::BrowseEntry;
sub run {
my ($class, $script_F, $text_ST, $script_buttons) = @_;
my ($yyyy, $mmm, $dd) = ('') x 3;
my @years = 2013 .. 2020;
my @months = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec};
my @days = map { sprintf '%02d', $_ } 1 .. 31;
my $temp_F = $script_F->Frame->pack;
my $done_B;
my %common_be_opts = (
-state => 'readonly', -autolistwidth => '1',
-justify => 'right', -buttontakefocus => 1,
-browsecmd => sub {
$done_B->configure(
-state => $yyyy && $mmm && $dd ? 'normal' : 'disabled'
)
}
);
my %be_pack_opts = (
-ipadx => 15, -side => 'top', -anchor => 'e', -expand => 1
);
my $y_BE = $temp_F->BrowseEntry(%common_be_opts,
-label => 'Select Year', -textvariable => \$yyyy
)->pack(%be_pack_opts);
$y_BE->insert(end => @years);
my $m_BE = $temp_F->BrowseEntry(%common_be_opts,
-label => 'Select Month', -textvariable => \$mmm
)->pack(%be_pack_opts);
$m_BE->insert(end => @months);
my $d_BE = $temp_F->BrowseEntry(%common_be_opts,
-label => 'Select Day', -textvariable => \$dd
)->pack(%be_pack_opts);
$d_BE->insert(end => @days);
$done_B = $temp_F->Button(-text => 'Done', -state => 'disabled',
-command => sub {
$text_ST->insert(end =>
"Selected day: $dd\n" .
"Selected month: $mmm\n" .
"Selected year: $yyyy\n"
);
$temp_F->destroy;
$script_F->configure(-height => 1);
$_->configure(-state => 'normal') for @$script_buttons;
})->pack;
}
1;
####
package Pm_1148798_dummy_tk_mod;
use strict;
use warnings;
sub run {
my ($class, $script_F, $text_ST, $script_buttons) = @_;
my $temp_F = $script_F->Frame->pack;
$temp_F->Label(-text => 'Dummy Frame for Testing Purposes')->pack;
$temp_F->Button(-text => 'Done', -command => sub {
$temp_F->destroy;
$script_F->configure(-height => 1);
$_->configure(-state => 'normal') for @$script_buttons;
})->pack;
$text_ST->insert(end => "Dummy line 1\n");
$text_ST->insert(end => "Dummy line 2\n");
}
1;
####
Running script: Dummy
Dummy line 1
Dummy line 2
Running script: Freeze
Selected day: 05
Selected month: Jul
Selected year: 2015
Running script: Dummy
Dummy line 1
Dummy line 2
Running script: Dummy
Dummy line 1
Dummy line 2
Running script: Freeze
Selected day: 06
Selected month: Nov
Selected year: 2018