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
|
#--------------------Configuration----------------------------
my $bb_base = "B:\TLSE-data.bb";
#-------------------------GUI---------------------------------
use Tk;
my $mw = MainWindow -> new();
$mw -> title("BB!");
$mw->geometry("300x120");
my $b_menu = $mw -> Frame(-relief => 'groove', -borderwidth => 2);
my $menu_app = $b_menu -> Menubutton (-text => "File",
-tearoff => 0,
-relief => 'ridge',
-menuitems => [
['command' => "Create new TLSE",-command => \&create_tlse],
['command' => "Delete TLSE",-command => \&delete_tlse],
['command' => "Exit",-command => sub {exit;}]
]
);
$menu_app -> pack(-side => 'left');
$b_menu -> pack(-side => 'top', -anchor => 'n', -fill => 'x');
#Frame containing all TLSE
my $all_tlse = $mw -> Frame(-relief => 'raised', -borderwidth => 2) -> pack();
#Last line
my $end = $mw -> Label(-relief => 'groove', -text => "2010", -font => '{Garamond} 10') -> pack (-side => 'bottom', -fill => 'both');
#Load all TLSE already declared in the BB file and their workload
init();
my %the_tlse;
MainLoop;
#---------------------Subfonction------------------------------
sub create_tlse {
my $tlse_creation = $mw->Toplevel();
my $tlse_creation_title = $tlse_creation->Label( -text => "Create a new TLSE" )->pack();
my $ent_name = $tlse_creation->Entry()->pack();
my $valid_button = $tlse_creation->Button(
-text => "Create",
-command => [ \&tlse, $ent_name ]
)->pack( -side => 'left' );
my $but_close = $tlse_creation->Button(
-text => "Close",
-command => sub { destroy $tlse_creation; }
)->pack();
$the_tlse{$ent_name} = $tlse_creation;
return;
}
sub tlse {
my ($ent_name) = @_;
#Frame TLSE
my $tlse_name = $all_tlse->Frame(
-relief => 'groove',
-borderwidth => 2
)->pack( -side => 'left' );
my $name = $ent_name->get();
#create the entry in the bb file
open( FILE, '>>', $bb_base ) or die("problem to open the bb file.");
print FILE "\n";
print FILE $name;
#By default, at the TLSE creation, the workload is set to 0
print FILE ";0;";
close FILE;
my $lb_name = $tlse_name->Label( -text => "$name" )->pack( -side => 'top' );
#By default, at the TLSE creation, the workload is set to 0
my $valeur_workload = 0;
my $lb_workload = $tlse_name->Label( -textvariable => \$valeur_workload )->pack();
my $minus_button = $tlse_name->Button(
-text => "-",
-command => [ \&push_minus, \$valeur_workload ]
)->pack( -side => 'left' );
my $plus_button = $tlse_name->Button(
-text => "+",
-command => [ \&push_plus, \$valeur_workload ]
)->pack( -side => 'right' );
return;
}
sub push_minus {
my ($ref_valeur_workload) = @_;
if (${$ref_valeur_workload} > 0){
${$ref_valeur_workload}--;
}
elsif (${$ref_valeur_workload} == 0){
my $message = $all_tlse->messageBox(-title=>'Message',
-message=>'The workload could not be negative!');
}
return;
}
sub push_plus {
my ($ref_valeur_workload) = @_;
${$ref_valeur_workload}++;
return;
}
sub init {
#Load all TLSE already declared in the BB file and their workload
my %init_bb;
open(FILE,'<', $bb_base) or die ("problem to open the $bb_base file.");
while ( my $bb = <FILE> ) {
if ( $bb !~ /^#/ ){
my ($workload, $tlse) = (split m/\;/, $bb);
$init_bb{$workload} = $tlse;
}
}
foreach (keys(%init_bb)){
my $valeur_workload = $init_bb{$_};
my $tlse_name = $all_tlse -> Frame(-relief => 'groove', -borderwidth => 2) -> pack(-side => 'left');
my $lb_name = $tlse_name->Label( -text => "$_" )->pack( -side => 'top' );
my $lb_workload = $tlse_name->Label( -textvariable => \$valeur_workload )->pack();
my $minus_button = $tlse_name->Button(
-text => "-",
-command => [ \&push_minus, \$valeur_workload ]
)->pack( -side => 'left' );
my $plus_button = $tlse_name->Button(
-text => "+",
-command => [ \&push_plus, \$valeur_workload ]
)->pack( -side => 'right' );
}
return;
}
sub delete_tlse {
my $tlse_deletion = $mw->Toplevel();
my $tlse_deletion_title = $tlse_deletion->Label( -text => "Delete a TLSE" )->pack();
my $to_be_deleted = $tlse_deletion->Entry()->pack();
my $valid_deletion = $tlse_deletion->Button(
-text => "Delete",
-command => [ \&del, $to_be_deleted ]
)->pack( -side => 'left' );
my $deletion_close = $tlse_deletion->Button(
-text => "Close",
-command => sub { destroy $tlse_deletion; }
)->pack();
#remove the entry from the hash $the_tlse{$ent_name} = $tlse_creation;
return;
}
sub del {
my ($to_be_deleted) = @_;
my $tbd = $to_be_deleted->get();
if ( Exists $the_tlse{$tbd} ) {
$the_tlse{$tbd}->destroy;
}
} |
Partager