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 :

Emplacement de code pour centrer un widget


Sujet :

Interfaces Graphiques Perl

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de PadawanInPerl
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    462
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2009
    Messages : 462
    Par défaut Emplacement de code pour centrer un widget
    Hello, j'ai repris ce bout de code pour centrer mon widget...

    http://perl.developpez.com/faq/tk/?p...CentrerFenetre

    Mais mon souci est qu'il affiche 2 fenêtres, avant le centrage et après.

    Je ne trouve pas la solution pour le placer correctement

  2. #2
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    Citation Envoyé par PadawanInPerl Voir le message
    Mais mon souci est qu'il affiche 2 fenêtres, avant le centrage et après.
    Comment ça, peux tu t'expliquer et montrer un exemple de code.

  3. #3
    Membre éclairé Avatar de PadawanInPerl
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    462
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2009
    Messages : 462
    Par défaut
    quand je lance le script, il y a une fenêtre qui s'affiche quasi vide qui est la mienne avant toutes les améliorations
    ENSUITE il y a ma fenêtre shell
    et PUIS par dessus ma superbe fenêtre centré.

    j'imagine un mauvais emplacement de mon code ou pire ?

  4. #4
    Membre éclairé Avatar de PadawanInPerl
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    462
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2009
    Messages : 462
    Par défaut
    voilà
    Fichiers attachés Fichiers attachés

  5. #5
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    emplacement de code. Tu peux le montrer ?

  6. #6
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    En me basant sur ton code fournit ci-dessus :

    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
    #!/usr/local/bin/perl
     
    use warnings;
    use strict;
    use Tk;
    use Tk::NoteBook;
    use Tk::DialogBox;
    use TK::Photo;
    use TK::JPEG;
    use TK::PNG;
     
    # ===== Interface graphique =====
     
    my $fenetre_principale = MainWindow->new( -title => 'PEB DBU-Seujet', -background => '#CF0063', );
    $fenetre_principale->geometry("400x400+50+50");
    $fenetre_principale->resizable( 0, 0 );    # Fenêtre non modifiable
    $fenetre_principale->Label(
      -text       => "Prêt inter-bibliothèques",
      -background => '#CF0063',
      -foreground => 'white',
      -font       => '{Comic Sans MS} 10 {bold}',
    )->pack();
     
    # =====  POUR CENTRER MA FENETRE A L'ECRAN =====
    CentrerWidget($fenetre_principale);
     
    sub CentrerWidget {
      unless ( scalar(@_) == 1 ) {
        die('Usage : CentrerWidget( $fenetre_principale );');
      }
      my ($Widget) = @_;
     
      # Height and width of the screen
      my $LargeurEcran = $Widget->screenwidth();
      my $HauteurEcran = $Widget->screenheight();
     
      # update le widget pour recuperer les vraies dimensions
      $Widget->update;
      my $LargeurWidget = $Widget->width;
      my $HauteurWidget = $Widget->height;
     
      # On centre le widget en fonction de la taille de l'ecran
      my $NouvelleLargeur = int( ( $LargeurEcran - $LargeurWidget ) / 2 );
      my $NouvelleHauteur = int( ( $HauteurEcran - $HauteurWidget ) / 2 );
      $Widget->geometry( $LargeurWidget . "x" . $HauteurWidget . "+$NouvelleLargeur+$NouvelleHauteur" );
     
      $Widget->update;
     
      return;
    }
     
    # ===== CHANGEMENT D'ICONE DE FENETRE =====
     
    my $MaNouvelleIcone = $fenetre_principale->Photo( -file => "cb.jpg" );
    $fenetre_principale->iconimage($MaNouvelleIcone);
     
    # ===== BLOCNOTE =====
     
    my $blocnote = $fenetre_principale->NoteBook(
      -backpagecolor => '#CF0063',
      -background    => 'white',
      -foreground    => '#CF0063',
      -font          => '{Comic Sans MS} 8 {bold}',
     
      #-inactivebackground => 'grey',
     
    )->pack(qw/-fill both -expand 1/);
     
    # ===== CREATION DES ONGLETS =====
     
    my $onglet_controle = $blocnote->add( "controle", -label => "Contrôle", );
    $onglet_controle->configure( -background => 'white', );    # obligatoire pour changer la couleur d'un onglet
     
    my $onglet_ajout = $blocnote->add( "ajout", -label => "Ajout", );
    $onglet_ajout->configure( -background => 'white', );
     
    # ===== ONGLET CONTROLE =====
     
    $onglet_controle->Label(
      -text       => "\nCONTRÔLE\n\n",
      -font       => '{Comic Sans MS} 11 {bold}',
      -background => 'white',
      -foreground => '#CF0063',
    )->pack();
     
    $onglet_controle->Label(
      -text       => "Entrer le code-barre du document :",
      -font       => '{Comic Sans MS} 11',
      -background => 'white',
      -foreground => '#CF0063',
    )->pack();
     
    my $cadre_controle_saisie = $onglet_controle->Frame( -background => 'white', )->pack(qw/ -padx 3 -pady 3/);
     
    $cadre_controle_saisie->Label(
      -text       => 'Code-barre : ',
      -font       => '{Comic Sans MS} 9',
      -background => 'white',
      -foreground => '#CF0063',
    )->pack(qw/ -side left /);
     
    my $entree_codebarre = $cadre_controle_saisie->Entry()->pack(qw/ -side left /);
     
    # ===== BOUTON CONTROLE =====
     
    my $ObjImage = $onglet_controle->Photo( -file => "loupe.jpg" );
    $cadre_controle_saisie->Button(
     
      #-image => $ObjImage,
      -command    => [ \&subone, $onglet_controle, $entree_codebarre ],
      -foreground => '#CF0063',
      -background => 'white',
    )->pack(qw/ -pady 1 -padx 1 -pady 3 -side left /);
     
    # ===== BOUTON SUPPRIMER =====
     
    my $ObjImage2 = $onglet_controle->Photo( -file => "supp.jpg" );
     
    $cadre_controle_saisie->Button(
     
      # -image    => $ObjImage2,
      -command    => [ \&subthree, $onglet_controle, $entree_codebarre ],
      -foreground => '#CF0063',
      -background => 'white',
    )->pack(qw/ -pady 1 -padx 1 -pady 3 -side left /);
     
    # ===== ONGLET AJOUT =====
     
    $onglet_ajout->Label(
      -text       => "\nAJOUT\n\n",
      -font       => '{Comic Sans MS} 11 {bold}',
      -background => 'white',
      -foreground => '#CF0063',
    )->pack();
     
    $onglet_ajout->Label(
      -text       => "Entrer le code-barre du document :",
      -font       => '{Comic Sans MS} 11',
      -background => 'white',
      -foreground => '#CF0063',
    )->pack();
     
    my $cadre_ajout_saisie
      = $onglet_ajout->Frame( -background => 'white', )->pack(qw/ -ipady 1 -ipadx 1 -pady 3/);
    $cadre_ajout_saisie->Label(
      -text       => ' Nouveau Code-barre : ',
      -font       => '{Comic Sans MS} 9',
      -background => 'white',
      -foreground => '#CF0063',
    )->pack(qw/ -side left/);
     
    my $entree_codebarre_new = $cadre_ajout_saisie->Entry()->pack(qw/ -side left/);
     
    # ===== BOUTON AJOUTER 2 =====
     
    my $ObjImage3 = $onglet_controle->Photo( -file => "ajout.gif" );
    $cadre_ajout_saisie->Button(
      -image      => $ObjImage3,
      -command    => [ \&subtwo, $onglet_ajout, $entree_codebarre_new ],
      -foreground => '#CF0063',
      -background => 'white',
    )->pack(qw/ -padx 5 -pady 5 -side left/);
     
    # ===== BOUTON FERMETURE TOUS ONGLET =====
     
    my $ObjImage5 = $onglet_controle->Photo( -file => "sortir.gif" );
    $fenetre_principale->Button(
      -image      => $ObjImage5,
      -command    => sub { exit; },
      -foreground => '#CF0063',
      -background => 'white',
      -font       => '{Comic Sans MS} 10 {bold}',
    )->pack();
     
    MainLoop;
     
    # ===== Procédures de contrôle =====
     
    sub subone {
      my ( $onglet, $entree_codebarre ) = @_;
     
      open OUT, '>>', 'log.txt'   or die("Ecriture impossible : $!");
      open IN,  '+<', 'liste.txt' or die("Lecture impossible : $!");
     
      my $codebarre_saisie = $entree_codebarre->get;
     
      unless ( defined $codebarre_saisie and $codebarre_saisie =~ /\S+/ ) {
        my $popup_erreur = $onglet->DialogBox(
          -title      => 'ERREUR',
          -buttons    => ['OK'],
          -background => 'white',
        );
     
        $popup_erreur->Label(
          -text       => "Vous n'avez fait aucune saisie\n\n",
          -background => 'white',
        )->pack();
     
        $popup_erreur->Label( -image => $popup_erreur->Photo( -file => "pas.jpg" ), )->pack();
     
        $popup_erreur->Subwidget("B_OK")->configure( -background => '#CF0063', );
        $popup_erreur->Show();
        return;
      }
      my $codebarre_trouve = 0;
      while ( my $line = <IN> ) {
        chomp $line;
     
        # ===== COMPARAISON DES CODES-BARRES =====
     
        if ( $line eq $codebarre_saisie ) {
          print OUT "code-barre $codebarre_saisie connu\n";    # Inscription dans le fichier log/data/archive
          my $popup_confirmation = $onglet->DialogBox(
            -title      => 'CONFIRMATION',
            -background => 'white',
            -buttons    => ['OK'],
          );
          $popup_confirmation->Subwidget("B_OK")->configure( -background => '#CF0063', );
     
          $popup_confirmation->Label(
            -text => "Le code-barre $codebarre_saisie,\n\n" . "fait bien partie du prêt inter-bibliothèques.\n\n",
            -background => 'white',
          )->pack();
     
          $popup_confirmation->Label( -image => $popup_confirmation->Photo( -file => "content.jpg" ), )->pack();
     
          $popup_confirmation->Show();
          $codebarre_trouve = 1;
          last;
        }
      }
     
      if ( $codebarre_trouve == 0 ) {
        my $popup_confirmation = $onglet->DialogBox(
          -title      => 'N° INCONNU',
          -background => 'white',
          -buttons    => ['OK'],
        );
        $popup_confirmation->Subwidget("B_OK")->configure( -background => '#00B9FF', );
        $popup_confirmation->Label(
          -text => "Le code-barre : $codebarre_saisie,\n"
            . "ne fait pas partie du prêt inter-bibliothèques.\n\n"
            . "Pour l'ajouter à la base,\npassez à l'onglet ajout.",
          -background => 'white',
        )->pack();
     
        $popup_confirmation->Label( -image => $popup_confirmation->Photo( -file => "pas.jpg" ), )->pack();
     
        $popup_confirmation->Show();
      }
      close(IN);
      close(OUT);
      return;
    }
     
    # ===== Procédures d'ajout =====
     
    sub subtwo {
      my ( $onglet, $entree_codebarre ) = @_;
     
      open OUT, '>>', 'log.txt'   or die("Ecriture impossible : $!");
      open IN,  '>>', 'liste.txt' or die("Lecture impossible : $!");
     
      my $codebarre_saisie_new = $entree_codebarre_new->get;
     
      unless ( defined $codebarre_saisie_new and $codebarre_saisie_new =~ /\S+/ ) {
        my $popup_erreur = $onglet->DialogBox(
          -title      => 'ERREUR',
          -buttons    => ['OK'],
          -background => 'white',
        );
     
        $popup_erreur->Label(
          -text       => "\nVous n'avez fait aucune saisie\n\n",
          -background => 'white',
        )->pack();
     
        $popup_erreur->Label( -image => $popup_erreur->Photo( -file => "pas.jpg" ), )->pack();
     
        $popup_erreur->Subwidget("B_OK")->configure( -background => '#CF0063', );
        $popup_erreur->Show();
        return;
      }
     
      print IN $codebarre_saisie_new, "\n";
     
      my $popup_ajout = $onglet->DialogBox(
        -title      => 'AJOUT',
        -buttons    => ['OK'],
        -background => 'white',
      );
      $popup_ajout->Label(
        -text       => "Votre code à barre a bien été insérer dans la base.",
        -background => 'white',
      )->pack();
     
      $popup_ajout->Subwidget("B_OK")->configure( -background => '#CF0063', );
      $popup_ajout->Show();
      return;
     
      close(IN);
      close(OUT);
      return;
    }
     
    # ===== Procédures de suppression =====
     
    sub subthree {
     
      my ( $onglet, $entree_codebarre ) = @_;
     
      open IN,  '+<liste.txt' or die("Lecture impossible : $!");
      open OUT, '>temp.txt'   or die("Lecture impossible : $!");
      open LOG, '>>', 'log.txt' or die("Ecriture impossible : $!");
     
      my @liste;
      my $codebarre_saisie = $entree_codebarre->get;
     
      while ( my $line = <IN> ) {
        chomp $line;
        if ( $codebarre_saisie ne $line ) { push( @liste, $line . "\n" ); }
      }
     
      print OUT @liste;
     
      close(IN);
      close(OUT);
     
      rename( "liste.txt", "xxx.txt" );
      rename( "temp.txt",  "liste.txt" );
      rename( "xxx.txt",   "temp.txt" );
     
      open OUT, '>temp.txt' or die("Lecture impossible : $!");
      close(OUT);
     
      print LOG "Suppression du CB : $codebarre_saisie\n";    # Inscription dans le fichier log/data/archive
      close(LOG);
     
      my $popup_sup = $onglet->DialogBox(
        -title      => 'CONFIRMATION',
        -background => 'white',
        -buttons    => ['OK'],
      );
      $popup_sup->Subwidget("B_OK")->configure( -background => 'green', );
      $popup_sup->Label(
        -text       => "Le code-barre $codebarre_saisie,\n\n" . "a bien été supprimé.\n\n",
        -background => 'white',
      )->pack();
      $popup_sup->Show();
    }

  7. #7
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    Rajoute un effet degradé dans un des tes boutons, ça peut être sympa .

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 29/12/2011, 14h05
  2. code pour fermer un formulaire
    Par rippey dans le forum IHM
    Réponses: 2
    Dernier message: 21/10/2003, 15h51
  3. [Lomboz] Génération de code pour EJB
    Par paikan dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 09/07/2003, 14h28
  4. Réponses: 2
    Dernier message: 01/04/2003, 22h09
  5. code pour interbase 6.0 et 6.5 de generateur
    Par tripper.dim dans le forum InterBase
    Réponses: 4
    Dernier message: 01/07/2002, 11h29

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