Bonjour à tous,

Voici un extrait de 3 fichiers .py


Code Ui_article.py : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
from PyQt4 import QtCore, QtGui
 
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(877, 590)
        Form.setMaximumSize(QtCore.QSize(900, 590))
        font = QtGui.QFont()
        font.setPointSize(7)
        Form.setFont(font)
        self.lineEdit = QtGui.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(360, 4, 191, 29))

Code Main.py : 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
 
from PyQt4 import QtCore, QtGui
from Ui_article import Ui_Form
import sys
from article import Slot_Article
 
class Frame(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)    
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        QtCore.QObject.connect(self.ui.pushButton,QtCore.SIGNAL('clicked()'), self.action)
 
    def action(self):
        Slot_Article().on_pushButton_clicked(self.ui)
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = Frame()
    myapp.show()
    sys.exit(app.exec_())

Code article.py : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import pyqtSignature
 
from Ui_article import Ui_Form
 
class Slot_Article(QMainWindow, Ui_Form):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
 
    @pyqtSignature("")
    def on_pushButton_clicked(self,  myparent):
        txt = myparent.lineEdit.text()
        print txt

L'inter-action entre ces codes fonctionne correctement.
Cela dit, afin de simplifier un peu ceux-ci, j'aimerai ne pas avoir à passer l'argument "self.ui" dans Main.py.
J'ai essayé les deux versions différentes de article.py

Code article.py nouvelle version 1 : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import pyqtSignature
 
from Ui_article import Ui_Form
 
class Slot_Article(QMainWindow, Ui_Form):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
 
    @pyqtSignature("")
    def on_pushButton_clicked(self):
        txt = Ui_Form().lineEdit.text()
        print txt
Là j'ai une erreur qui me dit que Ui_Form n'a pas d'objet lineEdit.

Code article.py nouvelle version 2 : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import pyqtSignature
 
from Ui_article import Ui_Form
 
class Slot_Article(QMainWindow, Ui_Form):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
 
    @pyqtSignature("")
    def on_pushButton_clicked(self):
        txt = self.lineEdit.text()
        print txt
Là aucune erreur ne se produit, mais par contre la valeur retournée de lineEdit reste, même après changement, celle initialement présente au démarrage du programme.

Quelqu'un verrait-il une raison du pourquoi???

D'avance merci