summaryrefslogtreecommitdiff
path: root/src/gui/windowRecherche.py
blob: c86bcc983305f9c0fdbac9982c67d4d4de263e19 (plain)
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

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()