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

PyQt Python Discussion :

Aide à finaliser mon script


Sujet :

PyQt Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Mars 2011
    Messages : 31
    Points : 11
    Points
    11
    Par défaut Aide à finaliser mon script
    Bonjour à tous.
    Pour commencer soyez indulgent je débute
    Je suis entrain de scripter un petit soft pour envoyer et recevoir des fichiers par FTP. Pour cela j'utilise NCFTP.

    L'interface je l'ai crée avec Designer.
    Voici mon code :
    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
    from PyQt4 import QtCore, QtGui
     
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        _fromUtf8 = lambda s: s
     
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName(_fromUtf8("Dialog"))
            Dialog.resize(432, 389)
            Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "FTP Gui", None, QtGui.QApplication.UnicodeUTF8))
            Dialog.setToolTip(_fromUtf8(""))
            self.buttonBox = QtGui.QDialogButtonBox(Dialog)
            self.buttonBox.setGeometry(QtCore.QRect(70, 350, 341, 32))
            self.buttonBox.setMouseTracking(True)
            self.buttonBox.setAcceptDrops(True)
            self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
            self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Ok)
            self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
            self.shell = QtGui.QTextEdit(Dialog)
            self.shell.setGeometry(QtCore.QRect(20, 210, 391, 131))
            self.shell.setMouseTracking(True)
            self.shell.setAutoFillBackground(False)
            self.shell.setFrameShape(QtGui.QFrame.WinPanel)
            self.shell.setFrameShadow(QtGui.QFrame.Sunken)
            self.shell.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
            self.shell.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
            self.shell.setAutoFormatting(QtGui.QTextEdit.AutoAll)
            self.shell.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextEditable|QtCore.Qt.TextEditorInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)
            self.shell.setObjectName(_fromUtf8("shell"))
            self.FTP = QtGui.QLineEdit(Dialog)
            self.FTP.setGeometry(QtCore.QRect(140, 10, 271, 20))
            self.FTP.setAutoFillBackground(False)
            self.FTP.setText(QtGui.QApplication.translate("Dialog", "192.168.1.1", None, QtGui.QApplication.UnicodeUTF8))
            self.FTP.setDragEnabled(True)
            self.FTP.setObjectName(_fromUtf8("FTP"))
            self.Login = QtGui.QLineEdit(Dialog)
            self.Login.setGeometry(QtCore.QRect(140, 40, 271, 20))
            self.Login.setText(QtGui.QApplication.translate("Dialog", "user", None, QtGui.QApplication.UnicodeUTF8))
            self.Login.setDragEnabled(True)
            self.Login.setObjectName(_fromUtf8("Login"))
            self.MdP = QtGui.QLineEdit(Dialog)
            self.MdP.setGeometry(QtCore.QRect(140, 70, 271, 20))
            self.MdP.setText(QtGui.QApplication.translate("Dialog", "password", None, QtGui.QApplication.UnicodeUTF8))
            self.MdP.setDragEnabled(True)
            self.MdP.setObjectName(_fromUtf8("MdP"))
            self.LocalFolder = QtGui.QLineEdit(Dialog)
            self.LocalFolder.setGeometry(QtCore.QRect(140, 100, 271, 20))
            self.LocalFolder.setText(QtGui.QApplication.translate("Dialog", "/test", None, QtGui.QApplication.UnicodeUTF8))
            self.LocalFolder.setDragEnabled(True)
            self.LocalFolder.setObjectName(_fromUtf8("LocalFolder"))
            self.RemoteFolder = QtGui.QLineEdit(Dialog)
            self.RemoteFolder.setGeometry(QtCore.QRect(140, 130, 271, 20))
            self.RemoteFolder.setText(QtGui.QApplication.translate("Dialog", "/", None, QtGui.QApplication.UnicodeUTF8))
            self.RemoteFolder.setDragEnabled(True)
            self.RemoteFolder.setObjectName(_fromUtf8("RemoteFolder"))
            self.LabelFTP = QtGui.QLabel(Dialog)
            self.LabelFTP.setGeometry(QtCore.QRect(20, 10, 81, 16))
            self.LabelFTP.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Adresse FTP</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelFTP.setObjectName(_fromUtf8("LabelFTP"))
            self.LabelLogin = QtGui.QLabel(Dialog)
            self.LabelLogin.setGeometry(QtCore.QRect(20, 40, 111, 16))
            self.LabelLogin.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Nom d\'utilisateur</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelLogin.setObjectName(_fromUtf8("LabelLogin"))
            self.LabelMdP = QtGui.QLabel(Dialog)
            self.LabelMdP.setGeometry(QtCore.QRect(20, 70, 101, 16))
            self.LabelMdP.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Mot de Passe</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelMdP.setObjectName(_fromUtf8("LabelMdP"))
            self.LabelLocalFolder = QtGui.QLabel(Dialog)
            self.LabelLocalFolder.setGeometry(QtCore.QRect(20, 100, 111, 16))
            self.LabelLocalFolder.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Répertoire Local</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelLocalFolder.setObjectName(_fromUtf8("LabelLocalFolder"))
            self.LabelRemoteFolder = QtGui.QLabel(Dialog)
            self.LabelRemoteFolder.setGeometry(QtCore.QRect(20, 130, 121, 16))
            self.LabelRemoteFolder.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Répertoire Distant</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelRemoteFolder.setObjectName(_fromUtf8("LabelRemoteFolder"))
            self.radioButtonUP = QtGui.QRadioButton(Dialog)
            self.radioButtonUP.setGeometry(QtCore.QRect(20, 170, 82, 17))
            font = QtGui.QFont()
            font.setBold(True)
            font.setWeight(75)
            self.radioButtonUP.setFont(font)
            self.radioButtonUP.setText(QtGui.QApplication.translate("Dialog", "Upload", None, QtGui.QApplication.UnicodeUTF8))
            self.radioButtonUP.setChecked(True)
            self.radioButtonUP.setObjectName(_fromUtf8("radioButtonUP"))
            self.radioButtonDown = QtGui.QRadioButton(Dialog)
            self.radioButtonDown.setGeometry(QtCore.QRect(90, 170, 82, 17))
            font = QtGui.QFont()
            font.setBold(True)
            font.setWeight(75)
            self.radioButtonDown.setFont(font)
            self.radioButtonDown.setText(QtGui.QApplication.translate("Dialog", "Download", None, QtGui.QApplication.UnicodeUTF8))
            self.radioButtonDown.setObjectName(_fromUtf8("radioButtonDown"))
            self.progressBar = QtGui.QProgressBar(Dialog)
            self.progressBar.setGeometry(QtCore.QRect(180, 170, 241, 23))
            font = QtGui.QFont()
            font.setBold(False)
            font.setWeight(50)
            self.progressBar.setFont(font)
            self.progressBar.setProperty("value", 0)
            self.progressBar.setObjectName(_fromUtf8("progressBar"))
            self.line = QtGui.QFrame(Dialog)
            self.line.setGeometry(QtCore.QRect(0, 150, 431, 20))
            self.line.setFrameShape(QtGui.QFrame.HLine)
            self.line.setFrameShadow(QtGui.QFrame.Sunken)
            self.line.setObjectName(_fromUtf8("line"))
     
            self.retranslateUi(Dialog)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.choice)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.close)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
     
        def retranslateUi(self, Dialog):
            pass
     
        def choice(self):
            print("choix de l envoi")
            print(Login)
            if self.radioButtonUP == True:
                self.ncftpup
            if self.radioButtonDown == True:
                self.ncftpdown
     
        def ncftpup(self):
            Login="user"      # avec ca ca marche
            MdP="password"
            FTP="192.168.1.1"
            RemoteFolder="/"
            LocalFolder="/test"
            args = ["C:\\windows\\ncftpput.exe","-u", Login,"-p", MdP,"-R","-z", FTP, RemoteFolder, LocalFolder]
            cmd = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)    
            status=cmd.wait()
            pyerr = cmd.stderr.readlines()
            pyout = cmd.stdout.readlines()
            print(pyerr)
            print(pyout)
     
        def ncftpdown(self):
            args = ["C:\\windows\\ncftpget.exe","-u", Login,"-p", MdP,"-R","-z", FTP, LocalFolder, RemoteFolder]
            cmd = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)   
            status=cmd.wait()
            pyerr = cmd.stderr.readlines()
            pyout = cmd.stdout.readlines()
            print(pyerr)
            print(pyout)
     
     
    if __name__ == "__main__":
        import os, sys, subprocess
        app = QtGui.QApplication(sys.argv)
        Dialog = QtGui.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        sys.exit(app.exec_())
    Plusieurs problèmes : Comment dire à subprocess d'utiliser les valeurs de connexion que je tape dans la fenêtre (ex: Nom d'utilisateur : user) car quand je le mets à la main ça fonctionne.

    Comment faire marcher les radiobuttons ainsi que la progressbar.

    Pouvez-vous me donner des pistes? C'est la première fois que j'utilise Qt. Ca à l'air compliquer mais que c'est pratique avec Designer pour faire de belles fenêtres.
    Mon objectif est de faire de simples scripts pour mon travail.

    Merci pour votre aide.

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Bonjour,

    1 Place cette ligne au tout début de ton script:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
        # -*- coding: utf-8 -*-
    2 Une bonne habitude à prendre, mettre les radioButton dans un groupe.
    Ici, tu n'en a que deux donc ca fonctionne, pour les utiliser, tu peux
    soit les connecter:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
        self.radioButtonUP.toggled.connect(self.maFonction)
    soit vérifier s'ils sont cochés
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
        if self.radioButtonUP.isChecked():
            ... action
    3 Pour les lineEdit, il suffit de les lire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
        ftp = unicode(self.FTP.text())
    4 Tes _fromUtf8 qui se balladent dans le code, je vois pas trop à quoi ils
    servent. Jamais utilisé.

    5 Tu peux aussi nettoyer ton code du Html en utilisant simplement une
    définition de fonte comme pour les radioButton.

    6 Pour les subprocess je ne vois rien d'anormal, il faudrait tester, je
    suppose que tu l'as fait, tu as eu des retours d'erreurs ?

    7 La progressBar s'utilise avec setValue(int) mais c'est toi qui, dans ton code, dois calculer le pourcentage de transfert. Si tu connais la taille totale, c'est faisable, sinon faut bricoler.

  3. #3
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Je ne l'avais pas vu, mais il faut mettre des parenthèses à tes appels de fonctions, je suppose que c'est un oubli.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
        def choice(self):
            print("choix de l envoi")
            print(Login)  # ! Login n'existe pas dans l'espace de nom de cette fonction !
            if self.radioButtonUP.isChecked():
                self.ncftpup()
            else:
                self.ncftpdown()

  4. #4
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 690
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 690
    Points : 30 986
    Points
    30 986
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par VinsS Voir le message
    4 Tes _fromUtf8 qui se balladent dans le code, je vois pas trop à quoi ils
    servent. Jamais utilisé.
    Salut

    Il l'a défini comme un raccourci de QString.fromUtf8(). Ca sert à rendre un texte utf8 (surtout s'il y a des accents) correctement écrit dans un objet Qt
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

  5. #5
    Rédacteur/Modérateur

    Avatar de Jiyuu
    Homme Profil pro
    Développeur amateur
    Inscrit en
    Janvier 2007
    Messages
    2 456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur amateur
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 2 456
    Points : 6 789
    Points
    6 789
    Billets dans le blog
    15
    Par défaut
    Petite remarque... à mon avis modifier le code issu de QtDesigner n'est pas une très bonne idée. Lorsque tu vas regénérer ce code via pyuic, tu risques fort d'avoir une mauvaise surprise.

    À mon avis, il serait déjà bien de jeter un coup d'oeil à mon article traitant de QtDesigner et Eric.

    Pour les applications devant travailler avec un serveur ftp, tu as aussi QFtp de pas mal. Tu peux lire ce topic pour te faire une petite idée de la chose.

    Bonne continuation
    Initiation à Qt Quick et QML : Partie 1 - Partie 2
    En cas de besoin, pensez à la
    Mon site et mes tutoriaux sur Developpez.com
    Pas de question technique par MP... Les forums sont là pour ça

  6. #6
    Membre à l'essai
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Mars 2011
    Messages : 31
    Points : 11
    Points
    11
    Par défaut
    Allo,

    Merci merci pour toutes ces réponses vous êtes bien gentils.

    Je vais me mettre à la tâche pour améliorer mon script.
    Je vais vous revenir bientôt avec mes résultats.

    A plus.

  7. #7
    Membre à l'essai
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Mars 2011
    Messages : 31
    Points : 11
    Points
    11
    Par défaut
    Bonjour Messieurs,

    Merci pour vos trucs ça m'a permis d'avancer dans mon script.

    Voici mon nouveau code :
    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
    # -*- coding: utf-8 -*-
     
    from PyQt4 import QtCore, QtGui
     
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        _fromUtf8 = lambda s: s
     
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName(_fromUtf8("Dialog"))
            Dialog.resize(432, 389)
            Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "FTP Gui", None, QtGui.QApplication.UnicodeUTF8))
            Dialog.setToolTip(_fromUtf8(""))
            self.buttonBox = QtGui.QDialogButtonBox(Dialog)
            self.buttonBox.setGeometry(QtCore.QRect(70, 350, 341, 32))
            self.buttonBox.setMouseTracking(True)
            self.buttonBox.setAcceptDrops(True)
            self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
            self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Ok)
            self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
            self.shell = QtGui.QTextEdit(Dialog)
            self.shell.setGeometry(QtCore.QRect(20, 210, 391, 131))
            self.shell.setMouseTracking(True)
            self.shell.setAutoFillBackground(False)
            self.shell.setFrameShape(QtGui.QFrame.WinPanel)
            self.shell.setFrameShadow(QtGui.QFrame.Sunken)
            self.shell.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
            self.shell.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
            self.shell.setAutoFormatting(QtGui.QTextEdit.AutoAll)
            self.shell.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextEditable|QtCore.Qt.TextEditorInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)
            self.shell.setObjectName(_fromUtf8("shell"))
            self.FTP = QtGui.QLineEdit(Dialog)
            self.FTP.setGeometry(QtCore.QRect(140, 10, 271, 20))
            self.FTP.setAutoFillBackground(False)
            self.FTP.setText(QtGui.QApplication.translate("Dialog", "192.168.1.1", None, QtGui.QApplication.UnicodeUTF8))
            self.FTP.setDragEnabled(True)
            self.FTP.setObjectName(_fromUtf8("FTP"))
            self.Login = QtGui.QLineEdit(Dialog)
            self.Login.setGeometry(QtCore.QRect(140, 40, 271, 20))
            self.Login.setText(QtGui.QApplication.translate("Dialog", "user", None, QtGui.QApplication.UnicodeUTF8))
            self.Login.setDragEnabled(True)
            self.Login.setObjectName(_fromUtf8("Login"))
            self.MdP = QtGui.QLineEdit(Dialog)
            self.MdP.setGeometry(QtCore.QRect(140, 70, 271, 20))
            self.MdP.setText(QtGui.QApplication.translate("Dialog", "password", None, QtGui.QApplication.UnicodeUTF8))
            self.MdP.setDragEnabled(True)
            self.MdP.setObjectName(_fromUtf8("MdP"))
            self.LocalFolder = QtGui.QLineEdit(Dialog)
            self.LocalFolder.setGeometry(QtCore.QRect(140, 100, 271, 20))
            self.LocalFolder.setText(QtGui.QApplication.translate("Dialog", "/test", None, QtGui.QApplication.UnicodeUTF8))
            self.LocalFolder.setDragEnabled(True)
            self.LocalFolder.setObjectName(_fromUtf8("LocalFolder"))
            self.RemoteFolder = QtGui.QLineEdit(Dialog)
            self.RemoteFolder.setGeometry(QtCore.QRect(140, 130, 271, 20))
            self.RemoteFolder.setText(QtGui.QApplication.translate("Dialog", "/", None, QtGui.QApplication.UnicodeUTF8))
            self.RemoteFolder.setDragEnabled(True)
            self.RemoteFolder.setObjectName(_fromUtf8("RemoteFolder"))
            self.LabelFTP = QtGui.QLabel(Dialog)
            self.LabelFTP.setGeometry(QtCore.QRect(20, 10, 81, 16))
            self.LabelFTP.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Adresse FTP</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelFTP.setObjectName(_fromUtf8("LabelFTP"))
            self.LabelLogin = QtGui.QLabel(Dialog)
            self.LabelLogin.setGeometry(QtCore.QRect(20, 40, 111, 16))
            self.LabelLogin.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Nom d\'utilisateur</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelLogin.setObjectName(_fromUtf8("LabelLogin"))
            self.LabelMdP = QtGui.QLabel(Dialog)
            self.LabelMdP.setGeometry(QtCore.QRect(20, 70, 101, 16))
            self.LabelMdP.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Mot de Passe</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelMdP.setObjectName(_fromUtf8("LabelMdP"))
            self.LabelLocalFolder = QtGui.QLabel(Dialog)
            self.LabelLocalFolder.setGeometry(QtCore.QRect(20, 100, 111, 16))
            self.LabelLocalFolder.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Répertoire Local</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelLocalFolder.setObjectName(_fromUtf8("LabelLocalFolder"))
            self.LabelRemoteFolder = QtGui.QLabel(Dialog)
            self.LabelRemoteFolder.setGeometry(QtCore.QRect(20, 130, 121, 16))
            self.LabelRemoteFolder.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Répertoire Distant</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelRemoteFolder.setObjectName(_fromUtf8("LabelRemoteFolder"))
            self.radioButtonUP = QtGui.QRadioButton(Dialog)
            self.radioButtonUP.setGeometry(QtCore.QRect(20, 170, 82, 17))
            font = QtGui.QFont()
            font.setBold(True)
            font.setWeight(75)
            self.radioButtonUP.setFont(font)
            self.radioButtonUP.setText(QtGui.QApplication.translate("Dialog", "Upload", None, QtGui.QApplication.UnicodeUTF8))
            self.radioButtonUP.setChecked(True)
            self.radioButtonUP.setObjectName(_fromUtf8("radioButtonUP"))
            self.radioButtonDown = QtGui.QRadioButton(Dialog)
            self.radioButtonDown.setGeometry(QtCore.QRect(90, 170, 82, 17))
            font = QtGui.QFont()
            font.setBold(True)
            font.setWeight(75)
            self.radioButtonDown.setFont(font)
            self.radioButtonDown.setText(QtGui.QApplication.translate("Dialog", "Download", None, QtGui.QApplication.UnicodeUTF8))
            self.radioButtonDown.setObjectName(_fromUtf8("radioButtonDown"))
            self.progressBar = QtGui.QProgressBar(Dialog)
            self.progressBar.setGeometry(QtCore.QRect(180, 170, 241, 23))
            font = QtGui.QFont()
            font.setBold(False)
            font.setWeight(50)
            self.progressBar.setFont(font)
            self.progressBar.setProperty("value", 0)
            self.progressBar.setObjectName(_fromUtf8("progressBar"))
            self.line = QtGui.QFrame(Dialog)
            self.line.setGeometry(QtCore.QRect(0, 150, 431, 20))
            self.line.setFrameShape(QtGui.QFrame.HLine)
            self.line.setFrameShadow(QtGui.QFrame.Sunken)
            self.line.setObjectName(_fromUtf8("line"))
     
            self.retranslateUi(Dialog)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.choice)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.close)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
     
        def retranslateUi(self, Dialog):
            pass
     
        def choice(self):
            if self.radioButtonUP.isChecked():
                self.ncftpup()
            if self.radioButtonDown.isChecked():
                self.ncftpdown()
     
        def ncftpup(self):
            Login = self.Login.text()
            MdP = self.MdP.text()
            FTP = self.FTP.text()
            RemoteFolder = self.RemoteFolder.text()
            LocalFolder = self.LocalFolder.text()
            args = ["C:\\windows\\ncftpput.exe","-u", Login,"-p", MdP,"-R","-z", FTP, RemoteFolder, LocalFolder]
            cmd = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)   
            status=cmd.wait()
            pyerr = cmd.stderr.readlines()
            pyout = cmd.stdout.readlines()
            print(pyerr)
            print(pyout)
            self.step = 0
            self.step += 100
            self.progressBar.setValue(self.step)
     
        def ncftpdown(self):
            Login = self.Login.text()
            MdP = self.MdP.text()
            FTP = self.FTP.text()
            RemoteFolder = self.RemoteFolder.text()
            LocalFolder = self.LocalFolder.text()
            args = ["C:\\windows\\ncftpget.exe","-u", Login,"-p", MdP,"-R","-z", FTP, LocalFolder, RemoteFolder]
            cmd = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)    
            status=cmd.wait()
            pyerr = cmd.stderr.readlines()
            pyout = cmd.stdout.readlines()
     
     
    if __name__ == "__main__":
        import os, sys, subprocess
        app = QtGui.QApplication(sys.argv)
        Dialog = QtGui.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        sys.exit(app.exec_())
    J'ai ajouté la partie ProgressBar mais à part la faire progresser de 0 à 100 d'un coup j'ai pas trouvé comment faire pour qu'elle s'ajuste avec l'upload ou download.
    J'aimerais aussi savoir comment je peux écrire le résultat de la commande ncftp (erreur etc..) ainsi qu'un texte qui me dit "Opération réussie" dans mon widget Shell.

    Merci de votre aide précieuse.

    Bonne journée

  8. #8
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 690
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 690
    Points : 30 986
    Points
    30 986
    Billets dans le blog
    1
    Par défaut
    Ok, allons-y pour les critiques
    1) tes libellés "Répertoire Local" apparaissent mal (au niveau des "é"). Il faut que tu passes ta chaine via QString.fromUtf8(). En revanche, passer les noms de tes objets (setObjectName) au travers de cette fonction est peu utile. Les noms des objets ne servent que si tu as envie de savoir qui appelle qui de façon plus sympa.

    2) ton champ de saisie mot de passe reste visible. Va regarder du coté de la methode setEchoMode() pour arranger cela.

    3) quand tu récupères le login via text(), tu récupères un QString. Or la commande Popen() en ligne 152 attend une string Python et non une string Qt et ça plante.

    Solution la moins compliquée: remplacer subprocess.Popen(args, ... par subprocess.Popen("%s" % args, .... Python adaptera lui-même via "%s" la QString en string.

    Solution la plus propre: récupérer text().toAscii().data() => tu récupères alors une vraie string python.

    Concernant la progress bar, son principe est le suivant
    Tu découpes une tâche complexe en n tâches plus simples
    Chaque fois qu'une tâche plus simple est terminée, tu indiques à la progress bar de se mettre à jour via setValue() en lui indiquant le nombre d'opérations effectuées et le nombre max d'opérations prévues. Là, la barre s'affichera alors comme il faut
    Donc ton vrai problème est d'arriver à détecter combien d'octets ont été transférés et combien tu en attends. Mais là, faut voir du coté de ton ftp. Et peut-être, au lieu de passer par popen() pour lancer un programme externe "ncftpget", voir si tu n'aurais pas des librairies Python dédiées au ftp. Vu le nombre de librairies qu'il y a, ça m'étonnerait qu'il n'y en ait pas une pour ça. Peut-être même que Qt en possède une (mais perso j'aime pas mélanger les outils et pour moi Qt sert à l'IHM et pas au travail de fond qui est dévolu au contrôleur comme le prévoir l'architecture MVC)

    Concernant l'écriture dans ta variable "shell" qui est un QTextEdit(), te suffit de faire shell.setText(_fromUft8("blablabla"))
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

  9. #9
    Rédacteur/Modérateur

    Avatar de Jiyuu
    Homme Profil pro
    Développeur amateur
    Inscrit en
    Janvier 2007
    Messages
    2 456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur amateur
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 2 456
    Points : 6 789
    Points
    6 789
    Billets dans le blog
    15
    Par défaut
    Je vais sûrement passer pour le lourding qui insiste, mais bon...

    Ne modifie pas le code généré par pyuic. Dès que tu vas modifier ton HMI et que tu vas relancer cette commande, tu perdras toutes tes modifs.

    Au risque de me répéter, lis les deux liens que je t'ai donnés précédemment.

    Tu y trouveras des réponses simples à tes questions.

    Rapidement :
    1°) Contrairement à ce que dit Sve@r, je pense que setObjectName reste utile. Ceci te permet d'appeler un slot uniquement via le nom du widget qui doit le lancer.
    2°) Qt permet de faire plein de choses jolies coté HMI, mais il permet aussi de faire d'autres choses (XML, Ftp, ...) et contrairement à Sve@r (encore ), moi je conseille de l'utiliser dès que c'est possible plutôt que d'avoir un nombre indéfini de petites librairies. Pour ton besoin de progressBar, voila ce que Qt propose en Ftp http://qt.developpez.com/doc/4.7/QFt...ansferprogress
    Initiation à Qt Quick et QML : Partie 1 - Partie 2
    En cas de besoin, pensez à la
    Mon site et mes tutoriaux sur Developpez.com
    Pas de question technique par MP... Les forums sont là pour ça

  10. #10
    Membre à l'essai
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Mars 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Mars 2011
    Messages : 31
    Points : 11
    Points
    11
    Par défaut
    Bonjour à vous,

    Merci pour les réponses.
    Ok j'ai décidé de changer ncftp par la classe QFtp.

    Voici mon code :

    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
    # -*- coding: utf-8 -*-
     
    from PyQt4 import QtCore, QtGui, QtNetwork
     
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        _fromUtf8 = lambda s: s
     
    etat = {0:"Aucune connexion", 1:"Resolution du nom en cours", 2:"Tentative de connexion en cours",
    3:"Connexion etablie", 4:"Identification etablie", 5:"Deconnexion en cours"} 
     
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName(_fromUtf8("Dialog"))
            Dialog.resize(432, 389)
            Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "FTP Gui", None, QtGui.QApplication.UnicodeUTF8))
            Dialog.setToolTip(_fromUtf8(""))
            self.buttonBox = QtGui.QDialogButtonBox(Dialog)
            self.buttonBox.setGeometry(QtCore.QRect(70, 350, 341, 32))
            self.buttonBox.setMouseTracking(True)
            self.buttonBox.setAcceptDrops(True)
            self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
            self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Ok)
            self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
            self.shell = QtGui.QTextEdit(Dialog)
            self.shell.setGeometry(QtCore.QRect(20, 210, 391, 131))
            self.shell.setMouseTracking(True)
            self.shell.setAutoFillBackground(False)
            self.shell.setFrameShape(QtGui.QFrame.WinPanel)
            self.shell.setFrameShadow(QtGui.QFrame.Sunken)
            self.shell.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
            self.shell.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
            self.shell.setAutoFormatting(QtGui.QTextEdit.AutoAll)
            self.shell.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextEditable|QtCore.Qt.TextEditorInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)
            self.shell.setObjectName(_fromUtf8("shell"))
            self.FTP = QtGui.QLineEdit(Dialog)
            self.FTP.setGeometry(QtCore.QRect(140, 10, 271, 20))
            self.FTP.setAutoFillBackground(False)
            self.FTP.setText(QtGui.QApplication.translate("Dialog", "192.168.1.1", None, QtGui.QApplication.UnicodeUTF8))
            self.FTP.setDragEnabled(True)
            self.FTP.setObjectName(_fromUtf8("FTP"))
            self.Login = QtGui.QLineEdit(Dialog)
            self.Login.setGeometry(QtCore.QRect(140, 40, 271, 20))
            self.Login.setText(QtGui.QApplication.translate("Dialog", "login", None, QtGui.QApplication.UnicodeUTF8))
            self.Login.setDragEnabled(True)
            self.Login.setObjectName(_fromUtf8("Login"))
            self.MdP = QtGui.QLineEdit(Dialog)
            self.MdP.setGeometry(QtCore.QRect(140, 70, 271, 20))
            self.MdP.setText(QtGui.QApplication.translate("Dialog", "password", None, QtGui.QApplication.UnicodeUTF8))
            self.MdP.setDragEnabled(True)
            self.MdP.setObjectName(_fromUtf8("MdP"))
            self.LocalFolder = QtGui.QLineEdit(Dialog)
            self.LocalFolder.setGeometry(QtCore.QRect(140, 100, 271, 20))
            self.LocalFolder.setText(QtGui.QApplication.translate("Dialog", "/test", None, QtGui.QApplication.UnicodeUTF8))
            self.LocalFolder.setDragEnabled(True)
            self.LocalFolder.setObjectName(_fromUtf8("LocalFolder"))
            self.RemoteFolder = QtGui.QLineEdit(Dialog)
            self.RemoteFolder.setGeometry(QtCore.QRect(140, 130, 271, 20))
            self.RemoteFolder.setText(QtGui.QApplication.translate("Dialog", "/", None, QtGui.QApplication.UnicodeUTF8))
            self.RemoteFolder.setDragEnabled(True)
            self.RemoteFolder.setObjectName(_fromUtf8("RemoteFolder"))
            self.LabelFTP = QtGui.QLabel(Dialog)
            self.LabelFTP.setGeometry(QtCore.QRect(20, 10, 81, 16))
            self.LabelFTP.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Adresse FTP</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelFTP.setObjectName(_fromUtf8("LabelFTP"))
            self.LabelLogin = QtGui.QLabel(Dialog)
            self.LabelLogin.setGeometry(QtCore.QRect(20, 40, 111, 16))
            self.LabelLogin.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Nom d\'utilisateur</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelLogin.setObjectName(_fromUtf8("LabelLogin"))
            self.LabelMdP = QtGui.QLabel(Dialog)
            self.LabelMdP.setGeometry(QtCore.QRect(20, 70, 101, 16))
            self.LabelMdP.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Mot de Passe</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelMdP.setObjectName(_fromUtf8("LabelMdP"))
            self.LabelLocalFolder = QtGui.QLabel(Dialog)
            self.LabelLocalFolder.setGeometry(QtCore.QRect(20, 100, 111, 16))
            self.LabelLocalFolder.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Répertoire Local</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelLocalFolder.setObjectName(_fromUtf8("LabelLocalFolder"))
            self.LabelRemoteFolder = QtGui.QLabel(Dialog)
            self.LabelRemoteFolder.setGeometry(QtCore.QRect(20, 130, 121, 16))
            self.LabelRemoteFolder.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt; font-weight:600;\">Répertoire Distant</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            self.LabelRemoteFolder.setObjectName(_fromUtf8("LabelRemoteFolder"))
            self.radioButtonUP = QtGui.QRadioButton(Dialog)
            self.radioButtonUP.setGeometry(QtCore.QRect(20, 170, 82, 17))
            font = QtGui.QFont()
            font.setBold(True)
            font.setWeight(75)
            self.radioButtonUP.setFont(font)
            self.radioButtonUP.setText(QtGui.QApplication.translate("Dialog", "Upload", None, QtGui.QApplication.UnicodeUTF8))
            self.radioButtonUP.setChecked(True)
            self.radioButtonUP.setObjectName(_fromUtf8("radioButtonUP"))
            self.radioButtonDown = QtGui.QRadioButton(Dialog)
            self.radioButtonDown.setGeometry(QtCore.QRect(90, 170, 82, 17))
            font = QtGui.QFont()
            font.setBold(True)
            font.setWeight(75)
            self.radioButtonDown.setFont(font)
            self.radioButtonDown.setText(QtGui.QApplication.translate("Dialog", "Download", None, QtGui.QApplication.UnicodeUTF8))
            self.radioButtonDown.setObjectName(_fromUtf8("radioButtonDown"))
            self.progressBar = QtGui.QProgressBar(Dialog)
            self.progressBar.setGeometry(QtCore.QRect(180, 170, 241, 23))
            font = QtGui.QFont()
            font.setBold(False)
            font.setWeight(50)
            self.progressBar.setFont(font)
            self.progressBar.setProperty("value", 0)
            self.progressBar.setObjectName(_fromUtf8("progressBar"))
            self.line = QtGui.QFrame(Dialog)
            self.line.setGeometry(QtCore.QRect(0, 150, 431, 20))
            self.line.setFrameShape(QtGui.QFrame.HLine)
            self.line.setFrameShadow(QtGui.QFrame.Sunken)
            self.line.setObjectName(_fromUtf8("line"))
     
            self.retranslateUi(Dialog)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.choice)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.close)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
     
            self.ftp = QtNetwork.QFtp(Dialog)
            self.ftp.stateChanged.connect(self.stateServer)
            self.ftp.dataTransferProgress.connect(self.test)
     
        def retranslateUi(self, Dialog):
            pass
     
        def choice(self):
            if self.radioButtonUP.isChecked():
                self.connect()
                self.upload()
            if self.radioButtonDown.isChecked():
                self.connect()
                self.download()
     
        def test(self, done, tot):
            #self.progressBar.setValue(self.step)
            print ('Chargement : %s sur %s' % (done, tot))
     
        def stateServer(self):
            self.shell.setText(etat[self.ftp.state()])
            #print (etat[self.ftp.state()])
            #print()
     
        def connect(self):
            Login = self.Login.text()
            MdP = self.MdP.text()
            FTP = self.FTP.text()
            RemoteFolder = self.RemoteFolder.text()
            LocalFolder = self.LocalFolder.text()
            port = 21
            if self.ftp.state() != 0:
                self.shell.setText("Serveur en cours de connexion ou connecte")
            else:        
                self.shell.setText("Debut de connexion")
                self.ftp.connectToHost(FTP, port)
                self.ftp.login(Login, MdP)
     
        def deconnect(self):
            if self.ftp.state() == 0:
                self.shell.setText("Serveur non connecte")
            else:
                self.ftp.close()
     
        def upload(self):
            file = QtCore.QFile("toto1.txt")
            file.open(QtCore.QIODevice.ReadOnly)
            self.ftp.put(file.readAll(), "toto1_depuis_local.txt")
            self.ftp.errorString ()
            self.shell.setText("Upload Terminé")
     
        def download(self):
            fileServer = "toto.txt"
            self.reply = self.ftp.get(fileServer)
            self.ftp.readyRead.connect(self.readyRead)
            self.ftp.errorString ()
            self.shell.setText("Download Terminé")
     
     
    if __name__ == "__main__":
        import os, sys, subprocess
        app = QtGui.QApplication(sys.argv)
        Dialog = QtGui.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        sys.exit(app.exec_())
    Voici mes questions :
    - Comment afficher les résultats des commandes dans ma fenêtre Shell un en-dessous de l'autre. Bref utiliser cette fenêtre pour tout indiquer du processus de connexion au transfert et la déconnexion.
    - Je veux envoyer et recevoir des répertoires complets et non des fichiers. J'ai vu QDir mais je sais pas si c'est bon pour ça.
    - et encore la progress bar j'y comprends pas grand chose.

    Merci à vous

  11. #11
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 690
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 690
    Points : 30 986
    Points
    30 986
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par tbr67fr Voir le message
    - Comment afficher les résultats des commandes dans ma fenêtre Shell un en-dessous de l'autre. Bref utiliser cette fenêtre pour tout indiquer du processus de connexion au transfert et la déconnexion.
    Ben je te l'ai dit. Ta fenêtre c'est un QTextEdit(). Donc tu peux lui écrire du texte via insertPlainText().
    Donc quand tu effectues une action importante tu rajoutes ensuite l'écriture dans ton QTextEdit() !!!!

    Citation Envoyé par tbr67fr Voir le message
    - Je veux envoyer et recevoir des répertoires complets et non des fichiers. J'ai vu QDir mais je sais pas si c'est bon pour ça.
    Le protocole ftp n'est conçu que pour des fichiers. Mais il sait créer des répertoires vides.
    Donc envoyer un répertoire se décomposera en
    créer le répertoire à l'autre bout
    ouvrir le répertoire à envoyer
    pour chaque élément du répertoire
    faire:
    si élément est répertoire alors:
    appeler fonction en récursif
    sinon:
    envoyer fichier
    fin si
    fin faire
    fermer répertoire
    Et QDir est un outil qui te permet de lire le contenu d'un répertoire...

    Citation Envoyé par tbr67fr Voir le message
    - et encore la progress bar j'y comprends pas grand chose.
    Code python : 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
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
     
    import sys
    try:
    	from PyQt4.QtCore import *				# Moteur contrôle Qt
    	from PyQt4.QtGui import *				# IHM Qt
    except:
    	import time								# Gestion heures système
    	for i in range(10):
    		print "PyQt non installé - A vérifier (%d/10)" % (i + 1)
    	time.sleep(5)
    	sys.exit(1)
    # try
     
    class QtAppli(
    		QApplication):						# Objet hérité
    	"Fenêtre de l'application"
     
    	# Constructeur fenêtre
    	def __init__(
    			self,							# Instance objet
    			argv,							# Arguments programme
    			transFile=None):				# Fichier de traduction
     
    		# Message de contrôle
    		print "Python version %s - QtAppli (qt v%s, pyqt_v%s)" % (
    			sys.version,
    			QT_VERSION_STR,
    			PYQT_VERSION_STR
    		)
     
    		# Appel constructeur de l'objet hértié
    		QApplication.__init__(self, argv)
     
    		# Translations
    		if transFile != None:
    			self.__trans=QTranslator()
    			self.installTranslator(self.__trans)
    			self.__trans.load(transFile)
    		#if
     
    		# Widget principale
    		self.mainWid=QMainWindow()
    		self.mainWid.setCentralWidget(QWidget(self.mainWid))
    		self.mainWid.statusBar()
     
    		# Titre
    		self.mainWid.setWindowTitle(
    			QApplication.translate(
    				"VerifQt",
    				"Exemple Qt (v%1)",
    				"Note: titre de la fenêtre",
    				QApplication.UnicodeUTF8,
    			).arg(QString.fromUtf8(QT_VERSION_STR))
    		)
     
    		# Les boutons + et -
    		self.__plus=QPushButton(
    			QApplication.translate(
    				"VerifQt",
    				"+",
    				"Note: titre du bouton",
    				QApplication.UnicodeUTF8,
    			),
    			self.mainWid.centralWidget()
    		)
    		self.connect(
    			self.__plus,
    			SIGNAL("clicked()"),
    			self.__slotPlus,
    		)
    		self.__moins=QPushButton(
    			QApplication.translate(
    				"VerifQt",
    				"-",
    				"Note: titre du bouton",
    				QApplication.UnicodeUTF8,
    			),
    			self.mainWid.centralWidget()
    		)
    		self.connect(
    			self.__moins,
    			SIGNAL("clicked()"),
    			self.__slotMoins,
    		)
     
    		# Le bouton version
    		ver=QPushButton(
    			QApplication.translate(
    				"VerifQt",
    				"A propos de Qt",
    				"Note: titre du bouton",
    				QApplication.UnicodeUTF8,
    			)
    		)
    		self.connect(
    			ver,
    			SIGNAL("clicked()"),
    			self.__slotQt,
    		)
     
    		# Pour quitter
    		quit=QPushButton(
    			QApplication.translate(
    				"VerifQt",
    				"Quitter",
    				"Note: titre du bouton",
    				QApplication.UnicodeUTF8,
    			)
    		)
    		self.connect(
    			quit,
    			SIGNAL("clicked()"),
    			self.mainWid,
    			SLOT("close()"),
    		)
     
    		# La progressbar
    		self.__progress=QProgressBar()
    		self.__progress.setMinimum(0)
    		self.__progress.setMaximum(30)
    		self.__checkButton()
     
    		# Rangement des éléments
    		mainLayout=QGridLayout(self.mainWid.centralWidget())
    		mainLayout.addWidget(self.__plus, 0, 0)
    		mainLayout.addWidget(self.__moins, 0, 1)
    		mainLayout.addWidget(self.__progress, 1, 0, 1, 2)
    		mainLayout.addWidget(ver, 2, 0, 1, 2)
    		mainLayout.addWidget(quit, 3, 0, 1, 2)
    	# __init__()
     
    	# Affichage et lancement application
    	def run(
    			self):							# Instance objet
    		self.mainWid.show()
    		self.exec_()
    	# run()
     
    	# Activation/Désactivation des boutons selon l'état de la barre
    	def __checkButton(
    			self):							# Instance objet
     
    		# Le bouton "-" est activé/désactivé selon la valeur de la barre par rapport à son minimum
    		self.__moins.setEnabled(self.__progress.value() > self.__progress.minimum())
     
    		# Le bouton "+" est activé/désactivé selon la valeur de la barre par rapport à son maximum
    		self.__plus.setEnabled(self.__progress.value() < self.__progress.maximum())
    	# __checkButton()
     
    	# Slot qui incrémente la progressbar
    	def __slotPlus(
    			self):							# Instance objet
     
    		print "%s.__slotPlus" % self.__class__.__name__
     
    		self.__progress.setValue(self.__progress.value() + 1)
    		self.__checkButton()
    	# __slotPlus()
     
    	# Slot qui décrémente la progressbar
    	def __slotMoins(
    			self):							# Instance objet
     
    		print "%s.__slotMoins" % self.__class__.__name__
     
    		self.__progress.setValue(self.__progress.value() - 1)
    		self.__checkButton()
    	# __slotMoins()
     
    	# Slot qui affiche la version de Qt
    	def __slotQt(
    			self):							# Instance objet
     
    		print "%s.__slotQt" % self.__class__.__name__
     
    		# Fenêtre "A propos de Qt"
    		QMessageBox.aboutQt(
    			self.mainWid,
    			QApplication.translate(
    				"VerifQt",
    				"à propos de Qt...",
    				"Note: titre de la fenêtre",
    				QApplication.UnicodeUTF8,
    			),
    		)
    	# __slotQt()
    # class QtAppli
     
    if __name__ == "__main__":
    	# Lancement appli
    	Appli=QtAppli(sys.argv, "verifqt_en")
    	Appli.run()
    # if
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

Discussions similaires

  1. Aide sur mon script
    Par naniccino dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 13
    Dernier message: 29/01/2015, 11h37
  2. Besoin d'aide pour mon script sur les listes chainées
    Par narama87 dans le forum Débuter
    Réponses: 1
    Dernier message: 13/01/2011, 12h29
  3. Aide pour mon premier script sous linux
    Par bomonde dans le forum Shell et commandes GNU
    Réponses: 1
    Dernier message: 21/10/2010, 13h27
  4. [AJAX] Finalisation de mon site
    Par belvina dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 25/01/2006, 01h54

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