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
| #!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Cwd;
use utf8;
use Encode;
## VARIABLES
# Scalaires
my $localpath = cwd();
my $am_path;
my $file_amont = "../res/Exigences_Amont.txt";
my $data;
# Tableaux
# Widgets
my $frame;
my $etat;
my $label;
my $addr_am_prev;
my $result;
my $resultats;
my $widget_texte;
my $top;
my $top_texte;
## SOUS-PROGRAMMES
sub SauveFichier {
# Description : Permet de sauvegarder le fichier des exigences amont.
open FILE_AMONT, ">" . $file_amont or die "Le fichier $file_amont n'existe pas !";
$data = $top_texte->get( '1.0', 'end' );
print FILE_AMONT $data;
close FILE_AMONT;
$top->destroy;
$frame->deiconify();
$frame->raise();
$frame->focus();
open FILE_AM, '<', $addr_am_prev or die "Le fichier $addr_am_prev n'existe pas !";
# Traitements;
close FILE_AM;
return;
}
sub AfficheTopLevel {
# Création du TopLevel
$top = $frame->Toplevel(
-title => 'Exigences Amonts',
-width => 600,
-height => 600
);
# On crée le widget acceuillant les résultats
$label = $top->Label( -text => 'Veuillez entrer les exigences amonts', )->place(
-x => 0,
-y => 0,
-width => 600,
-height => 20
);
$top_texte = $top->Text()->place( -x => 0, -y => 30, -width => 600, -height => 520 );
# On crée le bouton.
$top->Button(
-text => 'OK',
-command => \&SauveFichier,
)->place( -x => 250, -y => 570, -width => 100, -height => 30 );
return;
}
sub SelectFile {
# Description : Fonction de sélection d'un fichier
# Récupération du fichier (.xml files)
my @types = ( [ "Data Files", '.xml', 'TEXT' ], [ "All Files", "*" ] );
$addr_am_prev = $frame->getOpenFile(
-initialdir => $ENV{AppliConfig}->{DefaultDirectory},
-multiple => 0,
-filetypes => \@types,
);
# Gestion des caractères spéciaux
if ( $^O =~ m{mswin32}i ) {
$addr_am_prev = encode( 'iso-8859-1', $addr_am_prev );
}
AfficheTopLevel();
return;
}
## PROGRAMME PRINCIPAL
#### Création du TopLevel
$frame = MainWindow->new( -title => 'Verif_Coherence_AM_PREV' );
$frame->minsize( '900', '600' );
# On crée le widget acceuillant les résultats
$widget_texte = $frame->Text();
$widget_texte->place( -x => 0, -y => 0, -width => 900, -height => 540 );
#### On crée les deux boutons.
$frame->Button(
-text => 'Ouvrir',
-command => \&SelectFile
)->place( -x => 100, -y => 550, -width => 200, -height => 30 );
$frame->Button(
-text => 'Quitter',
-command => sub { exit 0; }
)->place( -x => 600, -y => 550, -width => 200, -height => 30 );
# On centre la fenêtre
CentrerWidget($frame);
MainLoop;
sub CentrerWidget {
unless ( scalar(@_) == 1 ) {
die('Usage : CentrerWidget( $MainWidget );');
}
my ($Widget) = @_;
# Height and width of the screen
my $LargeurEcran = $Widget->screenwidth();
my $HauteurEcran = $Widget->screenheight();
# update le widget pour recuperer les vraies dimensions
$Widget->update;
my $LargeurWidget = $Widget->width;
my $HauteurWidget = $Widget->height;
# On centre le widget en fonction de la taille de l'ecran
my $NouvelleLargeur = int( ( $LargeurEcran - $LargeurWidget ) / 2 );
my $NouvelleHauteur = int( ( $HauteurEcran - $HauteurWidget ) / 2 );
$Widget->geometry( $LargeurWidget . "x" . $HauteurWidget . "+$NouvelleLargeur+$NouvelleHauteur" );
$Widget->update;
return;
} |
Partager