|
|
|
|
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!!!
Configuration: Windows Vista Firefox 2.0.0.11
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!!!:
|
Apperement ça appel la même procédure!!!
|
Voial l'erreur qu'il me retourne :
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!!! :
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é :)
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();
};
} |