Bonjour,
Je travaille avec Python 3.5 et PyQt5 et je rencontre un souci avec le code suivant :
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 | # main.py from .ui.main_window import Ui_main_window from . import create_project class MainWindow(QtWidgets.QMainWindow, Ui_main_window): def __init__(self, parent=None): self.init_create_project_widget() self.setCentralWidget(self.create_project_widget) def display_message(self, txt): widget = messages.MessageWidget(txt) self.setCentralWidget(widget) def create_project_success(self, slug): print("success") def create_project_error(self, msg): print("error") def init_create_project_widget(self): self.create_project_widget = create_project.Widget() self.create_project_widget.created.connect(self.create_project_success) self.create_project_widget.creating.connect(lambda: self.display_message( "Création de l'étude en cours..." )) self.create_project_widget.aborted.connect(self.create_project_error) |
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 | # create_project.py class Thread(QtCore.QThread): error = QtCore.pyqtSignal(str) finished = QtCore.pyqtSignal(str) def __init__(self, url): super(Thread, self).__init__() self.url = url def __del__(self): self.wait() def run(self): # ... if cond: print("error_thread") self.error.emit("Alerte !") return # ... self.finished.emit("un slug") class Widget(QtWidgets.QWidget, Ui_create_project): creating = QtCore.pyqtSignal() created = QtCore.pyqtSignal(str) aborted = QtCore.pyqtSignal(str) def __init__(self): super(Widget, self).__init__() self.setupUi(self) self.create_btn.clicked.connect(self.create_project) def create_project(self): self.thread = Thread(self.url_input.text()) self.thread.error.connect(self.aborted.emit) self.thread.finished.connect(self.created.emit) self.thread.start() self.creating.emit() |
Je ne passe jamais dans les fonctions main.MainWindow.create_project_success
et main.MainWindow.create_project_error
, même si mon thread émet une erreur ("error_thread"
s'affiche).
Le signal creating
est par contre bien émis et reçu.
Merci !
+0
-0