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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946
| use strict;
use warnings;
use utf8;
use Tk; # Interface graphique
use Tk::LabFrame; # Pour utiliser LabFrame
use Tk::ROText; # Pour mettre un widget en lecture seule
use File::Spec; # Permet une meilleure gestion des noms des chemins sous tous les OS.
use Config::Std; # Lecture/ecriture d'un fichier .ini
use File::Basename; # Pour récupérer le nom du fichier sans le path complet
# Initialisation de variables
my $RepBase = 'E:/_DEV/_Younes';
# Lecture du fichier de configuration
my $fichier_configuration = File::Spec->catfile( $RepBase, 'config.ini' );
my %config;
if ( -e $fichier_configuration ) {
read_config $fichier_configuration => %config;
}
else {
%config = (
'GLOBAL' => {
Resultat => 1,
Deduction => 1,
Debug => 1,
FicLog => 'Younes.log',
FicResul => 'Resultat.txt',
FicDeduc => 'Deduction.txt',
},
'DOCU' => {
Rep => 'Docu',
Fic => 'ETH.txt',
},
'DICO' => {
Rep => 'Dico',
Fic => 'DicoEth.txt',
}
);
}
my ( $FicDebug, $fh_Debug, $Choix_Debug ) = ();
$Choix_Debug = $config{GLOBAL}{Debug};
my $Choix_Fichier_Resultat = $config{GLOBAL}{Resultat};
my $Choix_Fichier_Deduction = $config{GLOBAL}{Deduction};
my $FicResultat = File::Spec->catfile( $RepBase, $config{GLOBAL}{FicResul} );
my $FicDeduction = File::Spec->catfile( $RepBase, $config{GLOBAL}{FicDeduc} );
my $fh_Resul;
my $fh_Deduc;
my ( $LabRepDocu, $LabRepDico, $MsgErreur, ) = ();
my @nom_recuperer = ();
my $Stop ='';
my $RepDocu = File::Spec->catfile( $RepBase, $config{DOCU}{Rep} );
my $RepDico = File::Spec->catfile( $RepBase, $config{DICO}{Rep} );
my @PathsDocu = split ( / /, $config{DOCU}{Fic} );
my @PathsDico = split ( / /, $config{DICO}{Fic} );
# Création d'une fenêtre bidon pour récupérer les dimensions de l'écran
my $fen = MainWindow->new;
my $width = $fen->screenwidth();
my $height = $fen->screenheight();
$fen->destroy();
# Creation du widget principal
my $Wm = MainWindow->new(
-width => $width,
-height => $height,
-background => 'white',
);
$width = $Wm->screenwidth*(4/5);
$height = $Wm->screenheight*(4/5);
$Wm->configure(-height=>$height, -width=>$width, -title=>"Younes");
$Wm->geometry( $width ."x". $height );
$Wm->MoveToplevelWindow (100,100);
#$Wm->overrideredirect(1);
#$Wm->packPropagate(0);
#$Wm->raise();
# Invalidation fermeture -> obligation de passer par exit
$Wm->protocol( "WM_DELETE_WINDOW", sub {
fermer_application($Wm, $fichier_configuration, \%config);
} );
####################################
# Interface graphique
my $couleur_commune = '#E0F0FF';
####################################
# Cadre pour les messages de service
my $cadre_messages = $Wm->Frame( -background => $couleur_commune, );
# Label qui affichera les messages concernant les documents
my $label_documents = $cadre_messages->Label(
-textvariable => \$LabRepDocu,
-background => '#FFE0D0',
-relief => 'groove',
);
# Label qui affichera les messages concernant les dictionnaires
my $label_dictionnaires = $cadre_messages->Label(
-textvariable => \$LabRepDico,
-background => '#FFE0D0',
-relief => 'groove',
);
# Label qui affichera les messages d'erreur
my $label_msg_erreur = $cadre_messages->Label(
-textvariable => \$MsgErreur,
-background => '#FFE0D0',
-relief => 'groove',
);
#################
# Cadre résultats
my $cadre_Resultats = $Wm->Frame();
my $LabFrame_Resultats = $cadre_Resultats->LabFrame(
-label => 'Résultats',
-background => '#DCDCDC',
-font => '{Simplified Arabic} 10 {bold}',
);
# Scrolled qui affiche les résultats
my $widget_Resultats = $LabFrame_Resultats->Scrolled(
'ROText',
-scrollbars => 'e',
-takefocus => 0,
-wrap => 'word',
-background => '#ABFAA3',
);
configurer_tags($widget_Resultats);
# Label pour les déductions
my $LabFrame_Deductions = $cadre_Resultats->LabFrame(
-label => 'Déductions',
-background => '#DCDCDC',
-font => '{Simplified Arabic} 10 {bold}',
);
# Scrolled qui affiche les déductions
my $widget_Deductions = $LabFrame_Deductions->Scrolled(
'ROText',
-scrollbars => 'e',
-takefocus => 0,
-wrap => 'word',
-background => '#ABFAA3',
);
configurer_tags($widget_Deductions);
#################
# Cadre des paths
my $cadre_Paths = $Wm->Frame( -background => $couleur_commune, );
###########
# Documents
# Label pour les paths des documents
my $LabFrame_Documents = $cadre_Paths->LabFrame(
-label => 'Documents',
-background => '#DCDCDC',
-font => '{Simplified Arabic} 10 {bold}',
);
# Scrolled qui affiche les paths des documents
my $widget_Documents = $LabFrame_Documents->Scrolled(
'ROText',
-scrollbars => 'e',
-takefocus => 0,
-wrap => 'word',
-background => '#FFE0D0',
);
configurer_tags($widget_Documents);
# Remplissage de $widget_Documents avec les infos du fichiers config.ini
foreach my $PathDocu (@PathsDocu) {
$widget_Documents->insert( 'end', "$PathDocu\n", "g12" );
}
###############
# Dictionnaires
# Label pour les paths des dictionnaires
my $LabFrame_Dictionnaires = $cadre_Paths->LabFrame(
-label => 'Dictionnaires',
-background => '#DCDCDC',
-font => '{Simplified Arabic} 10 {bold}',
);
# Scrolled qui affiche les paths des dictionnaires
my $widget_Dictionnaires = $LabFrame_Dictionnaires->Scrolled(
'ROText',
-scrollbars => 'e',
-takefocus => 0,
-wrap => 'word',
-background => '#FFE0D0',
);
configurer_tags($widget_Dictionnaires);
# Remplissage de $widget_Dictionnaires avec les infos du fichiers config.ini
foreach my $PathDico (@PathsDico) {
$widget_Dictionnaires->insert( 'end', "$PathDico\n", "g12" );
}
###################################################
# Cadre du haut Documents - Dictionnaires - Gestion
#==================================================
# Label pour les documents
my $Frame_Documents = $Wm->LabFrame(
-label => 'Documents',
-background => $couleur_commune,
-font => '{Simplified Arabic} 10 {bold}',
);
# Bouton effacer documents
my $bouton_EffDocu = $Frame_Documents->Button(
-text => "Efface",
-command => sub {
$widget_Documents->delete( '1.0', 'end' );
$widget_Documents->update;
$widget_Documents->see('end');
undef @PathsDocu;
$widget_Resultats->delete( '1.0', 'end' );
$widget_Resultats->update;
$widget_Resultats->see('end');
$widget_Deductions->delete( '1.0', 'end' );
$widget_Deductions->update;
$widget_Deductions->see('end');
}
);
# Choix du répertoire des documents et récupération des fichiers .txt
my $widget_RepDocu = $Frame_Documents->Button(
-text => "Documents",
-command => sub {
# Selectionner un répertoire
my $Rep = $Wm->chooseDirectory(
-title => "Choix d'un document",
-initialdir => $RepDocu,
);
if ( $Rep) {
$LabRepDocu = $Rep;
my $types = [
[ 'Fichiers texte', '.txt' ],
[ 'Tous les fichiers', '*' ],
];
my @PathsDocuWidget = $Wm->getOpenFile(
-filetypes => $types,
-initialdir => "$RepDocu",
-multiple => 1,
);
foreach my $PathDocu (@PathsDocuWidget) {
$widget_Documents->insert( 'end', "$PathDocu\n", "g12" );
push @PathsDocu, $PathDocu;
}
@PathsDocu = doublons_grep( \@PathsDocu );
@PathsDocu = sort @PathsDocu;
( $config{DOCU}{Fic} ) = join(" ",@PathsDocu);
$Wm->update();
}
},
);
#===========================================================
# Label pour les dictionnaires
my $Frame_Dictionnaires = $Wm->LabFrame(
-label => 'Dictionnaires',
-background => $couleur_commune,
-font => '{Simplified Arabic} 10 {bold}',
);
# Bouton effacer dictionnaires
my $bouton_EffDico = $Frame_Dictionnaires->Button(
-text => "Efface",
-command => sub {
$widget_Dictionnaires->delete( '1.0', 'end' );
$widget_Dictionnaires->update;
$widget_Dictionnaires->see('end');
undef @PathsDico;
$widget_Resultats->delete( '1.0', 'end' );
$widget_Resultats->update;
$widget_Resultats->see('end');
$widget_Deductions->delete( '1.0', 'end' );
$widget_Deductions->update;
$widget_Deductions->see('end');
}
);
# Choix du répertoire des dictionnaires et récupération des fichiers .txt
my $widget_RepDico = $Frame_Dictionnaires->Button(
-text => "Dictionnaires",
-command => sub {
# Selectionner un répertoire
my $Rep = $Wm->chooseDirectory(
-title => "Choix d'un dictionnaire",
-initialdir => $RepDico,
);
if ( $Rep) {
$LabRepDico = $Rep;
my $types = [
[ 'Fichiers texte', '.txt' ],
[ 'Tous les fichiers', '*' ],
];
my @PathsDicoWidget = $Wm->getOpenFile(
-filetypes => $types,
-initialdir => "$RepDico",
-multiple => 1,
);
foreach my $PathDico (@PathsDicoWidget) {
$widget_Dictionnaires->insert( 'end', "$PathDico\n", "g12" );
push @PathsDico, $PathDico;
}
@PathsDico = doublons_grep( \@PathsDico );
@PathsDico = sort @PathsDico;
( $config{DICO}{Fic} ) = join(" ",@PathsDico);
$Wm->update();
}
},
);
#===========================================================
# Label pour la gestion
my $Frame_Gestion = $Wm->LabFrame(
-label => ' Gestion ',
-background => $couleur_commune,
-font => '{Simplified Arabic} 10 {bold}',
);
# Fichier résultats
my $case_Resultat = $Frame_Gestion->Checkbutton (
-text => "Fichier résultats",
-variable => \$Choix_Fichier_Resultat,
-command => sub {
$config{GLOBAL}{Resultat} = $Choix_Fichier_Resultat;
},
);
# Fichier déductions
my $case_Deduction = $Frame_Gestion->Checkbutton (
-text => "Fichier déductions",
-variable => \$Choix_Fichier_Deduction,
-command => sub {
$config{GLOBAL}{Deduction} = $Choix_Fichier_Deduction;
},
);
# Fichier debug
my $case_Debug = $Frame_Gestion->Checkbutton (
-text => "Fichier debug",
-variable => \$Choix_Debug,
-command => sub {
$config{GLOBAL}{Debug} = $Choix_Debug;
},
);
# Start
my $bouton_start = $Frame_Gestion->Button(
-text => 'Start',
-command => [ \&start ],
);
# Stop
my $bouton_stop = $Frame_Gestion->Button(
-text => 'Stop',
-command => [ \&stop, ],
);
# Sav
my $bouton_sav = $Frame_Gestion->Button(
-text => 'Save',
-command => [ \&sav, $Wm, $fichier_configuration, \%config ],
);
# Exit
my $bouton_exit = $Frame_Gestion->Button(
-text => 'Exit',
-command => [ \&fermer_application, $Wm, $fichier_configuration, \%config ],
);
####################################
# Gestion de l'affichage des widgets
#
$cadre_messages->pack (qw / -side bottom -fill both -expand 0 /);
$label_documents->pack (qw / -side left -fill both -expand 1 /);
$label_dictionnaires->pack (qw / -side left -fill both -expand 1 /);
$label_msg_erreur->pack (qw / -side left -fill both -expand 1 /);
$cadre_Resultats->pack (qw / -side bottom -fill both -expand 1 /);
$LabFrame_Resultats->pack (qw / -side left -fill both -expand 1 /);
$widget_Resultats->pack (qw / -side bottom -fill both -expand 1 /);
$LabFrame_Deductions->pack (qw / -side left -fill both -expand 1 /);
$widget_Deductions->pack (qw / -side bottom -fill both -expand 1 /);
$cadre_Paths->pack (qw / -side bottom -fill both -expand 1 /);
$LabFrame_Documents->pack (qw / -side left -fill both -expand 1 /);
$widget_Documents->pack (qw / -side bottom -fill both -expand 1 /);
$LabFrame_Dictionnaires->pack (qw / -side left -fill both -expand 1 /);
$widget_Dictionnaires->pack (qw / -side bottom -fill both -expand 1 /);
$Frame_Documents->pack (qw / -side left -fill both -expand 1 /);
$Frame_Dictionnaires->pack (qw / -side left -fill both -expand 1 /);
$Frame_Gestion->pack (qw / -side left -fill both -expand 1 /);
$bouton_EffDocu->grid( $widget_RepDocu, qw / -padx 8 -pady 5 -sticky nsew /);
$bouton_EffDico->grid( $widget_RepDico, qw / -padx 8 -pady 5 -sticky nsew /);
$case_Resultat->grid( $case_Deduction, $case_Debug, $bouton_start, $bouton_stop, $bouton_sav, $bouton_exit, qw / -padx 7 -pady 5 -sticky nsew /);
centrer_widget($Wm);
$label_msg_erreur->eventAdd( '<<virtual_clic1>>' => '<Button-1>' ) ;
MainLoop;
# Pour avoir les accents sur la console DOS
ActiverAccentDOS();
#######################
# Démarre l'application
sub start {
$label_msg_erreur->bind( '<<virtual_clic1>>' => \&ClearMessage ) ;
$label_msg_erreur->configure( -background => '#FFE0D0' );
$MsgErreur = '';
$Stop = '';
$widget_Resultats->delete( '1.0', 'end' );
$widget_Resultats->update;
$widget_Resultats->see('end');
$widget_Deductions->delete( '1.0', 'end' );
$widget_Deductions->update;
$widget_Deductions->see('end');
if ( $Choix_Fichier_Resultat ) {
open $fh_Resul, '>:utf8', $FicResultat or die("Impossible ouvrir $FicResultat \t$!");
}
if ( $Choix_Fichier_Deduction ) {
open $fh_Deduc, '>:utf8', $FicDeduction or die("Impossible ouvrir $FicDeduction \t$!");
}
if ( $Choix_Debug ) {
$FicDebug = File::Spec->catfile( $RepBase, $config{GLOBAL}{FicLog} );
open $fh_Debug, '>:utf8', $FicDebug or die("Impossible ouvrir $FicDebug \t$!");
}
if ( $Choix_Debug ) {
print $fh_Debug "\nLISDOCS=@PathsDocu=\n";
print $fh_Debug "LISTDICO=@PathsDico=\n";
}
if ( !@PathsDocu ) {
err("ATTENTION Il n'y a pas de document à analyser ARRET");
}
if ( !@PathsDico ) {
err("ATTENTION Il n'y a pas de dictionnaire pour faire le traitement ARRET");
}
my @TabMots = ();
my $fh_Dico;
my (%Exist, @MotUnique);
foreach my $PathDico (@PathsDico) {
if ( $Stop eq 'STOP' ) {
last;
}
open $fh_Dico , '<:utf8', $PathDico
or die("Impossible ouvrir $PathDico \t$!");
@TabMots = <$fh_Dico>;
close $fh_Dico;
chomp (@TabMots);
foreach my $Elem ( @TabMots ) {
push @MotUnique, $Elem unless defined $Exist{$Elem} ;
$Exist{$Elem} = 1;
}
}
if ( $Choix_Debug ) {
print $fh_Debug "\nMOT_UNIQUE=@MotUnique=\n";
}
foreach my $Document (@PathsDocu) {
if ( $Stop eq 'STOP' ) {
last;
}
if ( $Choix_Debug ) {
print $fh_Debug "\nTRAITEMENT_DOCUMENT=$Document=\n";
}
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "\n\n=============================================";
print $fh_Resul "Traitement du fichier $Document :\n";
}
$widget_Resultats->insert( 'end', "\n=============================================", "g14" );
$widget_Resultats->insert( 'end', "Traitement du fichier $Document :\n", "g14" );
my $In_Fic = $Document;
if ( -z $In_Fic ) {
ano ("ATTENTION le document $Document est VIDE !!!");
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "\t\tATTENTION le document $Document est VIDE !!!\n";
}
$widget_Resultats->insert( 'end', "\t\tATTENTION le document $Document est VIDE !!!\n", "g12" );
if ( $Choix_Fichier_Deduction ) {
print $fh_Deduc "\t\tATTENTION le document $Document est VIDE !!!\n";
}
$widget_Deductions->insert( 'end', "\t\tATTENTION le document $Document est VIDE !!!\n", "g12" );
}
my $fh_Entree;
open $fh_Entree, '<:utf8', $In_Fic
or die("Impossible ouvrir $In_Fic \t$!");
my %Comptage = ();
my $NbLigne;
while ( my $Ligne = <$fh_Entree> ) {
if ( $Stop eq 'STOP' ) {
last;
}
$NbLigne++;
foreach my $Mot (@MotUnique) {
chomp $Mot;
if ( $Ligne =~ $Mot ) {
$Comptage{$Mot}++;
#print $fh_Resul "$Mot a la ligne $NbLigne\n";
}
}
}
while ( my ( $Mot, $Nb ) = each(%Comptage) ) {
if ( $Stop eq 'STOP' ) {
last;
}
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "Le mot '$Mot' est present $Nb fois\n";
}
$widget_Resultats->insert( 'end', "Le mot '$Mot' est present $Nb fois\n", "g8" );
#remplir les mots trouver dans le tableau[] nom_recuperer
push @nom_recuperer, $Mot;
}
if ( $Choix_Debug ) {
print $fh_Debug "\nNOM_RECUPERER=@nom_recuperer=\n";
}
#comparer les mots avec tous les dico
if ( $Choix_Fichier_Deduction ) {
print $fh_Deduc "\n\nDéduction :\n";
}
$widget_Deductions->insert( 'end', "\n\nDéduction :\n", "g12" );
foreach my $PathDico (@PathsDico) {
if ( $Stop eq 'STOP' ) {
last;
}
if ( $Choix_Debug ) {
print $fh_Debug "\nCOMPARER_AVEC_DICO=$PathDico=\n";
}
my $pourcentage_appr = compare_with_dic($Document, $PathDico);
my $pourcentage;
my $deduction;
my $FileDico = fileparse($PathDico);
if ( $config{DEDU}{$FileDico} ) {
$deduction = $config{DEDU}{$FileDico};
} else {
$deduction = "Déduction indéderminée";
}
if ( $Choix_Fichier_Deduction ) {
$pourcentage = sprintf( "%0.2f", $pourcentage_appr );
print $fh_Deduc "$Document est $PathDico à $pourcentage %\n";
}
$widget_Deductions->insert( 'end', "$Document $deduction à $pourcentage %\n", "g12" );
}
undef %Comptage;
undef @nom_recuperer;
close $fh_Entree
}
if ( $Choix_Fichier_Resultat ) {
close $fh_Resul;
}
if ( $Choix_Fichier_Deduction ) {
close $fh_Deduc;
}
if ( $Choix_Debug ) {
print $fh_Debug "\nEXIT=\n";
close $fh_Debug;
}
}
################################################################
sub compare_with_dic {
my ( $Document, $Dico ) = @_;
if ( $Choix_Debug ) {
print $fh_Debug "\nCOMPARE_WITH_DIC=$Document=====$Dico=\n";
}
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "\nComparaison de $Document avec $Dico\n";
}
$widget_Resultats->insert( 'end', "Comparaison de $Document avec $Dico\n", "g12" );
my $count = 0;
my %hash;
@hash{@nom_recuperer} = 0 .. $#nom_recuperer;
my $PathDico = File::Spec->catfile( $RepBase, $Dico );
open my $fh_Dico , '<:utf8', $Dico
or die("Impossible ouvrir $Dico \t$!");
my @TabMots = <$fh_Dico>;
close $fh_Dico;
chomp (@TabMots);
my $NbDico = scalar(@TabMots);
if ($NbDico) {
for my $val (@TabMots) {
chomp $val;
if ( exists $hash{$val} ) {
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "Le mot $val est présent dans $Dico la position $hash{$val}.\n";
}
$widget_Resultats->insert( 'end', "Le mot $val est présent dans $Dico la position $hash{$val}.\n", "g8" );
$count += 1;
} else {
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "---->$val n'est pas dans $Dico.\n";
}
$widget_Resultats->insert( 'end', "---->$val n'est pas dans $Dico.\n", "g10" );
}
}
my $pourcentage;
my $pourcentage_appr = ( $count * 100 ) / $NbDico;
$pourcentage = sprintf( "%0.2f", $pourcentage_appr );
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "\nLe nombre de mots du fichier $Document présents dans $Dico est $count\n\t===> le pourcentage par raport au $Dico = $pourcentage %";
}
$widget_Resultats->insert( 'end', "Le nombre de mots du fichier $Document présents dans $Dico est $count\n", , 'fbleu' );
$widget_Resultats->insert( 'end', "===> le pourcentage par raport au $Dico = $pourcentage %\n", , 'fbleu' );
return $pourcentage_appr;
} else {
ano ("ATTENTION $Dico est VIDE !!!");
if ( $Choix_Fichier_Resultat ) {
print $fh_Resul "\n\t\tATTENTION $Dico est VIDE !!!\n";
}
$widget_Resultats->insert( 'end', "\n\t\tATTENTION $Dico est VIDE !!!\n", "g12" );
if ( $Choix_Fichier_Deduction ) {
print $fh_Deduc "\n\t\tATTENTION $Dico est VIDE !!!\n";
}
$widget_Deductions->insert( 'end', "\n\t\tATTENTION $Dico est VIDE !!!\n", "g12" );
return 0;
}
}
##########
# Anomalie
sub ano {
my ( $Ano ) = @_;
$MsgErreur = $Ano;
$Wm->bell();
$Wm->update();
if ( $Choix_Debug ) {
print $fh_Debug "\n----------->ANO=$MsgErreur=\n";
}
return;
}
########
# Erreur
sub err {
my ( $Ano ) = @_;
$label_msg_erreur->configure( -background => '#FF0000' );
$MsgErreur = $Ano;
$Wm->bell();
$Wm->update();
if ( $Choix_Debug ) {
print $fh_Debug "\n---------->ERR=$MsgErreur=\n";
}
return;
}
#########################
# Efface message d'erreur
sub ClearMessage {
$MsgErreur = '';
$label_msg_erreur->configure( -background => '#FFE0D0' );
}
######
# Stop
sub stop {
$label_msg_erreur->configure( -background => $couleur_commune );
$Wm->bell();
$Stop = 'STOP';
$MsgErreur = 'Traitement stoppé';
$Wm->update();
return;
}
###########################
# Sauvegarde des paramètres
sub sav {
my ( $mw, $fichier, $ref_config ) = @_;
# Sauvegarder configuration
sauvegarde_configuration( $fichier, $ref_config );
$MsgErreur = 'Paramètres sauvegardés';
return;
}
##########################
# Sauvegarde configuration
sub sauvegarde_configuration {
my ( $fichier, $ref_config ) = @_;
write_config %{$ref_config}, $fichier;
return;
}
#######################
# Exit de l'application
sub fermer_application {
my ( $Wm, $fichier, $ref_config ) = @_;
$Stop = "Fin";
my %Old_config;
if ( -e $fichier_configuration ) {
read_config $fichier_configuration => %Old_config;
} else {
%Old_config = (
'GLOBAL' => {
Debug => 'NON',
},
'DOCU' => {
Rep => 'Docu',
Fic => 'ETH.txt',
},
'DICO' => {
Rep => 'Dico',
Fic => 'DicoEth.txt',
}
);
}
if ( $Old_config{DOCU}{Fic} ne $config{DOCU}{Fic} ||
$Old_config{DICO}{Fic} ne $config{DICO}{Fic} ||
$Old_config{GLOBAL}{Resultat} ne $config{GLOBAL}{Resultat} ||
$Old_config{GLOBAL}{Deduction} ne $config{GLOBAL}{Deduction} ||
$Old_config{GLOBAL}{Debug} ne $config{GLOBAL}{Debug} ) {
my $Wm_Sortie = $Wm->Toplevel(
-title => "La configuration a été modifiée",
-background => 'white',
);
$Wm_Sortie->geometry("300x100+900+30");
my $SortieSave = $Wm_Sortie->Button(
-text => 'Save and exit',
-font => '{Simplified Arabic} 12 {bold}',
-command => sub {
sauvegarde_configuration( $fichier, $ref_config );
exit;
}
);
my $SortieSansSave = $Wm_Sortie->Button(
-text => 'Exit without save',
-font => '{Simplified Arabic} 12 {bold}',
-command => sub {
$Wm->destroy;
exit;
}
);
$SortieSave->grid($SortieSansSave,
qw / -padx 15 -pady 5 -sticky nsew /
);
} else {
$Wm->destroy;
exit;
}
}
#############################################################################
#############################################################################
#================================================
# But : Centrer un widget automatiquement
#================================================
sub centrer_widget {
my ( $widget ) = @_;
# Height and width of the screen
my $largeur_ecran = $widget->screenwidth();
my $hauteur_ecran = $widget->screenheight();
# update le widget pour récupérer les vraies dimensions
$widget->update;
my $largeur_widget = $widget->width;
my $hauteur_widget = $widget->height;
# On centre le widget en fonction de la taille de l'écran
my $nouvelle_largeur = int( ( $largeur_ecran - $largeur_widget ) / 2 );
my $nouvelle_hauteur = int( ( $hauteur_ecran - $hauteur_widget ) / 2 );
$widget->geometry($largeur_widget . "x" . $hauteur_widget
. "+$nouvelle_largeur+$nouvelle_hauteur");
$widget->update;
return;
}
#########################################
# Configuration des polices de caractères
#
sub configurer_tags {
my $widget_text = shift;
for my $police ( 12 .. 72 ) {
if ( $police % 2 == 0 ) {
$widget_text->tagConfigure(
"g$police",
-background => '#ABFAA3',
-font => "{Simplified Arabic} $police {bold}",
-justify => 'left',
);
$widget_text->tagConfigure(
"c$police",
-background => '#ABFAA3',
-font => "{Simplified Arabic} $police {bold}",
-justify => 'center',
);
$widget_text->tagConfigure(
"d$police",
-background => '#ABFAA3',
-font => "{Simplified Arabic} $police {bold}",
-justify => 'right',
);
}
}
$widget_text->tagConfigure(
'ara',
-background => '#D9FDFD',
-font => '{Simplified Arabic} 36', # Arabe
-justify => 'center',
);
$widget_text->tagConfigure(
'fnoir',
-background => '#D9FDFD',
-font => '{Simplified Arabic} 10', # Français 10 noir
-justify => 'center',
);
$widget_text->tagConfigure(
'froug',
-background => '#D9FDFD',
-foreground => '#FF0000',
-font => '{Simplified Arabic} 10', # Français 10 rouge
-justify => 'center',
);
$widget_text->tagConfigure(
'frougs',
-background => '#D9FDFD',
-foreground => '#FF0000',
-font => '{Simplified Arabic} 10', # Français 10 rouge souligné
-underline => 1,
-justify => 'center',
);
$widget_text->tagConfigure(
'fvert',
-background => '#D9FDFD',
-foreground => '#00CC00',
-font => '{Simplified Arabic} 10', # Français 10 vert traduction
-justify => 'center',
);
$widget_text->tagConfigure(
'fbleu',
-background => '#D9FDFD',
-foreground => '#3914AF',
-font => '{Simplified Arabic} 12', # Français 12 bleu
-justify => 'left',
);
$widget_text->tagConfigure(
'fbleus',
-background => '#D9FDFD',
-foreground => '#3914AF',
-font => '{Simplified Arabic} 10', # Français 10 bleu souligné
-underline => 1,
-justify => 'center',
);
return;
}
#######################################
# Elimination des doublons d'un tableau
sub doublons_grep {
my ($ref_tabeau) = @_;
my %hash_sans_doublon;
return grep { !$hash_sans_doublon{$_}++ } @{$ref_tabeau};
}
#==============================================================
# Pour avoir les accents sur la console DOS
# http://perl.developpez.com/faq/perl/?page=Terminal#AccentsDOS
#==============================================================
sub ActiverAccentsDOS {
my $encodage;
# Windows
if ( lc($^O ) eq 'mswin32') {
eval {
my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
$encodage = "cp$codepage";
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
else {
$encodage = `locale charmap`;
eval {
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
return $encodage;
}
#Sinon :
#ü \x81 à \x85 è \x8A
#é \x82 ç \x87 ï \x8B
#â \x83 ê \x88 î \x8C
#ä \x84 ë \x89 |
Partager