From 5e23fcc7de84adf23ea52ae0858f31b8934fabd3 Mon Sep 17 00:00:00 2001 From: Debulois Date: Wed, 27 Apr 2022 13:17:19 +0200 Subject: Système de recherche MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/windowRecherche.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/gui/windowRecherche.py (limited to 'src/gui/windowRecherche.py') diff --git a/src/gui/windowRecherche.py b/src/gui/windowRecherche.py new file mode 100644 index 0000000..c86bcc9 --- /dev/null +++ b/src/gui/windowRecherche.py @@ -0,0 +1,63 @@ + +from PyQt5.QtWidgets import ( + QDialog, QVBoxLayout, QHBoxLayout, + QLabel, QPushButton, QMessageBox +) +from src.database import dbsearch +# https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result +# https://stackoverflow.com/questions/53751106/create-lambda-functions-in-a-loop-for-pyqt5-signals?noredirect=1 + + +def more_infos(mainWindow, proId): + search: object = dbsearch.DbSearch(mainWindow) + resRecherche: list = search.get_user_info_by_userid(proId)[0][1:] + label: list = [ + "Nom", + "Prénom", + "Diplôme", + "Capacités", + "Description", + "Téléphone", + "Adresse", + "Code postale", + "Ville", + ] + text: list = [] + print(resRecherche) + for i in range(len(resRecherche)): + text.append(f"{label[i]}: {resRecherche[i]}") + + QMessageBox.information( + mainWindow, + "Informations du pro", + "\n".join(text) + ) + +def main(mainWindow: object, results: list) -> None: + dial = QDialog(parent = mainWindow) + dial.setWindowTitle("Recherche") + layoutsResult: list = [] + for i in results: + layoutLine = QHBoxLayout() + color = results.index(i) % 2 + if color: + colored = QLabel(i["text"]) + colored.setStyleSheet("background-color: rgb(230,200,200); border-radius: 3px") + layoutLine.addWidget(colored) + else: + layoutLine.addWidget(QLabel(i["text"])) + btnInfos = QPushButton("Infos") + btnInfos.clicked.connect( + lambda checked, proId = i['id']: + more_infos(mainWindow, proId) + ) + layoutLine.addStretch() + layoutLine.addWidget(btnInfos) + layoutsResult.append(layoutLine) + + layoutMain = QVBoxLayout() + for layout in layoutsResult: + layoutMain.addLayout(layout) + + dial.setLayout(layoutMain) + dial.show() -- cgit v1.2.3