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
| #!/usr/bin/perl
#=====================================================================
# Auteur : djibril à partir d'une ébauche de dmganges
# Date : 19/11/2011 17:00:00
# But : Cours d'arabe
#=====================================================================
use strict;
use warnings;
use Tk;
use Tk::LabFrame;
use Tk::ROText;
use Encode;
use encoding 'utf8';
use Encode::Arabic;
use English '-no_match_vars';
use Win32::MediaPlayer;
use File::Spec; # Permet une meilleure gestion des nom des chemins sous tous les OS.
use Config::Std; # Lecture/ecriture d'un fichier .ini
use utf8;
use File::Basename;
my $winmm = new Win32::MediaPlayer; # new an object
my $RepBaseWin = 'C:\Arabe';
my $RepBaseLin = '/Fat32/Arabe';
my ( $Titre, $Message, $Time, $Pause, $Stop, $Repeat ) = ();
# Initialisation OS
my $RepBase = lc $OSNAME eq 'mswin32' ? $RepBaseWin : $RepBaseLin;
my $fichier_configuration = File::Spec->catfile( $RepBase, 'configuration.ini' );
# Initialisation des boutons
# Lecture du fichier de configuration
my %config;
if ( -e $fichier_configuration ) {
read_config $fichier_configuration => %config;
}
else {
%config = (
'DEFAUT' => {
aff => 'oui',
auteur => 'Sib_1',
boucle => '1',
trans => 'non',
tra => '11',
tempo => '0',
son => 'oui',
font => 'g28',
fin => '24',
deb => '24',
},
);
}
# Creation du widget principal
my $Wm = MainWindow->new(
-title => "Cours d'Arabe",
-background => 'white',
);
# Sauvegarder la configuration à la fermeture de la fenêtre
$Wm->protocol( 'WM_DELETE_WINDOW', [ \&fermer_application, $Wm, $fichier_configuration, \%config ] );
$Wm->minsize( 800, 600 );
$Wm->focusForce;
# Cadre des configurations
my $couleur_commune = '#E0F0FF';
my $cadre_configuration_playlist = $Wm->Frame( -background => $couleur_commune, );
# Cadre des configurations
my $cadre_configuration = $Wm->LabFrame(
-label => 'Configuration',
-background => $couleur_commune,
-font => '{Simplified Arabic} 10 {bold}',
);
# Cadre pour lancer les cours
my $cadre_playlist = $Wm->LabFrame(
-label => 'Gestions du cours',
-background => $couleur_commune,
-font => '{Simplified Arabic} 10 {bold}',
);
# Label qui affichera le cours
my $label_cours = $Wm->Label(
-textvariable => \$Titre,
-height => 1,
-font => '{Simplified Arabic} 20 {bold}',
-background => '#FFE0D0',
-relief => 'groove',
);
# Label qui affichera l'état
my $label_etat = $Wm->Label(
-textvariable => \$Message,
-background => '#FFE0D0',
-relief => 'groove',
);
my $widget_text_cours = $Wm->Scrolled(
'ROText',
-scrollbars => 'e',
-takefocus => 0,
-wrap => 'word',
-relief => 'flat',
-background => '#ABFAA3',
);
configurer_tags($widget_text_cours);
# Configuration du cadre de config
# Auteur
my @les_auteurs = qw / Ass_1 Cha_1 Sib_1 Pet_1 /;
my $LibAuteur = $cadre_configuration->Label( -text => 'Auteur', -background => $couleur_commune, );
my $optionmenu_auteur = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Auteur : ' ],
-textvariable => \$config{DEFAUT}{auteur},
-options => \@les_auteurs,
);
# RepDeb
my $LibRepDeb = $cadre_configuration->Label( -text => 'Déb', -background => $couleur_commune, );
my $optionmenu_deb = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Deb : ' ],
-textvariable => \$config{DEFAUT}{deb},
-options => [ 1 .. 77 ]
);
# RepFin
my $LibRepFin = $cadre_configuration->Label( -text => 'Fin', -background => $couleur_commune, );
my $optionmenu_fin = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Fin : ' ],
-textvariable => \$config{DEFAUT}{fin},
-options => [ 1 .. 77 ],
);
# Temporisation
my $LibTempo = $cadre_configuration->Label( -text => 'Tempo', -background => $couleur_commune, );
my $optionmenu_tempo = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Tempo : ' ],
-textvariable => \$config{DEFAUT}{tempo},
-options => [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40 ]
);
my $LibBoucle = $cadre_configuration->Label( -text => 'Boucles', -background => $couleur_commune, );
my $optionmenu_boucle = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Boucles : ' ],
-textvariable => \$config{DEFAUT}{boucle},
-options => [ 1 .. 9 ]
);
# Notes de cours
my $LibNotes = $cadre_configuration->Label( -text => 'Notes de',-background => $couleur_commune, );
my $optionmenu_notes = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Boucles : ' ],
-textvariable => \$config{DEFAUT}{boucle},
);
my $afficher_note_cours = $cadre_configuration->Button(
-text => 'Cours',
-command => \&Cours,
);
# Son
my $LibSon = $cadre_configuration->Label( -text => 'Son', -background => $couleur_commune, );
my $optionmenu_son = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Son : ' ],
-textvariable => \$config{DEFAUT}{son},
-options => [ "OUI", "NON" ]
);
# Affichage .txt
my $LibAff = $cadre_configuration->Label( -text => 'Texte', -background => $couleur_commune, );
my $optionmenu_aff = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Texte : ' ],
-textvariable => \$config{DEFAUT}{aff},
-options => [ 'OUI', 'TOUT', 'NON' ]
);
# Translittération
my $LibTrans = $cadre_configuration->Label( -text => 'Trans', -background => $couleur_commune, );
my $optionmenu_trans = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Trans : ' ],
-textvariable => \$config{DEFAUT}{trans},
-options => [ 'OUI', 'NON' ]
);
# Traduction
my $LibTra = $cadre_configuration->Label( -text => 'Trad', -background => $couleur_commune, );
my $optionmenu_tra = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Trad : ' ],
-textvariable => \$config{DEFAUT}{tra},
-options => [ '00', '01', '10', '11' ]
);
# Fontes
my $LibFont = $cadre_configuration->Label( -text => 'Font', -background => $couleur_commune, );
my $optionmenu_font = $cadre_configuration->Optionmenu(
-command => [ \&affichage_print, 'Font : ' ],
-textvariable => \$config{DEFAUT}{font},
-options => [ 'g12', 'g14', 'g16', 'g18', 'g20', 'g22', 'g24', 'g26', 'g28', 'g36', 'g48', 'g72' ]
);
# Playlist
# Start
my $bouton_start = $cadre_playlist->Button(
-text => 'Start',
-command => [ \&start, ],
);
# Start
my $bouton_stop = $cadre_playlist->Button(
-text => 'Stop',
-command => [ \&stop, ],
);
# Exit
my $bouton_exit = $cadre_playlist->Button(
-text => 'Exit',
-command => [ \&fermer_application, $Wm, $fichier_configuration, \%config ],
);
# Repeat
my $LibRepeat = $cadre_playlist->Label( -text => 'Repeat', -background => $couleur_commune, );
my @data_repeat = map { sprintf '%02d', $_ } ( 0 .. 50 );
my $optionmenu_repeat = $cadre_playlist->Optionmenu(
-command => [ \&affichage_print, 'Repeat : ' ],
-textvariable => \$Repeat,
-options => \@data_repeat,
);
# Gestion de l'affichage des widgets
$label_etat->pack(qw / -side bottom -fill x -expand 0 /);
$widget_text_cours->pack(qw / -side bottom -fill both -expand 1 /);
$label_cours->pack(qw / -side bottom -fill x -expand 0 /);
$cadre_configuration_playlist->pack(qw / -side top -fill x -expand 0 /);
$cadre_configuration->pack(qw / -side left -fill both -expand 1 /);
$cadre_playlist->pack(qw / -side right -fill both -expand 1 /);
#$afficher_note_cours->grid(qw/ -columnspan 10 -pady 5 /);
$LibAuteur->grid(
$optionmenu_auteur, $LibRepDeb, $optionmenu_deb,
$LibRepFin, $optionmenu_fin, $LibTempo,
$optionmenu_tempo, $LibBoucle, $optionmenu_boucle, $LibNotes, $afficher_note_cours,
qw / -padx 2 -pady 5 -sticky nsew /
);
$LibSon->grid( $optionmenu_son, $LibAff, $optionmenu_aff, $LibTrans, $optionmenu_trans, $LibTra,
$optionmenu_tra, $LibFont, $optionmenu_font, qw / -padx 2 -pady 5 -sticky nsew / );
$bouton_start->grid( $bouton_stop, $bouton_exit, $LibRepeat, $optionmenu_repeat,
qw / -padx 2 -pady 5 -sticky nsew / );
centrer_widget($Wm);
MainLoop;
sub stop {
$winmm->close;
$Stop = 'Stop';
return;
}
sub start {
if ( $config{DEFAUT}{aff} eq 'NON' && $config{DEFAUT}{son} eq 'NON' ) {
MsgErr("Son ET Texte ne peuvent être à NON");
return;
}
$Message = 'Lecture en cours';
$Stop = '';
Prog();
$Message = 'Lecture terminée';
$Wm->bell();
if ( $Stop ne '' ) {
$winmm->close;
$Wm->afterCancel($Pause);
$Message = 'Lecture Stoppée';
}
return;
}
sub Prog {
# Boucles
if ( $config{DEFAUT}{fin} < $config{DEFAUT}{deb} ) {
MsgErr("Le répertoire de fin doit être supérieur ou égal au répertoire de début");
}
for my $Count ( 1 .. $config{DEFAUT}{boucle} ) {
if ( $Stop ne '' ) { last; }
# Pause 1 - début de boucle
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 100 );
my $RepD = $config{DEFAUT}{deb};
while ( $RepD <= $config{DEFAUT}{fin} ) {
if ( $Stop ne "" ) { last; }
# Traitement d'un répertoire
my $NumCours = sprintf '%02d', $RepD;
my $repertoire = File::Spec->catfile( $RepBase, $config{DEFAUT}{auteur}, 'CDdecoup', "LLc_$NumCours" );
# Traitement d'un cours
$widget_text_cours->delete( "1.0", 'end' );
my $fichier_titre = File::Spec->catfile( $repertoire, 'FicTitre.utf8' );
open IN_Fic, '<:encoding(UTF-8)', $fichier_titre
or die "L'ouverture de $fichier_titre ne s'est pas effectuée correctement";
$Titre = <IN_Fic>;
close IN_Fic;
$Wm->update;
my $fichier_mp3 = File::Spec->catfile( $repertoire, 'FicTitre.mp3' );
if ( !-e $fichier_mp3 ) {
die "Impossible de lire le fichier $fichier_mp3\n$!";
}
if ( lc $OSNAME eq 'mswin32' ) {
if ( $Stop ne "" ) { last; }
$winmm->load($fichier_mp3); # Load music file disk, or an URL
$winmm->play; # Play the music
$winmm->volume(100); # Set volume after playing
$Time = $winmm->length;
$Pause = $Wm->after($Time);
$winmm->close;
}
else {
#@Liste = ("mplayer $fichier_mp3");
#system @Liste;
}
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 50 ); # Pause 2 - après titre
opendir my $FhRep, $repertoire or die "impossible d'ouvrir le répertoire $repertoire\n $!";
my @Contenu = grep { !/^\.\.?$/ } readdir($FhRep);
closedir $FhRep;
$widget_text_cours->delete( '1.0', 'end' );
if ( $Stop ne "" ) { last; }
foreach my $Nom ( sort @Contenu ) {
my ( $TraE, $TraS ) = split //, $config{DEFAUT}{tra};
if ( $Stop ne '' ) { last; }
my ( $nom_fichier, $nom_rep, $suffix ) = fileparse( $Nom, qr/\.[^.]*/ );
my @NomFic = split /\./, $Nom;
$suffix =~ s{\.}{};
next if $nom_fichier eq 'FicTitre';
next if $suffix ne 'utf8';
next if $nom_fichier =~ /^c/;
next if $nom_fichier =~ /^T/;
if ( $Repeat ne '00' ) {
$Nom = "P_${Repeat}.utf8";
$nom_fichier = "P_$Repeat";
}
my $fichier_arabe = File::Spec->catfile( $repertoire, $Nom );
# Traitement TEXTE
if ( $Stop ne "" ) { last; }
if ( $config{DEFAUT}{aff} eq 'OUI' || $config{DEFAUT}{aff} eq 'TOUT' ) {
open my $fh, '<:encoding(UTF8)', $fichier_arabe
or die "ERREUR : Impossible d'ouvrir $fichier_arabe\n";
if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
# Affichage texte Arabe
if ( $Stop ne "" ) { last; }
while ( my $Ligne = <$fh> ) {
$bouton_stop->focus();
$widget_text_cours->insert( 'end', "\n", $config{DEFAUT}{font} );
$widget_text_cours->insert( 'end', $Ligne, $config{DEFAUT}{font} );
$widget_text_cours->update;
$widget_text_cours->see('end');
# Affichage Translittération
if ( $Stop ne "" ) { last; }
if ( $config{DEFAUT}{trans} eq 'OUI' ) {
$widget_text_cours->insert( 'end', "\n" );
my $Translit = encode( 'arabtex', $Ligne );
$Translit = decode( "utf-8", $Translit );
$widget_text_cours->insert( 'end', $Translit, "tcours" );
$widget_text_cours->update();
$widget_text_cours->see('end');
}
}
close $fh;
}
if ( $Stop ne '' ) {
$Message = 'Lecture Stoppée';
$Wm->update;
last;
Stop();
}
# Son Arabe
if ( $config{DEFAUT}{son} eq 'OUI' ) {
my $fichier_mp3 = File::Spec->catfile( $repertoire, "${nom_fichier}.mp3" );
if ( !-e $fichier_mp3 ) {
die "Impossible de lire le fichier $fichier_mp3\n$!";
}
if ( $Stop ne "" ) { last; }
my $Taille = -s $fichier_mp3;
$Message = "$fichier_mp3 - $Taille";
$Wm->update;
if ( $config{DEFAUT}{tempo} != 0 ) {
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 200 ); # Pause 3 - avant SON Arabe
}
if ( $Stop ne "" ) { last; }
if ( lc $OSNAME eq 'mswin32' ) {
$winmm->load($fichier_mp3); # Load music file disk, or an URL
$winmm->play; # Play the music
$winmm->volume(100); # Set volume after playing
$Time = $winmm->length;
$Pause = $Wm->after($Time);
$winmm->close;
}
else {
#@Liste = ("mplayer $fichier_mp3");
#system @Liste;
}
if ( $Stop ne '' ) {
$Message = 'Lecture Stoppée';
$Wm->update();
last;
}
if ( $config{DEFAUT}{tempo} != 0 ) {
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 100 ); # Pause 4 - de Fichier Arabe
}
}
# Traduction écrite
if ( $Stop ne "" ) { last; }
if ( $TraE eq '1' ) {
my @NumFic = split /\_/, $nom_fichier;
my $fichier_traduction = File::Spec->catfile( $repertoire, "T_$NumFic[1].txt" );
if ( $config{DEFAUT}{tempo} != 0 ) {
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 25 ); # Pause 5 - avant Traduction écrite
}
if ( $Stop ne "" ) { last; }
open FIC, '<', $fichier_traduction
or die "Impossible de lire $fichier_traduction\n$!";
while ( my $Ligne = <FIC> ) {
$widget_text_cours->insert( 'end', "\n" );
$widget_text_cours->insert( 'end', $Ligne, 'tcours' );
$widget_text_cours->update;
$widget_text_cours->see('end');
}
if ( $Stop ne "" ) { last; }
if ( $config{DEFAUT}{tempo} != 0 ) {
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 50 ); # Pause 6 - après Traduction écrite
}
close FIC;
}
# Traduction orale
if ( $Stop ne "" ) { last; }
if ( $TraS eq '1' && $config{DEFAUT}{son} eq 'OUI' ) {
my @NumFic = split /\_/, $nom_fichier;
my $fichier_traductionS_mp3 = File::Spec->catfile( $repertoire, "Tr_$NumFic[1].mp3" );
my $Taille = -s $fichier_traductionS_mp3;
$Message = "$fichier_traductionS_mp3 - $Taille";
$Wm->Label->update();
if ( $Stop ne "" ) { last; }
if ( !-e $fichier_traductionS_mp3 ) {
die "Impossible de lire le fichier $fichier_traductionS_mp3\n$!";
}
if ( $Stop ne "" ) { last; }
if ( $config{DEFAUT}{tempo} != 0 ) {
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 10 ); # Pause 7 - avant SON Français
}
if ( lc $OSNAME eq 'mswin32' ) {
if ( $Stop ne "" ) { last; }
$winmm->load($fichier_traductionS_mp3); # Load music file disk, or an URL
$winmm->play; # Play the music
$winmm->volume(100); # Set volume after playing
$Time = $winmm->length;
$Pause = $Wm->after($Time);
$winmm->close;
}
else {
#@Liste = ("mplayer $fichier_mp3");
#system @Liste;
}
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 100 ); # Pause 8 - de Fichier Français
if ( $Stop ne '' ) {
$Message = 'Lecture Stoppée';
$Wm->update();
last;
}
}
# Commentaire écrit !!!!! NB il faut un fichier Tr....mp3 EVT vide !
if ( $TraE eq '1' && $config{DEFAUT}{tempo} > 3 ) {
my @NumFic = split /\_/, $nom_fichier;
my $fichier_traductionE = File::Spec->catfile( $repertoire, "T_$NumFic[1].utf8" );
if ( -f $fichier_traductionE ) {
if ( $config{DEFAUT}{tempo} != 0 ) {
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 50 ); # Pause 9 - avant commentaire écrit
}
if ( $Stop ne "" ) { last; }
open my $fh, '<:encoding(UTF-8)', $fichier_traductionE
or die "Impossible de lire $fichier_traductionE\n$!";
if ( $Stop ne "" ) { last; }
while ( my $Ligne = <$fh> ) {
$widget_text_cours->insert( 'end', "\n" );
$widget_text_cours->insert( 'end', $Ligne, 'tcours' );
$widget_text_cours->update();
$widget_text_cours->see('end');
}
close $fh;
if ( $config{DEFAUT}{tempo} != 0 ) {
$Pause = $Wm->after( $config{DEFAUT}{tempo} * 200 ); # Pause 10 - après commentaire écrit
}
}
}
}
$RepD++;
}
}
if ( $config{DEFAUT}{aff} ne 'TOUT' ) {
$widget_text_cours->delete( '1.0', 'end' );
$widget_text_cours->update;
$widget_text_cours->see('end');
}
}
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 => 'center',
);
}
}
$widget_text->tagConfigure(
'gcours',
-background => '#D9FDFD',
-font => '{Simplified Arabic} 14',
-justify => 'center',
);
$widget_text->tagConfigure(
'tcours',
-background => '#ABFAA3',
-font => '{Simplified Arabic} 14',
-justify => 'center',
);
return;
}
sub affichage_print {
my ( $message, $valeur ) = @_;
print "$message $valeur\n";
}
sub sauvegarde_configuration {
my ( $fichier, $ref_config ) = @_;
write_config %{$ref_config}, $fichier;
return;
}
sub fermer_application {
my ( $mw, $fichier, $ref_config ) = @_;
# Sauvegarder configuration
sauvegarde_configuration( $fichier, $ref_config );
# Fermer l'application
$mw->destroy;
exit;
}
# Affichage des notes de cours
#
sub Cours {
my $NumCours = sprintf '%02d', $config{DEFAUT}{deb};
my $RepCours = "LLc_$NumCours";
my $fichier_cours
= File::Spec->catfile( $RepBase, $config{DEFAUT}{auteur}, 'CDdecoup', $RepCours, "P_${NumCours}.utf8" );
$widget_text_cours->delete( '1.0', 'end' );
open my $fh, '<:encoding(UTF-8)', $fichier_cours or die "Impossible de lire $fichier_cours\n$!";
while ( my $Ligne = <$fh> ) {
$widget_text_cours->insert( 'end', $Ligne, 'gcours' );
}
close $fh;
return;
}
#================================================
# But : Afficher les messages d'erreurs dans une fenêtre
# Arguments : rien
# Retour : Rien
#================================================
sub Tk::Error {
my ( $widget, $Error, @Locations ) = @_;
# Error widget
my $MwError = $widget->Toplevel( -background => 'white' );
$MwError->title("Fenêtre d'erreurs");
$MwError->minsize( 300, 300 );
$MwError->grab();
my $MessageError = $MwError->Scrolled( 'Text', -scrollbars => 'oe' );
$MessageError->delete( '1.0', 'end' );
$MessageError->insert( 'end', "Erreur : $Error\n\n" );
$MessageError->pack(qw/ -fill both -expand 1 /);
centrer_widget($MessageError);
return;
}
sub MsgErr {
my $message = shift;
my $err = $Wm->Toplevel( -background => 'white' );
$err->geometry('509x200+508+100');
$err->title('Erreur');
$err->Label(
-text => $message,
-font => '{Simplified Arabic} 20 {bold}',
-background => 'white',
)->pack(qw/ -expand 1/);
$err->Button(
-text => 'Message lu',
-command => sub { $err->destroy() },
)->pack(qw/ -padx 20 -pady 20 -side bottom /);
centrer_widget($err);
$err->focusForce;
$err->grab;
return;
}
#================================================
# 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;
} |
Partager