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 :

Ecran Tk clignote avec Console


Sujet :

Interfaces Graphiques Perl

  1. #21
    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
    Bonjour djibril,

    Pressé de faire un test, j'en ai fait un, en vitesse, de bon matin.
    L'interface est plus jolie c'est sûr, ça n'a jamais été mon fort, mais comme je ne peux diffuser le programme, les cours n'étant pas de moi, je l'avais réduite le plus possible pour avoir un plus grand scrolled.
    Mais après utilisation du tien, c'est quand même plus beau, plus confortable et convivial.
    Donc j'adopte !

    Pour ce qui est des anomalies, aucune n'est résolue.
    Sur Linux, XP et Windows7 :

    - Lorsqu'on promène le focus sur le mot ou la phrase arabe ou qu'on clique dessus il y a toujours scission.
    Bon celle-ci, comme je l'avais écrit, n'est pas pénalisante puisqu'on n'a pas à cliquer sur le mot ou la phrase durant l'exécution.

    - Il y a toujours une sorte de <Tab> devant certains mots ou phrases, pour mieux s'en rendre compte il faut passer le scrolled en justification à droite.
    Bon celle-ci n'est pas trop pénalisante, enfin pour commencer car au début les phrases sont courtes, c'est pour cette raison que j'avais justifié au centre. Plus tard lorsqu'il y aura du texte sur plusieurs lignes ça peut être gênant. Mais pour le moment ça me suffit !

    - Durant l'exécution, lorsqu'on clique sur un bouton pour modifier un paramètre, ne serait-ce que pour faire un "stop", ou pire lorsqu’on clique seulement à l'extérieur d'un bouton :
    - le basculement interface/console (clignotement) reprend
    - de plus il y a le message d'erreur :
    Erreur : Undefined subroutine &main::stop called at C:/Perl/site/lib/Tk.pm line 250, <FIC> line 1.
    J'ai ajouté la routine :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    MainLoop;
    sub stop {
    	$Stop = "Stop";
    }
    sub start {
    ...
    C'est OK.

    Par contre ce "clignotement" lui est pénalisant.
    Il ne se produit que sous Windows7, pas sur Linux ni XP.
    Linux (activestate) et XP (strawberry) sont sur un desktop et voient tous les deux la même partition Fat32.
    Windows7 est lui sur un portable Sony. Je ne sais pas déterminer si l'anomalie provient du matériel (Sony) ou de l'OS Windows7.

    Je n'ai pas encore eu le temps d'étudier ton code, en plus de l'interface, j'apprécie la gestion centralisée des paramètres dans un .ini

    PS : Je suis absent de la matinée, je reprendrai les tests cet après-midi.
    @+
    MERCI BEAUCOUP !

  2. #22
    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 : 499 184
    Points
    499 184
    Par défaut
    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
    #!/usr/bin/perl
    #=====================================================================
    #	Auteur : dmganges
    # Date   : 18/11/2011 01:56:46
    # But    : Cours d'arabe
    #=====================================================================
    use strict;
    use warnings;
    use Tk;
    use Tk::LabFrame;
    use Tk::ROText;
     
    use Encode;
    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
    # Cours
    my $afficher_note_cours = $cadre_configuration->Button(
      -text    => 'Cours',
      -command => \&Cours,
    );
     
    # 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 ]
    );
     
    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 ]
    );
     
    # 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,
      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 {
      $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 '' ) {
        $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' ) {
            $winmm->load($fichier_mp3);    # Load music file disk, or an URL
            #$Pause = $Wm->after(250);
            #sleep 2;
            $winmm->play;                  # Play the music
            $winmm->volume(100);           # Set volume after playing
     
            @Time = split /:/, $winmm->length(1);
            my $Duree = sprintf '%02d%02d', $Time[0], $Time[1];
     
            sleep int( $Duree + 2 );
            $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' );
          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 ( $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
              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 ( $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;
            }
     
            # 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$!";
              }
              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 ( lc $OSNAME eq 'mswin32' ) {
                $winmm->load($fichier_mp3);                             # Load music file disk, or an URL
                #$Pause = $Wm->after(250);
                #sleep 2;
                $winmm->play;                                           # Play the music
                $winmm->volume(100);                                    # Set volume after playing
     
                @Time = split( /:/, $winmm->length(1) );
                my $Duree = sprintf '%02d%02d', $Time[0], $Time[1];
                sleep int( $Duree + 2 );
                $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 ( $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} * 50 );     # Pause 5 - avant Traduction écrite
              }
              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 ( $config{DEFAUT}{tempo} != 0 ) {
                $Pause = $Wm->after( $config{DEFAUT}{tempo} * 100 );    # Pause 6 - après Traduction écrite
              }
              close FIC;
            }
     
            # Traduction orale
            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 ( !-e $fichier_traductionS_mp3 ) {
                die "Impossible de lire le fichier $fichier_traductionS_mp3\n$!";
              }
              if ( $config{DEFAUT}{tempo} != 0 ) {
                $Pause = $Wm->after( $config{DEFAUT}{tempo} * 50 );    # Pause 7 - avant SON Français
              }
              if ( lc $OSNAME eq 'mswin32' ) {
                $winmm->load($fichier_traductionS_mp3);                # Load music file disk, or an URL
                $Pause = $Wm->after(250);
                sleep 2;
                $winmm->play;                                          # Play the music
                $winmm->volume(100);                                   # Set volume after playing
     
                @Time = split /:/, $winmm->length(1);
                my $Duree = sprintf '%02d%02d', $Time[0], $Time[1];
                sleep int( $Duree + 2 );
                $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
                }
                open my $fh, '<:encoding(UTF-8)', $fichier_traductionE
                  or die "Impossible de lire $fichier_traductionE\n$!";
                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($MwError);
     
      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;
    }
    j'ai rajouté le centrage de la fenêtre et commenté certains sleep et after. Maintenant, j'ai l'impression de ne plus avoir de sauts intempestifs. Je suis sous Vista.

  3. #23
    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
    Déjà MERCI !

    POUR LA SCISSION :
    toujours pareil pour XP et Windows7. Linux pas testé.
    Mais pour moi c'est OK, pas la peine de se casser la tête d'autant qu'il faut vraiment faire exprès de cliquer dans cette zone !!!

    POUR LES DÉBUTS DE LIGNE : (<Tab>)
    toujours pareil, j'ai passé le widget_text à 'right'
    Pour faire un essai rapidement, tu passes : Son à "NON", Texte à "TOUT", Trans à "NON", Trad à "00"
    Je ne comprends pas pourquoi ça zigzag !

    LE MEILLEURS :
    J'avais aussi remarqué, sous Windows7, que plus les pauses étaient longues et plus les anomalies de clignotement étaient flagrantes et longues.
    J'avais donc également passé les $Duree à + 1 au lieu de 2.
    Dans ton dernier jet j'ai également passé des sleep à 1

    Sous XP toujours OK !
    Sous Windows 7 c'est quasiment SUPER, je doute qu'on puisse faire mieux :
    Pour faire clignoter, il faut le faire exprès c-à-d cliquer comme un malade.
    Mais en cas de clic involontaire j'ai trouvé la parade, même avec les sleep et $Duree = 2 , il suffit de cliquer en dehors de la fenêtre du programme et si elle est maximisée, il suffit de cliquer dans la barre des taches, et tout rentre dans l'ordre.
    J'ai le COMMENT mais pas le POURQUOI !!!

    J'ai UN PEU modifié l'interface, histoire de m'entraîner... et pour récupérer un peu de place dans le scrolled. Tu me diras si je n'ai pas mis le foutoir !!!

    J'ai dû ajouter use encoding 'utf8';
    J'ai passé tous mes fichiers, même les traductions T_xx.txt en utf8.
    Ceux que je t'ai envoyés sont en ANSI. Sans le encoding j'ai 3 caractères indésirables devant les traductions.

    Deux petites questions indépendantes, si tu préfères j'ouvre 2 autres discussions. J'ai fait une recherche trop rapide surement !

    1 - Est-il possible de faire un use conditionnel ?
    car je n'ai pas : Win32::MediaPlayer; Sous Linux
    Ne t'attardes pas, juste pour info, car je vais abandonner l'exécution sous Linux, pour moi tout seul, je fini par passer plus de temps à coder qu'à apprendre l'arabe ...

    2 - Peut-on avoir plusieurs instructions dans le or die
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    open FIC, '<', $fichier_traduction
                or die "Impossible de lire $fichier_traduction\n$!";
    J'explique : Tous les mots arabes ne se traduisent pas, exemple les mois lunaires. Dans ce cas je n'ai pas de T_xx.txt, il me faudrait sortir comme avant avec un next ou un last... ou ne pas entrer si le fichier n'existe pas.
    Pardonne-moi mes lacunes !!!

    EN CONCLUSION :
    Seul le mauvais cadrage à droite qui zigzag me gène un peu, surtout pour l'avenir avec des phrases longues !
    Pour moi le reste est résolu !

    D'abord ENCORE MERCI,
    et ton deuxième jet modifié :

    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
    #!/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 ]
    );
     
    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 {
      $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 '' ) {
        $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' ) {
            $winmm->load($fichier_mp3);    # Load music file disk, or an URL
            #$Pause = $Wm->after(250);
            #sleep 2;
            $winmm->play;                  # Play the music
            $winmm->volume(100);          # Set volume after playing
     
            @Time = split /:/, $winmm->length(1);
            my $Duree = sprintf '%02d%02d', $Time[0], $Time[1];
     
            sleep int( $Duree + 1 );
            $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' );
          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 ( $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
              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 ( $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;
            }
     
            # 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$!";
              }
              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 ( lc $OSNAME eq 'mswin32' ) {
                $winmm->load($fichier_mp3);                            # Load music file disk, or an URL
                #$Pause = $Wm->after(250);
                #sleep 2;
                $winmm->play;                                          # Play the music
                $winmm->volume(100);                                    # Set volume after playing
     
                @Time = split( /:/, $winmm->length(1) );
                my $Duree = sprintf '%02d%02d', $Time[0], $Time[1];
                sleep int( $Duree + 1 );
                $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 ( $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} * 50 );    # Pause 5 - avant Traduction écrite
              }
              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 ( $config{DEFAUT}{tempo} != 0 ) {
                $Pause = $Wm->after( $config{DEFAUT}{tempo} * 100 );    # Pause 6 - après Traduction écrite
              }
              close FIC;
            }
     
            # Traduction orale
            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 ( !-e $fichier_traductionS_mp3 ) {
                die "Impossible de lire le fichier $fichier_traductionS_mp3\n$!";
              }
              if ( $config{DEFAUT}{tempo} != 0 ) {
                $Pause = $Wm->after( $config{DEFAUT}{tempo} * 50 );    # Pause 7 - avant SON Français
              }
              if ( lc $OSNAME eq 'mswin32' ) {
                $winmm->load($fichier_traductionS_mp3);                # Load music file disk, or an URL
                $Pause = $Wm->after(250);
                sleep 1;
                $winmm->play;                                          # Play the music
                $winmm->volume(100);                                  # Set volume after playing
     
                @Time = split /:/, $winmm->length(1);
                my $Duree = sprintf '%02d%02d', $Time[0], $Time[1];
                sleep int( $Duree + 1 );
                $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
                }
                open my $fh, '<:encoding(UTF-8)', $fichier_traductionE
                  or die "Impossible de lire $fichier_traductionE\n$!";
                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    => 'right',
          );
        }
      }
     
      $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;
    }

  4. #24
    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
    Bonjour,

    J'ai remplacé les séquences du type :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    $winmm->load($fichier_traductionS_mp3); # Load music file disk, or an URL
    $Pause = $Wm->after(250);
    sleep 1;
    $winmm->play;                                          # Play the music
    $winmm->volume(100);                               # Set volume after playing
     
    @Time = split /:/, $winmm->length(1);
    my $Duree = sprintf '%02d%02d', $Time[0], $Time[1];
    sleep int( $Duree + 1 );
    $winmm->close;
    par :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    $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;
    Autrement dit j'ai évité de mélanger les sleep et $Pause = $Wm->after
    Je n'ai conservé que les $Pause = $Wm->after
    en utilisant $Time = $winmm->length; qui donne le temps en millisecondes, au lieu de @Time = split /:/, $winmm->length(1);
    Ben ça fonctionne SUPER bien SANS basculement Tk / Console quelque soit la durée de pause choisie !

    MERCI djibril !
    Dernière mouture :

    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
    #!/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;
    }

  5. #25
    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 : 499 184
    Points
    499 184
    Par défaut
    Bravo

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. [Formulaire][03]Clignotement avec TabControl
    Par Pmatt dans le forum IHM
    Réponses: 5
    Dernier message: 26/04/2007, 11h04
  2. Impossible de prendre une valeur avec Console.Read( ?
    Par Tux1 dans le forum Windows Forms
    Réponses: 9
    Dernier message: 07/01/2007, 16h29
  3. [Sécurité] Ecran De Login Avec Htaccess
    Par rte304 dans le forum Langage
    Réponses: 3
    Dernier message: 08/12/2006, 14h03
  4. Stocker un imprim ecran sous bmp avec l'api windows
    Par Tofalu dans le forum Windows
    Réponses: 7
    Dernier message: 04/05/2005, 11h32

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