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 :

Ouverture de fichier a travers perl/TK


Sujet :

Interfaces Graphiques Perl

  1. #1
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut Ouverture de fichier a travers perl/TK
    Hello,

    petit souci,...je suis parti d'un script perl qui fonctionné et j'ai décidé de faire les entrées par perl TK...

    je récupère avec ce type là:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $fenetre_principale->Label( -text => 'Quel fichier traiter ?  : ')->pack(-fill=>'both');
    my $input = $fenetre_principale->Entry( )->pack(-fill=>'both');
    je lance après la saisie comme cela:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $fenetre_principale->Button(-text => "GO !", -command => \&feu)->pack;
    MainLoop;
    j'ai fait un sub de mon script qui fonctionné en pensant naïvement que ça irait
    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
    sub feu{
    chomp $input;
     
    chomp $che;
    if ($che!~/\/$/){$che.="/";}
    while ($line=<IN>)
    {
      chomp $line;
      $url=$zone=$pdf='';
     
      if ($line=~/^toto/){
        $line=~/(toto).*\/([^\/]*\.pdf)/;
        $zone=$1;
        $pdf=$2;
        if ($pdf=~/ /){
          $pdf=~s/ /%20/g;
          $url=$zone.$che.$pdf;
          print OUT $url."\n";
          }
        else{
          $url=$zone.$che.$pdf;
          print OUT $url."\n";
          }
       }
     
    else{print OUT $line."\n";}
     
    }
     
    }
    bien évidemment cela ne marche pas et je ne sais pas ou mettre ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    open IN,'<:encoding(utf8)',"$input";
    open OUT,'>:encoding(utf8)',"$output";
    Merci d'avance...
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  2. #2
    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
    Essaye de jeter un coup d'oeil sur le FAQ Perl/Tk et de mieux reformuler ta demande, je n'ai pas tout saisie.

  3. #3
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut erreur de mon script
    tel que je t'ai présenté mes lignes de code...si je place mes deux "open" dans le sub...

    j'ai comme message d'erreur :

    tk::error at chemin ...(ligne de mon open d'ouverture)
    tk callback for .button
    tk::_ANON_ at chemin/tk.pm line 250
    tk::Button::butUp at chemin/Button.pm line175
    <ButtonRelease-1>
    <command bound to event>
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  4. #4
    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
    $input n'est pas un fichier et $output, je ne sais pas ce que c'est .

  5. #5
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut erreur de mon script


    bon,

    Alors comment faire pour récupérer un nom en saisie qui me permette d'ouvrir un fichier txt existant ?

    Parce que je pensais faire cela avec ce script...prendre un nom en saisie. puis m'en servir pour ouvrir mon fichier...

    $output est mon fichier de sortie construit sur la mm base que $input...
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  6. #6
    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
    C'est pour cela que je t'ai demandé de regarder la FAQ pour voir comment on crée et récupère un champ de saisie, tu as la réponse ici. Ton $input est un objet et tu dois utiliser la méthode get pour pouvoir extraire la saisie.

  7. #7
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut erreur de mon script
    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
    my $fenetre_principale = MainWindow->new( -title => 'Test de graph' );
     
    $fenetre_principale->Label( -text => 'Quel fichier traiter ?  : ')->pack(-fill=>'both');
    my $input = $fenetre_principale->Entry( )->pack(-fill=>'both');
     
     
    $fenetre_principale->Label( -text => 'Quel nom en sortie ?  : ')->pack(-fill=>'both');
    my $output = $fenetre_principale->Entry( )->pack(-fill=>'both');
     
     
    $fenetre_principale->Label( -text => 'Quel est le chemin du dossier ? : ')->pack(-fill=>'both');
    my $che = $fenetre_principale->Entry( )->pack(-fill=>'both');
     
    $fenetre_principale->Button(-text => "GO !", -command => sub { 
        print $entry->get,"\n";
      },
      ,)->pack;
    MainLoop;
       #
     
    sub feu{
    chomp $input;
     
    open IN,'<:encoding(utf8)',"$input";
    open OUT,'>:encoding(utf8)',"$output";
     
    chomp $che;
    if ($che!~/\/$/){$che.="/";}
    while ($line=<IN>)
    {
      chomp $line;
      $url=$zone=$pdf='';
     
      if ($line=~/^hug/){
        $line=~/(hug    http ).*\/([^\/]*\.pdf)/;
        $zone=$1;
        $pdf=$2;
        if ($pdf=~/ /){
          $pdf=~s/ /%20/g;
          $url=$zone.$che.$pdf;
          print OUT $url."\n";
          }
        else{
          $url=$zone.$che.$pdf;
          print OUT $url."\n";
          }
       }
     
    else{print OUT $line."\n";}
     
    }
     
    }
    #close IN;
    close OUT;
    Merci pour tes info Djibril mais étant trop novice encore, ça ne me dit pas comment ouvrir mon fichier avec la saisie et pourvoir utilisé mon sub...

    Après avoir lu ton dernier post je l'ai remis tel quelle...ça me renvoie à l'écran ma saisie...chouette, mais...je veux qu'il ce serve de ma saisie pour ouvrir mon fichier correspondant et le traiter avec mon sub
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  8. #8
    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
    Bon, on va faire plus propre et plus simple. Donc dis moi si je me trompe.
    Tu souhaites interagir avec l'utilisateur via une petite fenêtre Tk afin que :
    - L'utilisateur te donne un fichier en entrée et en sortie ?
    - Que tu puisses récupérer ce fichier input, faire un traitement dessus et créer un fichier (output) correspondant à celui qu'il t'aura donner ?

    Est ce bien cela, ou bien y a t il d'autres interactions ?

  9. #9
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut erreur de mon script
    C'est parfaitement ça !
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  10. #10
    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
    Voici un programme que je t'ai fait rapidement.

    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
    #!/usr/bin/perl
    use warnings;
    use strict;
    use Tk;
     
    my ( $fichier_input, $fichier_output );
    my $fenetre_principale = MainWindow->new( -title => 'Test de graph' );
     
    my $LabelInput = $fenetre_principale->Label( -text => 'Quel fichier traiter ?  : ' );
    my $BoutonInput = $fenetre_principale->Button(
      -text    => 'input file',
      -command => sub { $fichier_input = $fenetre_principale->getOpenFile(); }
    );
    my $AfficheInput = $fenetre_principale->Label( -textvariable => \$fichier_input );
     
    my $LabelOutput = $fenetre_principale->Label( -text => 'Quel nom en sortie ?  : ' );
    my $BoutonOutput = $fenetre_principale->Button(
      -text    => 'output file',
      -command => sub {
        $fichier_output = $fenetre_principale->getSaveFile( -initialfile => "FichierResutat.txt" );
      },
    );
    my $AfficheOutput = $fenetre_principale->Label( -textvariable => \$fichier_output );
     
    my $BoutonGO = $fenetre_principale->Button(
      -text    => "GO !",
      -command => \&feu,
    );
     
    # Utilisation de grid pour la disposition des éléments
    $LabelInput->grid( $BoutonInput, $AfficheInput, qw/ -sticky nsew / );
    $LabelOutput->grid( $BoutonOutput, $AfficheOutput, qw/ -sticky nsew / );
    $BoutonGO->grid( '-', qw/ -sticky nsew -pady 25/ );
     
    MainLoop;
     
    sub feu {
     
      unless ( defined $fichier_input ) {
        print "Pas de fichier input\n";
        return;
      }
      unless ( defined $fichier_output ) {
        print "Pas de fichier output\n";
        return;
      }
     
      print "input : $fichier_input\noutput : $fichier_output\n";return;
      open( IN,  '<:encoding(utf8)', $fichier_input )  or die("Impossible de lire le fichier $fichier_input\n");
      open( OUT, '>:encoding(utf8)', $fichier_output ) or die("Impossible de d'ecrire dans le fichier $fichier_output\n");
     
      while ( my $line = <IN> ) {
        chomp $line;
     
        # Ton traitement, et ecrit proprement
      }
      close IN;
      close OUT;
      return;
    }

  11. #11
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut erreur de mon script
    C'est super cool, je le test tout de suite...

    Merci
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  12. #12
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut erreur de mon script
    Il semble ne pas me créer le FichierResultat.txt...

    je suis en train de retester mon code d'origine mais cela semble aller
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  13. #13
    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
    Faut enlever la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    print "input : $fichier_input\noutput : $fichier_output\n";return;

  14. #14
    Membre habitué 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
    Points : 186
    Points
    186
    Par défaut erreur de mon script
    Merci pour tout Djibril,

    J'étais très loin de tout ça

    c'est la grande classe

    Encore merci !!
    Windows 7, 64 bit
    Perl 5.12, ActivePerl
    Python 3.2, ActivePython ( NOVICE ! )

  15. #15
    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
    N'oubliez pas le tag résolu. Merci

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

Discussions similaires

  1. ouverture de fichier txt
    Par juguul dans le forum MFC
    Réponses: 11
    Dernier message: 18/12/2003, 09h44
  2. Ouverture de fichier en api
    Par Michaël dans le forum Windows
    Réponses: 9
    Dernier message: 10/12/2003, 16h47
  3. Ouverture de fichier
    Par Ricou.13 dans le forum VBA Access
    Réponses: 3
    Dernier message: 07/10/2003, 08h59
  4. Réponses: 2
    Dernier message: 26/02/2003, 15h18
  5. [VBA-E] Evenement ouverture de fichier
    Par gjeff dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 13/12/2002, 09h42

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