IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques Perl Discussion :

Perl Tk Chaînes arabes dans un Scrolled Text


Sujet :

Interfaces Graphiques Perl

  1. #41
    Rédactrice

    Avatar de stoyak
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    408
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 408
    Points : 1 491
    Points
    1 491
    Par défaut
    C'est chose faite !
    Images attachées Images attachées  
    Cela demande du courage d'en tirer du plaisir
    Quand on n'a qu'un marteau, tous les problèmes ressemblent à un clou

  2. #42
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Je me suis renseigné auprès d'autres spécialistes de Perl et voici la conclusion :
    D'après http://wiki.tcl.tk/3158 "Tk has no bidi facilities yet, so Unicodes even if from r2l systems must come naively left-to-right if they are to appear correct on screen."
    Le problème n'est pas coté Perl mais côté Tk. Une fois qu'une chaine avec des caractères corrects est fournie, ce n'est pas Perl qui se charge de l'afficher, mais Tk.

    Depuis wiki.tcl.tk, http://czyborra.com/arabjoin/arabjoin "a simple filter to render Arabic text".
    D'après http://coding.derkeiler.com/Archive/.../msg01233.html le rendu bidi, en particulier pour l'arabe, semble buggué depuis un moment dans Tk, mais c'est à vérifier, ce message datant
    Il y a aussi des infos, mais plutôt concernant Tcl, ici http://en.wikibooks.org/wiki/Tcl_Pro...ationalization.

  3. #43
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    On ne va donc pas y passer tout notre temps !
    Ce n'est pas la mort, j'éviterai de cliquer dans le scrolled...

    DESOLE pour tout le temps que je t'ai fait perdre, et MERCI djibril pour toutes ces infos et tout le temps que tu m'as consacré !
    Merci stoyak.

  4. #44
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Pas de soucis. Si un jour une solution est donnée, on se le dira.

  5. #45
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    AVEC PLAISIR !
    Là il me faut avancer dans les cours, mais me connaissant je ferai d'autres essais...

    Edit 9/12/11 05:55
    pour celles et ceux qui suivent, ce n'est pas un pb sur 3 ou 4 digits, l'insertion suivante est sur 4 digits, elle est syntaxiquement correcte mais un clic de souris la désorganise.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $texte->insert('end', "\x{FEFF}\x{0645}\x{064E}\x{0627}\x{0630}\x{064E}\x{0627}\x{20}", 'gras');
    Il se trouve que le scrolled texte, ne gère pas correctement les signes diacritiques. Autrement dit ex: Malika مَلِيكَة se scinde alors que مليكة ne se scinde pas.
    Un arabophone lit sans difficulté sans les signes diacritiques, un débutant, moi, non

  6. #46
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut Suppression des caractères diacritiques
    Bonjour,

    Je continue ici car le problème que je soumets n'est que la suite logique de ce qui précède.
    Le Scrolled Text ne gérant pas correctement les signes diacritiques arabes, et compte tenu qu'en arabe il faut à terme lire sans ces signes, j'essaye d'ajouter cette fonctionnalité dans le programme.

    Le module initial est celui-ci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    # Affichage texte Arabe
              if ( $Stop ne "" ) { last; }
              while ( my $Ligne = <$fh> ) {
                $bouton_stop->focus();
                $widget_text_cours->insert( 'end', "\n", "g12" );   
                $widget_text_cours->insert( 'end', $Ligne, $config{DEFAUT}{font} );
                $widget_text_cours->update;
                $widget_text_cours->see('end');
    Lorsque j'ajoute ceci pour supprimer les diacritiques, Il ne se passe rien les diacritiques s'affichent encore :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    # Affichage texte Arabe
              if ( $Stop ne "" ) { last; }
              while ( my $Ligne = <$fh> ) {
                $bouton_stop->focus();
                $widget_text_cours->insert( 'end', "\n", "g12" );
     
            binmode $fh;
            $Ligne =~ s/\xD9\x8E//go; # Fatha
        	$Ligne =~ s/\xD9\x8B//go; # FathaTan
        	$Ligne =~ s/\xD9\x90//go; # Kasra
        	$Ligne =~ s/\xD9\x8D//go; # KasraTan
        	$Ligne =~ s/\xD9\x8F//go; # Damma
        	$Ligne =~ s/\xD9\x8C//go; # DammaTan
        	$Ligne =~ s/\xD9\x92//go; # Soukoune
        	$Ligne =~ s/\xD9\x91//go; # Chadda
            utf8::encode($Ligne);
     
                $widget_text_cours->insert( 'end', $Ligne, $config{DEFAUT}{font} );
                $widget_text_cours->update;
                $widget_text_cours->see('end');
    Par contre si je crée d'autres fichiers dans un autre répertoire à partir de ceux qui contiennent les diacritiques, et que je lis ces fichiers dans le Scrolled, ça fonctionne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    $Fichier = "$repertoire/$nom";
    		[...]
    		open my $fhi, '<:encoding(UTF8)', $IN_Fic1
                    or die "ERREUR : Impossible d'ouvrir $IN_Fic1\n";
                    open my $fho, '>:encoding(UTF8)', $OUT_Dia
                    or die "ERREUR : Impossible d'ouvrir $OUT_Dia\n";
     
        binmode $fhi;
        binmode $fho;
        while ( my $Ligne = <$fhi> ) {
        	$Ligne =~ s/\xD9\x8E//go; # Fatha
        	$Ligne =~ s/\xD9\x8B//go; # FathaTan
        	$Ligne =~ s/\xD9\x90//go; # Kasra
        	$Ligne =~ s/\xD9\x8D//go; # KasraTan
        	$Ligne =~ s/\xD9\x8F//go; # Damma
        	$Ligne =~ s/\xD9\x8C//go; # DammaTan
        	$Ligne =~ s/\xD9\x92//go; # Soukoune
        	#	$Ligne =~ s/\xD9\x91//go; # Chadda
     
        	print $fho $Ligne;
        }
        close $fhi;
        close $fho;
    Autant dire que je préférerais le faire dans le programme principal sans à avoir à créer de fichiers supplémentaires, même si ce n'est pas très lourd...
    MERCI D'AVANCE pour vos lumières !!!

    Pour celles et ceux que ça intéresse, le programme complet avec quelques fonctionnalités supplémentaires :
    - suppression des diacritiques EN ROUGE GRAS (nécessite de créer d'autres fichiers) Là le Scrolled se comporte correctement, pas de scission des phrases
    - 1 à 9 répétitions de la phrase arabe
    - 6 modes de lecture : ArabeSeul ArabeFrançais FrançaisArabe + 3 modes de dictée
    Il fonctionne avec n'importe qu'elle langue...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    #!/usr/bin/perl
    #=====================================================================
    #    Auteur : djibril à partir d'une ébauche de dmganges
    # Date  : 01/01/2012 05: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, $RepDia ) = ();
    
    # 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    => 'rien',
          tempo  => '0',
          son    => 'oui',
          font   => 'g28',
          fin    => '24',
          deb    => '24',
          dia    => 'non',
          nbara  => '1',
          mod    => 'AraFra',
        },
      );
    }
    
    # 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 / App_1 Ass_1 Cha_1 Cul_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 => [ 1 .. 25 ]
    );
    
    # Boucles
    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 ]
    );
    
    # Repeat
    my $LibRepeat = $cadre_configuration->Label( -text => 'Repeat', -background => $couleur_commune, );
    my @data_repeat = map { sprintf '%02d', $_ } ( 0 .. 60 );
    
    my $optionmenu_repeat = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'Repeat : ' ],
      -textvariable => \$Repeat,
      -options      => \@data_repeat,
    );
    
    # NbAra
    my $LibNbAra = $cadre_configuration->Label( -text => 'NbAra', -background => $couleur_commune, );
    my $optionmenu_nbara = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'NbAra : ' ],
      -textvariable => \$config{DEFAUT}{nbara},
      -options      => [ 1 .. 9 ],
    );
    
    # Mode
    my @les_modes      = qw / AraSeul AraFra FraAra Dict1 Dict2 Dict3 /;
    my $LibMod = $cadre_configuration->Label( -text => 'Mode', -background => $couleur_commune, );
    my $optionmenu_mod = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'Mod : ' ],
      -textvariable => \$config{DEFAUT}{mod},
      -options      => \@les_modes,
    );
    
    # 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 => 'SonAra', -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 => 'TexAra', -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 => [ 'RIEN', 'SON', 'ECRI', 'TOUT' ]
    );
    
    # 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' ]
    );
    
    # Diacritiques
    my $LibDia = $cadre_configuration->Label( -text => 'Diacritiques', -background => $couleur_commune, );
    my $optionmenu_dia = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'Dia : ' ],
      -textvariable => \$config{DEFAUT}{dia},
      -options => [ 'OUI',            'NON' ]
    );
    
    # 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 ],
    );
    
    
    
    # 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, $LibRepeat, $optionmenu_repeat, $LibNbAra, $optionmenu_nbara, $LibMod, $optionmenu_mod,
      qw / -padx 2 -pady 5 -sticky nsew /
    );
    $LibSon->grid( $optionmenu_son, $LibAff, $optionmenu_aff, $LibTrans, $optionmenu_trans, $LibTra,
      $optionmenu_tra, $LibFont, $optionmenu_font, $LibDia, $optionmenu_dia, $LibNotes, $afficher_note_cours, qw / -padx 2 -pady 5 -sticky nsew / );
    
    $bouton_start->grid( $bouton_stop, $bouton_exit,
      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 {
    
      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");
      }
    	# Boucle générale
      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 + 200);
            $winmm->close;
          }
          else {
    
            #@Liste = ("mplayer $fichier_mp3");
            #system @Liste;
          }
          $Pause = $Wm->after( $config{DEFAUT}{tempo} * 1000 );    # 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 ) {
            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/;
    				
    				# Boucle classique infinie sur une phrase
            if ( $Repeat ne '00' ) {
              $Nom        = "P_${Repeat}.utf8";
              $nom_fichier = "P_$Repeat";
              while ( $Stop eq "" ) {
              	TxtAra($repertoire, $Nom);
            		SonAra($repertoire, $nom_fichier);
            		TraEcr($repertoire, $nom_fichier);
            		TraOra($repertoire, $nom_fichier);
            		ComEcr($repertoire, $nom_fichier);
              }
            }
            
            # Arabe seul
            if ( $config{DEFAUT}{mod} eq 'AraSeul' ) {
          		TxtAra($repertoire, $Nom);
          		SonAra($repertoire, $nom_fichier);
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Arabe -> Français (Classique)
          	if ( $config{DEFAUT}{mod} eq 'AraFra' ) {
          		TxtAra($repertoire, $Nom);
          		SonAra($repertoire, $nom_fichier);
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		ComEcr($repertoire, $nom_fichier);
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Français -> Arabe
          	if ( $config{DEFAUT}{mod} eq 'FraAra' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		SonAra($repertoire, $nom_fichier);
          		ComEcr($repertoire, $nom_fichier);
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Dictée phrase arabe 1 fois
          	if ( $config{DEFAUT}{mod} eq 'Dict1' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 1 - dictée 1
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Dictée phrase arabe 2 fois
            if ( $config{DEFAUT}{mod} eq 'Dict2' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 1 - dictée 2
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 2 - dictée 2
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Dictée phrase arabe 3 fois
            if ( $config{DEFAUT}{mod} eq 'Dict3' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 1 - dictée 3
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 2 - dictée 3
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 3 - dictée 3
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          }
          $RepD++;
        }
      }
      if ( $config{DEFAUT}{aff} ne 'TOUT' ) {
        $widget_text_cours->delete( '1.0', 'end' );
        $widget_text_cours->update;
        $widget_text_cours->see('end');
      }
    }
    
    ################################################
    # Affichage texte arabe
    #
    sub TxtAra {
    	my ( $repertoire, $Nom ) = @_;
    				if ( $config{DEFAUT}{dia} eq "NON" ) {
        			$RepDia = "$repertoire/Acc";
        		}
        		else {
        				$RepDia = $repertoire;
        		}
            my $fichier_arabe = File::Spec->catfile( $RepDia, $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";
    
              # Affichage texte Arabe
              if ( $Stop ne "" ) { last; }
              while ( my $Ligne = <$fh> ) {
                $bouton_stop->focus();
                $widget_text_cours->insert( 'end', "\n", "g12" );
                
                binmode $fh;
                $Ligne =~ s/\xD9\x8E//go; # Fatha
        				$Ligne =~ s/\xD9\x8B//go; # FathaTan
        				$Ligne =~ s/\xD9\x90//go; # Kasra
        				$Ligne =~ s/\xD9\x8D//go; # KasraTan
        				$Ligne =~ s/\xD9\x8F//go; # Damma
        				$Ligne =~ s/\xD9\x8C//go; # DammaTan
        				$Ligne =~ s/\xD9\x92//go; # Soukoune
        				#	$Ligne =~ s/\xD9\x91//go; # Chadda
                
                utf8::encode($Ligne);
                
                $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" );
                	$widget_text_cours->insert( 'end', "\n", "g12" );
                  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
    #
    sub SonAra {
    	my ( $repertoire, $nom_fichier ) = @_;
            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' ) {
              	for my $NbAra ( 1 .. $config{DEFAUT}{nbara} ) {
                	$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 + 200);
    							$Message = "$fichier_mp3 ====> $Time";
              		$Wm->update;
      		      	$winmm->close;
      		      	$Pause = $Wm->after( 1000 );                           # Pause 4 - entre phrases Arabe
      		      }
              }
              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 5 - de Fichier Arabe
              }
            }
            return $Time;
    }
    #######################
    # Traduction écrite
    #
    sub TraEcr {
    		my ( $repertoire, $nom_fichier ) = @_;
            if ( $Stop ne "" ) { last; }
          	if ( $config{DEFAUT}{tra} eq 'ECRI' || $config{DEFAUT}{tra} eq 'TOUT' ) {
              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 6 - 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}{tra} eq 'ECRI' ) {
                $Pause = $Wm->after( $config{DEFAUT}{tempo} * 1000 );    # Pause 7 - après Traduction écrite
              }
              close FIC;
            }
    }
    #######################
    # Traduction orale
    #
    sub TraOra {
    	my ( $repertoire, $nom_fichier ) = @_;
            if ( $Stop ne "" ) { last; }
           	if ( ($config{DEFAUT}{tra} eq 'SON' || $config{DEFAUT}{tra} eq 'TOUT' ) && $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 8 - 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 + 200);
     			      $winmm->close;
              }
              else {
                #@Liste = ("mplayer $fichier_mp3");
                #system @Liste;
              }
              $Pause = $Wm->after( $config{DEFAUT}{tempo} * 100 );    # Pause 9 - de Fichier Français
              if ( $Stop ne '' ) {
                $Message = 'Lecture Stoppée';
                $Wm->update();
                last;
              }
            }
    }
    
    ############################
    # Affichage des commentaires
    #
    sub ComEcr {
    	my ( $repertoire, $nom_fichier ) = @_;
            # Commentaire écrit          !!!!!    NB il faut un fichier Tr....mp3 EVT vide !
            if ( ($config{DEFAUT}{tra} eq 'ECRI' || $config{DEFAUT}{tra} eq 'TOUT') && $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 10 - 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} * 500 );    # Pause 11 - après commentaire écrit
                }
              }
            }
    }
    
    #########################################
    # 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    => '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";
    }
    ##########################
    # Sauvegarde configuration
    #
    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;
    }
    Je peux faire un petit mode d'emploi si ça intéresse...

  7. #47
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Je ne peux plus faire un édit du précédent, à toutes fins utiles je colle la dernière mouture avec Lecture Pas à Pas (contrôle d'un while avec bind et tkwait). Merci pour vos suggestions.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    #!/usr/bin/perl
    #=====================================================================
    # Auteur : djibril à partir d'une ébauche de dmganges
    # Date  : 01/02/2012 05: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, $RepDia ) = ();
    my $Char = "A";
     
    # 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    => 'rien',
          tempo  => '0',
          son    => 'oui',
          font   => 'g28',
          fin    => '24',
          deb    => '24',
          dia    => 'non',
          nbara  => '1',
          mod    => 'AraFra',
        },
      );
    }
     
    # 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 / App_1 Ass_1 Cha_1 Cul_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 => [ 1 .. 25 ]
    );
     
    # Boucles
    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 ]
    );
     
    # Repeat
    my $LibRepeat = $cadre_configuration->Label( -text => 'Repeat', -background => $couleur_commune, );
    my @data_repeat = map { sprintf '%02d', $_ } ( 0 .. 60 );
     
    my $optionmenu_repeat = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'Repeat : ' ],
      -textvariable => \$Repeat,
      -options      => \@data_repeat,
    );
     
    # NbAra
    my $LibNbAra = $cadre_configuration->Label( -text => 'NbAra', -background => $couleur_commune, );
    my $optionmenu_nbara = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'NbAra : ' ],
      -textvariable => \$config{DEFAUT}{nbara},
      -options      => [ 1 .. 9 ],
    );
     
    # Mode
    my @les_modes      = qw / AraSeul AraFra FraAra Dict1 Dict2 Dict3 PasApas /;
    my $LibMod = $cadre_configuration->Label( -text => 'Mode', -background => $couleur_commune, );
    my $optionmenu_mod = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'Mod : ' ],
      -textvariable => \$config{DEFAUT}{mod},
      -options      => \@les_modes,
    );
     
    # 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 => 'SonAra', -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 => 'TexAra', -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 => [ 'RIEN', 'SON', 'ECRI', 'TOUT' ]
    );
     
    # 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' ]
    );
     
    # Diacritiques
    my $LibDia = $cadre_configuration->Label( -text => 'Diacritiques', -background => $couleur_commune, );
    my $optionmenu_dia = $cadre_configuration->Optionmenu(
      -command      => [ \&affichage_print, 'Dia : ' ],
      -textvariable => \$config{DEFAUT}{dia},
      -options => [ 'OUI',            'NON' ]
    );
     
    # Playlist
     
    # Sav
    my $bouton_sav = $cadre_playlist->Button(
      -text    => 'Save',
      -command => [ \&sav, $Wm, $fichier_configuration, \%config ],,
    );
     
    # Start
    my $bouton_start = $cadre_playlist->Button(
      -text    => 'Start',
      -command => [ \&start, ],
    );
     
    # Stop
    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 ],
    );
     
     
     
    # 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 /);
     
    $LibAuteur->grid(
      $optionmenu_auteur, $LibRepDeb,      $optionmenu_deb,
      $LibRepFin,        $optionmenu_fin, $LibTempo,
      $optionmenu_tempo,  $LibBoucle,      $optionmenu_boucle, $LibRepeat, $optionmenu_repeat, $LibNbAra, $optionmenu_nbara, $LibMod, $optionmenu_mod,
      qw / -padx 2 -pady 5 -sticky nsew /
    );
    $LibSon->grid( $optionmenu_son, $LibAff, $optionmenu_aff, $LibTrans, $optionmenu_trans, $LibTra,
      $optionmenu_tra, $LibFont, $optionmenu_font, $LibDia, $optionmenu_dia, $LibNotes, $afficher_note_cours, qw / -padx 2 -pady 5 -sticky nsew / );
     
    $bouton_sav->grid( qw / -column 1 -pady 5 -sticky nsew / );
     
    $bouton_start->grid( $bouton_stop, $bouton_exit,
      qw / -padx 2 -pady 5 -sticky nsew / );
     
    centrer_widget($Wm);
     
    # association virtuelle
    $widget_text_cours->eventAdd( '<<virtual_clic1>>' => '<ButtonRelease-1>' ) ;
     
    MainLoop;
     
    sub PasApas {
    	if ($Char eq "A") {
    		$Char = "B";
    	}
    	else {
    		$Char = "A";
    	}
    }
     
    sub stop {
    	$winmm->close;
      $Stop = 'Stop';
      PasApas();
    	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 {
     
      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");
      }
    	# Boucle générale
      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 + 200);
            $winmm->close;
          }
          else {
     
            #@Liste = ("mplayer $fichier_mp3");
            #system @Liste;
          }
          $Pause = $Wm->after( $config{DEFAUT}{tempo} * 1000 );    # 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 ) {
            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/;
     
    				# Boucle classique infinie sur une phrase
            if ( $Repeat ne '00' ) {
              $Nom        = "P_${Repeat}.utf8";
              $nom_fichier = "P_$Repeat";
              while ( $Stop eq "" ) {
              	TxtAra($repertoire, $Nom);
            		SonAra($repertoire, $nom_fichier);
            		TraEcr($repertoire, $nom_fichier);
            		TraOra($repertoire, $nom_fichier);
            		ComEcr($repertoire, $nom_fichier);
              }
            }
     
            # Arabe seul
            if ( $config{DEFAUT}{mod} eq 'AraSeul' ) {
          		TxtAra($repertoire, $Nom);
          		SonAra($repertoire, $nom_fichier);
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Arabe -> Français (Classique)
          	if ( $config{DEFAUT}{mod} eq 'AraFra' ) {
          		TxtAra($repertoire, $Nom);
          		SonAra($repertoire, $nom_fichier);
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		ComEcr($repertoire, $nom_fichier);
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Français -> Arabe
          	if ( $config{DEFAUT}{mod} eq 'FraAra' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		SonAra($repertoire, $nom_fichier);
          		ComEcr($repertoire, $nom_fichier);
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Dictée phrase arabe 1 fois
          	if ( $config{DEFAUT}{mod} eq 'Dict1' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 1 - dictée 1
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Dictée phrase arabe 2 fois
            if ( $config{DEFAUT}{mod} eq 'Dict2' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 1 - dictée 2
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 2 - dictée 2
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# Dictée phrase arabe 3 fois
            if ( $config{DEFAUT}{mod} eq 'Dict3' ) {
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		TxtAra($repertoire, $Nom);
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 1 - dictée 3
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 2 - dictée 3
          		$Time = SonAra($repertoire, $nom_fichier);
          		$Pause = $Wm->after( $config{DEFAUT}{tempo} * $Time );    # Pause 3 - dictée 3
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          	# PasApas
            if ( $config{DEFAUT}{mod} eq 'PasApas' ) {
            	$widget_text_cours->bind( '<<virtual_clic1>>' => \&PasApas ) ;
           		TxtAra($repertoire, $Nom);
          		SonAra($repertoire, $nom_fichier);
          		TraEcr($repertoire, $nom_fichier);
          		TraOra($repertoire, $nom_fichier);
          		if ( $config{DEFAUT}{aff} ne 'TOUT' ) { $widget_text_cours->delete( '1.0', 'end' ); }
          	}
          }
          $RepD++;
        }
      }
      if ( $config{DEFAUT}{aff} ne 'TOUT' ) {
        $widget_text_cours->delete( '1.0', 'end' );
        $widget_text_cours->update;
        $widget_text_cours->see('end');
      }
    }
     
    ################################################
    # Affichage texte arabe
    #
    sub TxtAra {
    	my ( $repertoire, $Nom ) = @_;
    				if ( $config{DEFAUT}{dia} eq "NON" ) {
        			$RepDia = "$repertoire/Acc";
        		}
        		else {
        				$RepDia = $repertoire;
        		}
            my $fichier_arabe = File::Spec->catfile( $RepDia, $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";
     
              # Affichage texte Arabe
              if ( $Stop ne "" ) { last; }
              while ( my $Ligne = <$fh> ) {
                $bouton_stop->focus();
                $widget_text_cours->insert( 'end', "\n", "g12" );
     
                $widget_text_cours->insert( 'end', $Ligne, $config{DEFAUT}{font} );
                $widget_text_cours->update;
                $widget_text_cours->see('end');
                if ( $config{DEFAUT}{mod} eq 'PasApas' ) {
                	$widget_text_cours->tkwait('variable' => \$Char);
                } 
     
                # Affichage Translittération
                if ( $Stop ne "" ) { last; }
                if ( $config{DEFAUT}{trans} eq 'OUI' ) {
                #	$widget_text_cours->insert( 'end', "\n" );
                	$widget_text_cours->insert( 'end', "\n", "g12" );
                  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
    #
    sub SonAra {
    	my ( $repertoire, $nom_fichier ) = @_;
            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' ) {
              	for my $NbAra ( 1 .. $config{DEFAUT}{nbara} ) {
                	$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 + 200);
    							$Message = "$fichier_mp3 ====> $Time";
              		$Wm->update;
      		      	$winmm->close;
      		      	$Pause = $Wm->after( $config{DEFAUT}{tempo} * 500 );   # Pause 4 - entre phrases Arabe
      		      }
              }
              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 5 - de Fichier Arabe
              }
            }
            return $Time;
    }
    #######################
    # Traduction écrite
    #
    sub TraEcr {
    		my ( $repertoire, $nom_fichier ) = @_;
            if ( $Stop ne "" ) { last; }
          	if ( $config{DEFAUT}{tra} eq 'ECRI' || $config{DEFAUT}{tra} eq 'TOUT' ) {
              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 6 - 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}{tra} eq 'ECRI' ) {
                $Pause = $Wm->after( $config{DEFAUT}{tempo} * 1000 );    # Pause 7 - après Traduction écrite
              }
              close FIC;
            }
    }
    #######################
    # Traduction orale
    #
    sub TraOra {
    	my ( $repertoire, $nom_fichier ) = @_;
            if ( $Stop ne "" ) { last; }
           	if ( ($config{DEFAUT}{tra} eq 'SON' || $config{DEFAUT}{tra} eq 'TOUT' ) && $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 8 - 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 + 200);
     			      $winmm->close;
              }
              else {
                #@Liste = ("mplayer $fichier_mp3");
                #system @Liste;
              }
              $Pause = $Wm->after( $config{DEFAUT}{tempo} * 100 );    # Pause 9 - de Fichier Français
              if ( $Stop ne '' ) {
                $Message = 'Lecture Stoppée';
                $Wm->update();
                last;
              }
            }
    }
     
    ############################
    # Affichage des commentaires
    #
    sub ComEcr {
    	my ( $repertoire, $nom_fichier ) = @_;
            # Commentaire écrit          !!!!!    NB il faut un fichier Tr....mp3 EVT vide !
            if ( ($config{DEFAUT}{tra} eq 'ECRI' || $config{DEFAUT}{tra} eq 'TOUT') && $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 10 - 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} * 500 );    # Pause 11 - après commentaire écrit
                }
              }
            }
    }
     
    #########################################
    # 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    => '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";
    }
    ##########################
    # Sauvegarde configuration
    #
    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;
    }
     
    sub sav {
      my ( $mw, $fichier, $ref_config ) = @_;
     
      # Sauvegarder configuration
      sauvegarde_configuration( $fichier, $ref_config );
      $Message = 'Paramètres sauvegardés';
      $Wm->update();
    }
     
    ##############################
    # 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;
    }

Discussions similaires

  1. [Perl/Tk] [Arabe] Afficher le contenu d'un fichier dans un widget Text
    Par rimenis dans le forum Interfaces Graphiques
    Réponses: 7
    Dernier message: 06/11/2013, 09h22
  2. Ecrire Arabe dans un fichier texte
    Par najma dans le forum MATLAB
    Réponses: 6
    Dernier message: 02/06/2011, 19h05
  3. comment afficher en arabe dans un label text
    Par lucastof dans le forum MATLAB
    Réponses: 1
    Dernier message: 29/05/2011, 02h26
  4. Problème d'ecriture arabe dans un fichier texte
    Par gateserv dans le forum Entrée/Sortie
    Réponses: 5
    Dernier message: 30/08/2008, 11h44
  5. [jsp][servlet][jdbc] afficher texte arabe dans un textarea
    Par villeneuvejsp dans le forum Servlets/JSP
    Réponses: 11
    Dernier message: 11/11/2005, 08h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo