1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| package setSetting;
use lib '.';
use Cwd qw(abs_path);
use FindBin qw($Bin);
use lib "$Bin/../lib/perl";
use Thread::Semaphore;
use Tk;
use Tk::FileSelect;
use Tk::ItemStyle;
use Tk::HList;
use Tk::JComboBox;
use strict;
use warnings;
my ( $settingName, $choice, $defaultVal, @values, %choices, $mw );
sub initTask {
my $task = shift;
eval "require $task";
my %settings = map { $_->getName => $_ } $task->getTaskSettings();
return (%settings);
}
sub init {
my ( $setting, $task, $win ) = @_;
eval "require $task";
my %settings = map { $_->getName => $_ } $task->getTaskSettings();
my $desc = $settings{$setting}->getDescription;
my $type = $settings{$setting}->getType;
my $mandatory = $settings{$setting}->isMandatory;
$settingName = $settings{$setting}->getName;
@values = $settings{$setting}->getValues;
$defaultVal = $settings{$setting}->getDefault;
$mw = $win->Toplevel();
#$mw = new MainWindow(-bg => 'alice blue');
$mw->title('Demonstrator: Set Settings -Wotan2.2');
$mw->fontCreate( "lucida", -family => 'lucida', -size => '12' );
$mw->minsize( 350, 100 );
if ( $type eq 'text' ) { popText(); }
if ( $type eq 'file' ) { popFile(); }
if ( $type eq 'singleValue' ) { popSingleValue(); }
if ( $type eq 'multiValue' ) { popMultiValue(); }
if ( defined $err[0] ) { print "@err\n"; }
return ($choice);
}
sub getFile {
my $f = $mw->getOpenFile(
-title => "Select the file you want to use for $settingName" );
if ( defined $f ) { $choice = $f; $mw->destroy; return; }
}
sub popText {
my $frame = $mw->Frame(
-relief => 'groove',
-background => 'light cyan',
-borderwidth => 3
)->pack( -side => 'top', -fill => 'x' );
my $label = $frame->Label(
-text => '',
-background => 'light cyan',
-foreground => 'black'
)->pack( -side => 'left' );
my $ent
= $frame->Entry( -width =>, -background => 'white', -textvariable => )
->pack( -side => 'left', -pady => 3, -padx => 135 );
return;
}
sub popFile {
my $frame = $mw->Frame(
-relief => 'groove',
-background => 'light cyan',
-borderwidth => 3
)->pack( -side => 'top', -fill => 'both', -expand => 1 );
my $label = $frame->Label(
-font => 'lucida',
-text => "set the value of the setting $settingName",
-background => 'light cyan',
-foreground => 'black'
)->pack( -side => 'left', -padx => 10 );
my $ent = $frame->Entry(
-background => 'white',
-textvariable => \$choice,
-width => length($defaultVal) - 26
)->pack( -side => 'left', -pady => 3, -padx => 10 );
my $Btt1 = $frame->Button( -text => "Browse", -command => \&getFile )
->pack( -side => 'right', -pady => 10, -padx => 10 );
my $Btt2 = $frame->Button(
-text => "OK",
-command => sub { $mw->destroy; return }
)->pack( -side => 'right', -pady => 10, -padx => 10 );
return;
}
sub popSingleValue {
my $answer;
my $frame = $mw->Frame(
-relief => 'groove',
-background => 'azure2',
-borderwidth => 3
)->pack( -side => 'top', -fill => 'x' );
my $label = $frame->Label(
-font => 'lucida',
-text => "set the value of the setting $settingName",
-background => 'azure2',
-foreground => 'black'
)->pack( -side => 'left' );
my $jcb = $frame->JComboBox(
-entrybackground => 'white',
-mode => 'readonly',
-relief => 'sunken',
-textvariable => \$answer,
-choices => \@values
)->pack;
my $frame2 = $mw->Frame(
-relief => 'groove',
-background => 'alice blue',
-borderwidth => 3
)->pack( -side => 'top', -fill => 'both', -expand => '1' );
#my $Btt1=$frame2->Button( -text => "OK", -command => sub {$choice=$answer;$s->up;$mw->destroy;})-> pack(-side=> 'left', -pady=> 10, -padx=> 70);
my $Btt1 = $frame2->Button(
-text => "OK",
-command => sub { $choice = $answer; $mw->destroy; }
)->pack( -side => 'left', -pady => 10, -padx => 70 );
my $Btt2 = $frame2->Button(
-text => "Cancel",
-command => sub { $choice = "$defaultVal"; $mw->destroy; }
)->pack( -side => 'right', -after => $Btt1, -pady => 10, -padx => 70 );
}
sub popMultiValue {
my $frame = $mw->Frame(
-relief => 'groove',
-background => 'azure2',
-borderwidth => 3
)->pack( -side => 'top', -fill => 'x' );
my $label = $frame->Label(
-font => 'lucida',
-text => "set the value of the setting $settingName :",
-background => 'azure2',
-foreground => 'black'
)->pack( -side => 'top' );
foreach (@values) {
$choices{$_} = 0;
$frame->Checkbutton(
-textvariable => \$_,
-variable => \$choices{$_},
-bg => 'ghost white'
)->pack( -side => 'top', -pady => 5 );
}
my $Btt1 = $frame->Button(
-text => "OK",
-command => sub { finalizeMultiOption(); $mw->destroy; return; }
)->pack( -side => 'left', -pady => 10, -padx => 70 );
my $Btt2 = $frame->Button(
-text => "Cancel",
-command => sub { $choice = "$defaultVal"; $mw->destroy; return; }
)->pack( -side => 'right', -after => $Btt1, -pady => 10, -padx => 70 );
}
sub finalizeMultiOption {
if (%choices) {
$choice = '';
my $flag = 0;
foreach (@values) {
if ( $choices{$_} == 1 ) {
if ( $choice eq '' ) { $choice = $_; }
else { $choice = $choice . ' ' . $_; }
$flag = 1;
}
}
if ( $flag == 0 ) { $choice = $defaultVal; }
}
return;
}
1; |
Partager