PERL Textbox multiligne et Tableau
Résolu
charlesbouillault
Messages postés
138
Date d'inscription
Statut
Membre
Dernière intervention
-
lami20j Messages postés 21331 Date d'inscription Statut Modérateur, Contributeur sécurité Dernière intervention -
lami20j Messages postés 21331 Date d'inscription Statut Modérateur, Contributeur sécurité Dernière intervention -
Bonjour,
Voila j'ai un souçi, je lis un fichier text, puis je l'affiche dans une textbox, en même temps je sauvegarde chaque ligne dans un tableau!!
Lorsque l'utilisateur ferme la fenetre contenant la textbox je voudrais simplement restaocker les lignes de la text box dans un autre tableau, faire une comparaison ligne par ligne entre les deux et mettre a jour si beasoin le fichier text..
Je vous montre la partis de mon code qui bloque!!!
je voudrais juste savoire comment retransferer le contenu de la textbox multiligne ligne par ligne dans un Tableau!!!
Merci beaucoups ça m'arrangerai bien car je suis bloqué!!!
#Fonction pour Afficher le fichier
sub AfficherFichier
{
$Bool = 0;
my $fenetreAffichage = new MainWindow () ;
$fenetreAffichage -> title ('Affichage Document') ;
$fenetreAffichage ->maxsize (1024, 768) ;
$fenetreAffichage ->minsize (1024, 768) ;
$txtAffichage = $fenetreAffichage -> Scrolled ('Text',
-scrollbars => 'se',
-width => 1024,
-height => 768
) ;
$txtAffichage -> pack () ;
$fichier = $txtFichier -> get ( ) ;
open (LIRE, $fichier) ;
$cpt = 0;
while (<LIRE>)
{
$txtAffichage -> insert ( 'end', $_ ) ;
$TabAvant[$cpt] = $_;
$cpt++;
}
close (LIRE);
$fenetreAffichage -> bind ( "<Destroy>" , \&Enregistrer) ;
}
sub Enregistrer
{
if ($Bool==0)
{
$Bool = 1;
c'est ici que je veus stocker le contenu de
ma textebox $txtAffichage dans un le @TabApres
puis faire la comparaison entre les deux!!
}
}
Merci à tous car c'est urgent!!!
Voila j'ai un souçi, je lis un fichier text, puis je l'affiche dans une textbox, en même temps je sauvegarde chaque ligne dans un tableau!!
Lorsque l'utilisateur ferme la fenetre contenant la textbox je voudrais simplement restaocker les lignes de la text box dans un autre tableau, faire une comparaison ligne par ligne entre les deux et mettre a jour si beasoin le fichier text..
Je vous montre la partis de mon code qui bloque!!!
je voudrais juste savoire comment retransferer le contenu de la textbox multiligne ligne par ligne dans un Tableau!!!
Merci beaucoups ça m'arrangerai bien car je suis bloqué!!!
#Fonction pour Afficher le fichier
sub AfficherFichier
{
$Bool = 0;
my $fenetreAffichage = new MainWindow () ;
$fenetreAffichage -> title ('Affichage Document') ;
$fenetreAffichage ->maxsize (1024, 768) ;
$fenetreAffichage ->minsize (1024, 768) ;
$txtAffichage = $fenetreAffichage -> Scrolled ('Text',
-scrollbars => 'se',
-width => 1024,
-height => 768
) ;
$txtAffichage -> pack () ;
$fichier = $txtFichier -> get ( ) ;
open (LIRE, $fichier) ;
$cpt = 0;
while (<LIRE>)
{
$txtAffichage -> insert ( 'end', $_ ) ;
$TabAvant[$cpt] = $_;
$cpt++;
}
close (LIRE);
$fenetreAffichage -> bind ( "<Destroy>" , \&Enregistrer) ;
}
sub Enregistrer
{
if ($Bool==0)
{
$Bool = 1;
c'est ici que je veus stocker le contenu de
ma textebox $txtAffichage dans un le @TabApres
puis faire la comparaison entre les deux!!
}
}
Merci à tous car c'est urgent!!!
A voir également:
- PERL Textbox multiligne et Tableau
- Tableau word - Guide
- Tableau ascii - Guide
- Trier un tableau excel - Guide
- Tableau croisé dynamique - Guide
- Imprimer tableau excel sur une page - Guide
9 réponses
Merci pour ton aide, mais me reste un petit souçi, je ne vois pas comment recupérer ce contenu lors de la femeture de la fenetre!!!:
voia le code modifié :
sub AfficherFichier
{
$Bool = 0;
$fenetreAffichage = new MainWindow () ;
$fenetreAffichage -> title ('Affichage Document') ;
$fenetreAffichage ->maxsize (1024, 768) ;
$fenetreAffichage ->minsize (1024, 768) ;
$fenetreAffichage -> bind ( "<Destroy>", \&Enregistrer) ;
$txtAffichage = $fenetreAffichage -> Scrolled ('Text',
-scrollbars => 'se',
-width => 1024,
-height => 768) ;
$txtAffichage -> pack () ;
$fichier = $txtFichier -> get ( ) ;
open (LIRE, $fichier) ;
while (<LIRE>)
{
$txtAffichage -> insert ( 'end', $_ ) ;
}
close (LIRE);
$tabAvant = $txtAffichage->get("1.0",'end');
}
sub Enregistrer
{
if ($Bool==0)
{
$tabApres = $txtAffichage->get("1.0",'end');
$Bool = 1;
$modif = 0;
if ($tabAvant ne $tabApres)
{
$modif = 1;
};
};
}
au niveau de l'evenement Destroy qui utilise la fonction "Enregistrer", il me reste un probléme, étant doné que j'utilise l'événement destroy, lorsque je veus recupérer le contenu de ma $txtAffichage il me dis qu'elle est détruite, je m'en doute, mais je ne vois pas trop comment faire ce control autrement !!!
Y aurait un autre evenement conçernant le fermeture de la fenetre ?
voia le code modifié :
sub AfficherFichier
{
$Bool = 0;
$fenetreAffichage = new MainWindow () ;
$fenetreAffichage -> title ('Affichage Document') ;
$fenetreAffichage ->maxsize (1024, 768) ;
$fenetreAffichage ->minsize (1024, 768) ;
$fenetreAffichage -> bind ( "<Destroy>", \&Enregistrer) ;
$txtAffichage = $fenetreAffichage -> Scrolled ('Text',
-scrollbars => 'se',
-width => 1024,
-height => 768) ;
$txtAffichage -> pack () ;
$fichier = $txtFichier -> get ( ) ;
open (LIRE, $fichier) ;
while (<LIRE>)
{
$txtAffichage -> insert ( 'end', $_ ) ;
}
close (LIRE);
$tabAvant = $txtAffichage->get("1.0",'end');
}
sub Enregistrer
{
if ($Bool==0)
{
$tabApres = $txtAffichage->get("1.0",'end');
$Bool = 1;
$modif = 0;
if ($tabAvant ne $tabApres)
{
$modif = 1;
};
};
}
au niveau de l'evenement Destroy qui utilise la fonction "Enregistrer", il me reste un probléme, étant doné que j'utilise l'événement destroy, lorsque je veus recupérer le contenu de ma $txtAffichage il me dis qu'elle est détruite, je m'en doute, mais je ne vois pas trop comment faire ce control autrement !!!
Y aurait un autre evenement conçernant le fermeture de la fenetre ?
apperement ça appel la même procédure!!!
Voici le msg d'erreur :
<Destroy>
(command bound to event)
Tk::Error: Failed to AUTOLOAD 'Tk::Widget::get' at C:/Perl/lib/Tk/Derived.pm line 469
l'événement interviens apres le destruction de la feuille $fenetreAffichage ce qui fait que l'objet txtAffichage dessus est detruit aussi, donc je ne peut plus recuperer les données!!!
Je sais que en VB par exemple, il y l'evenement une fois la feuille fermé, mais aussi durant la fermeture "Closed" ou "Closing"
un peu chiant mon truc la, sinon je peus mettre un bouton "Quitter", mais comme surprimmer la croix en haut de la $fenetreAffichage!!!
Voici le msg d'erreur :
<Destroy>
(command bound to event)
Tk::Error: Failed to AUTOLOAD 'Tk::Widget::get' at C:/Perl/lib/Tk/Derived.pm line 469
l'événement interviens apres le destruction de la feuille $fenetreAffichage ce qui fait que l'objet txtAffichage dessus est detruit aussi, donc je ne peut plus recuperer les données!!!
Je sais que en VB par exemple, il y l'evenement une fois la feuille fermé, mais aussi durant la fermeture "Closed" ou "Closing"
un peu chiant mon truc la, sinon je peus mettre un bouton "Quitter", mais comme surprimmer la croix en haut de la $fenetreAffichage!!!
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
et si tu fait ça
$fenetreAffichage->destroy() if Tk::Exists($fenetreAffichage); $fenetreAffichage->OnDestroy(\&Enregistrer);
voial l'erreur qu'il me retourne :
c'est vraiment casse tête j'y suis depuis ce matin 8heure, impossible de trouver !!!
Tk::Error: MainWindow=HASH(0x2ec314c) is not a widget at Client_FTP.pl line 161 Tk callback for .button1 Tk::__ANON__ at C:/Perl/lib/Tk.pm line 252 Tk::Button::butUp at C:/Perl/lib/Tk/Button.pm line 111 <ButtonRelease-1> (command bound to event)
c'est vraiment casse tête j'y suis depuis ce matin 8heure, impossible de trouver !!!
Tiens, je te poste le script complet pour que tu puisse voire a quoi ça ressemble!!! :
j'ai mis en gras les partie conçernées!!
Merci beaucoups pour ton aide car la je bloque :)
use Net::FTP ; use Tk ; use Tk::Dialog ; use Tk::Event; # Programme principal MiseEnForme () ; MainLoop () ; #Fonction de Mise en Forme sub MiseEnForme { $fenetrePrincipale = new MainWindow () ; $fenetrePrincipale -> title ('Client FTP') ; $fenetrePrincipale ->maxsize ( 390, 215 ) ; $fenetrePrincipale ->minsize ( 390, 215 ) ; $labServeur = $fenetrePrincipale -> Label ( -text =>'Adresse du serveur FTP :', -foreground => 'blue', ); $labServeur ->place ( -x => 10, -y => 30, ) ; $txtServeur = $fenetrePrincipale -> Entry ( -text => 'ftp.cpan.org', -width => 20 ); $txtServeur->place ( -x => 200, -y => 30, ) ; $labLogin = $fenetrePrincipale -> Label ( -text =>'Login :', -foreground => 'blue' ); $labLogin ->place ( -x => 10, -y => 60, ) ; $txtLogin = $fenetrePrincipale -> Entry ( -text => 'anonymous', -width => 20, ) ; $txtLogin ->place ( -x => 200, -y => 60, ) ; $labMDP = $fenetrePrincipale -> Label ( -text =>'Mot de passe :', -foreground => 'blue' ); $labMDP ->place ( -x => 10, -y => 90, ) ; $txtMDP = $fenetrePrincipale -> Entry ( -text => 'anonymous', -width => 20 ) ; $txtMDP -> place ( -x => 200, -y => 90, ) ; $labChemin = $fenetrePrincipale -> Label ( -text =>'Chemin complet du fihchier :', -foreground => 'blue' ); $labChemin ->place ( -x => 10, -y => 120, ) ; $txtChemin = $fenetrePrincipale -> Entry ( -text => '/pub/CPAN', -width => 20 ) ; $txtChemin -> place ( -x => 200, -y => 120, ) ; $labFichier = $fenetrePrincipale -> Label ( -text =>'Nom complet du fichier :', -foreground => 'blue' ); $labFichier ->place ( -x => 10, -y => 150, ) ; $txtFichier = $fenetrePrincipale -> Entry ( -text => 'README', -width => 20 ) ; $txtFichier -> place ( -x => 200, -y => 150, ) ; $cmdDownload = $fenetrePrincipale -> Button ( -text => 'Téléchargement' , -command => \&OuvrireConnection , -width =>20 ) ; $cmdDownload -> place ( -x => 0, -y => 192, ) ; $cmdAfficher = $fenetrePrincipale -> Button ( -text => 'AfficherFichier' , -command => \&AfficherFichier , -width =>20, ) ; $cmdAfficher -> place ( -x => 130, -y => 192, ) ; $cmdQuitter = $fenetrePrincipale -> Button ( -text => 'Quitter' , -command => \&Quitter , -width =>20 ) ; $cmdQuitter -> place ( -x => 260, -y => 192) ; } #Fonction Pour ouvrire la connection sur le serveur FTP sub OuvrireConnection { my $serveur = $txtServeur -> get () ; my $login = $txtLogin -> get () ; my $mdp = $txtMDP -> get () ; my $chemin = $txtChemin -> get () ; my $fichier = $txtFichier -> get () ; my $ftp = Net::FTP ->new ($serveur) ; $ftp->login ($login, $mdp) ; $ftp->cwd ($chemin) ; $ftp->get ($fichier) ; $ftp->quit ; my $boite_dialogue_Download = $fenetrePrincipale-> Dialog ( -title => 'Information' , -text => "Le fichier $fichier est bien telechargé, il se situe dans le repertoire du programme Client FTP !" , -bitmap => 'info' , -default_button => 'OK' , -buttons => [ 'OK' ] ) ; $boite_dialogue_Download -> Show ( ) ; } #Fonction pour Afficher le fichier sub AfficherFichier { $Bool = 0; $fenetreAffichage = new MainWindow () ; $fenetreAffichage -> title ('Affichage Document') ; $fenetreAffichage ->maxsize (1024, 768) ; $fenetreAffichage ->minsize (1024, 768) ; #$fenetreAffichage -> bind ( "<Destroy>", \&Enregistrer) ; #$fenetreAffichage->OnDestroy(\&Enregistrer); #$fenetreAffichage->destroy() if Tk::Exists($fenetreAffichage); #$fenetreAffichage->OnDestroy(\&Enregistrer); $txtAffichage = $fenetreAffichage -> Scrolled ('Text', -scrollbars => 'se', -width => 1024, -height => 768) ; $txtAffichage -> pack () ; $fichier = $txtFichier -> get ( ) ; open (LIRE, $fichier) ; while (<LIRE>) { $txtAffichage -> insert ( 'end', $_ ) ; }; close (LIRE); $tabAvant = $txtAffichage->get("1.0",'end'); } #Fonction Enregister sub Enregistrer { if ($Bool==0) { $Bool = 1; $tabApres = $txtAffichage->get("1.0",'end'); if ($tabAvant ne $tabApres) { my $boite_dialogue_Enregistrer = $fenetrePrincipale -> Dialog ( -title => 'Enregistrer' , -text => 'Voulez vous enregistrer vos modifications ?' , -bitmap => 'question' , -default_button => 'Oui' , -buttons => [ 'Oui' , 'Non' ] ) ; my $reponse = $boite_dialogue_Enregistrer -> Show ( ) ; if ( $reponse eq 'Oui' ) { open (ECRIRE, ">$fichier"); print ECRIRE $tabApres; close (ECRIRE); }; }; }; } #Fonction pour Quitter l'Applixcation sub Quitter { my $boite_dialogue_Quitter = $fenetrePrincipale -> Dialog ( -title => 'Quitter' , -text => 'Etes vous certain de vouloir quitter ?' , -bitmap => 'question' , -default_button => 'Oui' , -buttons => [ 'Oui' , 'Non' ] ) ; my $reponse = $boite_dialogue_Quitter -> Show ( ) ; if ( $reponse eq 'Oui' ) { exit(); }; }
j'ai mis en gras les partie conçernées!!
Merci beaucoups pour ton aide car la je bloque :)
c'est bon j'ai trouvé :)
Prise de tête mais ça y est !!!! Je te montre le script avec en gras le truc !!!
Prise de tête mais ça y est !!!! Je te montre le script avec en gras le truc !!!
use Net::FTP ; use Tk ; use Tk::Dialog ; use Tk::Event; # Programme principal MiseEnForme () ; MainLoop () ; #Fonction de Mise en Forme sub MiseEnForme { $fenetrePrincipale = new MainWindow () ; $fenetrePrincipale -> title ('Client FTP') ; $fenetrePrincipale ->maxsize ( 390, 215 ) ; $fenetrePrincipale ->minsize ( 390, 215 ) ; $labServeur = $fenetrePrincipale -> Label ( -text =>'Adresse du serveur FTP :', -foreground => 'blue', ); $labServeur ->place ( -x => 10, -y => 30, ) ; $txtServeur = $fenetrePrincipale -> Entry ( -text => 'ftp.cpan.org', -width => 20 ); $txtServeur->place ( -x => 200, -y => 30, ) ; $labLogin = $fenetrePrincipale -> Label ( -text =>'Login :', -foreground => 'blue' ); $labLogin ->place ( -x => 10, -y => 60, ) ; $txtLogin = $fenetrePrincipale -> Entry ( -text => 'anonymous', -width => 20, ) ; $txtLogin ->place ( -x => 200, -y => 60, ) ; $labMDP = $fenetrePrincipale -> Label ( -text =>'Mot de passe :', -foreground => 'blue' ); $labMDP ->place ( -x => 10, -y => 90, ) ; $txtMDP = $fenetrePrincipale -> Entry ( -text => 'anonymous', -width => 20 ) ; $txtMDP -> place ( -x => 200, -y => 90, ) ; $labChemin = $fenetrePrincipale -> Label ( -text =>'Chemin complet du fihchier :', -foreground => 'blue' ); $labChemin ->place ( -x => 10, -y => 120, ) ; $txtChemin = $fenetrePrincipale -> Entry ( -text => '/pub/CPAN', -width => 20 ) ; $txtChemin -> place ( -x => 200, -y => 120, ) ; $labFichier = $fenetrePrincipale -> Label ( -text =>'Nom complet du fichier :', -foreground => 'blue' ); $labFichier ->place ( -x => 10, -y => 150, ) ; $txtFichier = $fenetrePrincipale -> Entry ( -text => 'README', -width => 20 ) ; $txtFichier -> place ( -x => 200, -y => 150, ) ; $cmdDownload = $fenetrePrincipale -> Button ( -text => 'Téléchargement' , -command => \&OuvrireConnection , -width =>20 ) ; $cmdDownload -> place ( -x => 0, -y => 192, ) ; $cmdAfficher = $fenetrePrincipale -> Button ( -text => 'AfficherFichier' , -command => \&AfficherFichier , -width =>20, ) ; $cmdAfficher -> place ( -x => 130, -y => 192, ) ; $cmdQuitter = $fenetrePrincipale -> Button ( -text => 'Quitter' , -command => \&Quitter , -width =>20 ) ; $cmdQuitter -> place ( -x => 260, -y => 192) ; } #Fonction Pour ouvrire la connection sur le serveur FTP sub OuvrireConnection { my $serveur = $txtServeur -> get () ; my $login = $txtLogin -> get () ; my $mdp = $txtMDP -> get () ; my $chemin = $txtChemin -> get () ; my $fichier = $txtFichier -> get () ; my $ftp = Net::FTP ->new ($serveur) ; $ftp->login ($login, $mdp) ; $ftp->cwd ($chemin) ; $ftp->get ($fichier) ; $ftp->quit ; my $boite_dialogue_Download = $fenetrePrincipale-> Dialog ( -title => 'Information' , -text => "Le fichier $fichier est bien telechargé, il se situe dans le repertoire du programme Client FTP !" , -bitmap => 'info' , -default_button => 'OK' , -buttons => [ 'OK' ] ) ; $boite_dialogue_Download -> Show ( ) ; } #Fonction pour Afficher le fichier sub AfficherFichier { $Bool = 0; $fenetreAffichage = new MainWindow () ; $fenetreAffichage -> title ('Affichage Document') ; $fenetreAffichage ->maxsize (1024, 768) ; $fenetreAffichage ->minsize (1024, 768) ; $fenetreAffichage->protocol('WM_DELETE_WINDOW' => \&Enregistrer); $txtAffichage = $fenetreAffichage -> Scrolled ('Text', -scrollbars => 'se', -width => 1024, -height => 768) ; $txtAffichage -> pack () ; $fichier = $txtFichier -> get ( ) ; open (LIRE, $fichier) ; while (<LIRE>) { $txtAffichage -> insert ( 'end', $_ ) ; }; close (LIRE); $tabAvant = $txtAffichage->get("1.0",'end'); } #Fonction Enregister sub Enregistrer { if ($Bool==0) { $Bool = 1; $tabApres = $txtAffichage->get("1.0",'end'); if ($tabAvant ne $tabApres) { my $boite_dialogue_Enregistrer = $fenetrePrincipale -> Dialog ( -title => 'Enregistrer' , -text => 'Voulez vous enregistrer vos modifications ?' , -bitmap => 'question' , -default_button => 'Oui' , -buttons => [ 'Oui' , 'Non' ] ) ; my $reponse = $boite_dialogue_Enregistrer -> Show ( ) ; if ( $reponse eq 'Oui' ) { open (ECRIRE, ">$fichier"); print ECRIRE $tabApres; close (ECRIRE); }; }; $fenetreAffichage->destroy; }; } #Fonction pour Quitter l'Applixcation sub Quitter { my $boite_dialogue_Quitter = $fenetrePrincipale -> Dialog ( -title => 'Quitter' , -text => 'Etes vous certain de vouloir quitter ?' , -bitmap => 'question' , -default_button => 'Oui' , -buttons => [ 'Oui' , 'Non' ] ) ; my $reponse = $boite_dialogue_Quitter -> Show ( ) ; if ( $reponse eq 'Oui' ) { exit(); }; }