erwan83 Du Shift DEL tu te méfieras ! |
Voici mon bout de code :
Dans la première class j'ai mes LABEL, INPUT et encore LABEL pour afficher les correspondances trouvées dans la BDD
je vais chercher à partir de NOM_Input et PRENOM_Input des personnes dans la BDD CLIENTELE
avec : def click_NOM_Input(self):
def click_PRENOM_Input(self):
je récupère donc mes valeurs suivantes :
Prenom_frappe
Nom_frappe
je cherche dans la BDD et je confirme, ça me sort : (lignes 91 à 109)
Date_Naissance_frappe
je lance une deuxième fois une recherche BDD (ça reste à améliorer...) (lignes 93 à 103)
La deuxième class est vide pour l'instant.
Dans la troisième class je voudrais faire une représentation graphique (ça marchait à la base... mais en faisant des corrections je me suis planté)
Donc je définis mon canvas QPixmap déjà dans ma class
Mais je le recrée dans la fonction du dessous.
Et là où je panique, c'est que rien ne s'affiche...
Donc voilà, désolé pour le gros code mais tout y est (ou presque)
Si une âme charitable peut m'aider.....
Code :
- import psycopg2
- import sys
- import math
- from PyQt6.QtWidgets import QApplication, QPushButton, QWidget, QLineEdit,QDialog, QLabel, QCalendarWidget,QMessageBox,QComboBox,QVBoxLayout,QHBoxLayout,QGridLayout,QLayout
- from PySide6.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,QRect, QSize, QUrl, Qt)
- from PyQt6.QtGui import QBrush, QPainter, QPen, QPixmap, QColor,QFont
- from PyQt6 import QtWidgets, QtCore, QtGui
- class PREMIER_BLOC(QtWidgets.QWidget):
- def __init__(self, parent=None):
- super(PREMIER_BLOC, self).__init__(parent)
-
- self.LAYOUT_1 = QtWidgets.QHBoxLayout()
-
- ### 1ere HBox
- self.H_BOX1 = QtWidgets.QHBoxLayout()
-
- self.NOM_Label = QtWidgets.QLabel('Nom :')
- self.H_BOX1.addWidget(self.NOM_Label)
- self.NOM_Input = QtWidgets.QLineEdit()
- self.NOM_Input.textChanged.connect(self.click_NOM_Input)
- self.H_BOX1.addWidget(self.NOM_Input)
- self.NOM_Corresp = QtWidgets.QLabel(self)
- self.H_BOX1.addWidget(self.NOM_Corresp)
- ### 2eme HBox
- self.H_BOX2 = QtWidgets.QHBoxLayout()
- self.PRENOM_Label = QtWidgets.QLabel('Prénom :'))')
- self.H_BOX2.addWidget(self.PRENOM_Label)
- self.PRENOM_Input = QtWidgets.QLineEdit()
- self.PRENOM_Input.textChanged.connect(self.click_PRENOM_Input)
- self.H_BOX2.addWidget(self.PRENOM_Input)
- self.PRENOM_Corresp = QtWidgets.QLabel(self)
- self.H_BOX2.addWidget(self.PRENOM_Corresp)
-
- ### 3eme HBox
- self.H_BOX3 = QtWidgets.QHBoxLayout()
- self.DATE_DE_NAISSANCE_Label = QtWidgets.QLabel('Date de naissance :')
- self.H_BOX3.addWidget(self.DATE_DE_NAISSANCE_Label)
- self.DATE_DE_NAISSANCE_Input = QtWidgets.QLineEdit(self)
- self.H_BOX3.addWidget(self.DATE_DE_NAISSANCE_Input)
- self.DATE_DE_NAISSANCE_Corresp = QtWidgets.QLabel(self)
- self.H_BOX3.addWidget(self.DATE_DE_NAISSANCE_Corresp)
-
- ### Ajout addStretch pour les espacements
- self.H_BOX1.addStretch()
- self.H_BOX2.addStretch()
- self.H_BOX3.addStretch()
-
- self.V_BOX1 = QtWidgets.QVBoxLayout()
- self.V_BOX1.addLayout(self.H_BOX1)
- self.V_BOX1.addLayout(self.H_BOX2)
- self.V_BOX1.addLayout(self.H_BOX3)
- self.V_BOX1.addLayout(self.LAYOUT_1)
- self.V_BOX1.addStretch()
- Concrete_Group = QtWidgets.QGroupBox()
- Concrete_Group.setTitle('Choix de la personne')
- Concrete_Group.setLayout(self.V_BOX1)
- lay = QtWidgets.QVBoxLayout(self)
- lay.addWidget(Concrete_Group)
- def click_NOM_Input(self):
- Nom_frappe = self.NOM_Input.text()
- self.NOM_Corresp.setText(Nom_frappe)
- ligne = "%s%s%s" % ("SELECT NOM FROM CLIENTELE WHERE UPPER(NOM) LIKE '",Nom_frappe.upper(), "%'" )
- lancesql(ligne)
- conn.commit()
- records = cursor.fetchall()
- for row in records:
- if row[0].upper() == Nom_frappe.upper():
- self.NOM_Corresp.setText(row[0].upper())
- def click_PRENOM_Input(self):
- Prenom_frappe = self.PRENOM_Input.text()
- Nom_frappe = self.NOM_Input.text()
- Date_Naissance_frappe = self.DATE_DE_NAISSANCE_Input.text()
- self.PRENOM_Corresp.setText(Prenom_frappe)
- print(Prenom_frappe)
- ligne = "%s%s%s" % ("SELECT PRENOM, NOM FROM CLIENTELE WHERE UPPER(PRENOM) LIKE '",Prenom_frappe.upper(), "%'" )
- lancesql(ligne)
- conn.commit()
- records = cursor.fetchall()
- for row in records:
- if row[0].upper() == Prenom_frappe.upper() and row[1].upper() == Nom_frappe.upper():
- self.PRENOM_Corresp.setText(row[0].upper())
- ligne = "%s%s%s%s%s" % ("SELECT NOM,PRENOM, DATE_NAISSANCE FROM CLIENTELE WHERE UPPER(PRENOM) LIKE '",Prenom_frappe.upper(), "%' AND UPPER(NOM) LIKE '",Nom_frappe.upper(), "%'" )
- lancesql(ligne)
- conn.commit()
- records = cursor.fetchall()
- for row in records:
- if row[0].upper() == Nom_frappe.upper() and row[1].upper() == Prenom_frappe.upper():
- print(row[0],row[1],row[2])
- self.DATE_DE_NAISSANCE_Corresp.setText(row[2])
- self.DATE_DE_NAISSANCE_Input.setText(row[2])
- print(Prenom_frappe,Nom_frappe,Date_Naissance_frappe)
- return(Prenom_frappe,Nom_frappe,Date_Naissance_frappe)
-
- ### SECOND BLOC
- class SECOND_BLOC(QtWidgets.QWidget):
- def __init__(self, parent=None):
- super(SECOND_BLOC, self).__init__(parent)
- ### TROISIEME BLOC
- class TROISIEME_BLOC(QtWidgets.QWidget):
- def __init__(self, parent=None):
- super(TROISIEME_BLOC, self).__init__(parent)
- V_BOX1 = QtWidgets.QVBoxLayout(self)
- self.H_BOX4 = QtWidgets.QHBoxLayout()
- self.BTN_RECHERCHER_LIENS = QtWidgets.QPushButton('Rechercher',self)
- self.BTN_RECHERCHER_LIENS.clicked.connect(self.RECHERCHER_LIENS)
- self.H_BOX4.addWidget(self.BTN_RECHERCHER_LIENS)
- TROISIEME_BLOC.label = QtWidgets.QLabel()
- canvas = QtGui.QPixmap(1600,1600)
- canvas.fill(QColor("white" ))
- TROISIEME_BLOC.label.setPixmap(canvas)
- V_BOX1.addWidget(self.BTN_RECHERCHER_LIENS)
- V_BOX1.addWidget(self.label)
- TROISIEME_BLOC.label.setPixmap(canvas)
-
- def RECHERCHER_LIENS(self):
- Prenom_frappe = PREMIER_BLOC.click_NOM_Input(Prenom_frappe)
- Nom_frappe = PREMIER_BLOC.click_PRENOM_Input(Nom_frappe)
- Date_Naissance_frappe = PREMIER_BLOC.click_PRENOM_Input(Date_Naissance_frappe)
- ### PREMIERE BOUCLE : RECHERCHE DES RELATIONS
- ligne = "%s%s%s%s%s" % ("SELECT PRENOM_ORIGINE,NOM_ORIGINE,DATE_NAISSANCE_ORIGINE,PRENOM_DESTINATION,NOM_DESTINATION,DATE_NAISSANCE_DESTINATION,TYPE_DE_RELATION FROM RELATION WHERE UPPER(PRENOM_ORIGINE) LIKE '",Prenom_frappe.upper(), "%' AND UPPER(NOM_ORIGINE) LIKE '",Nom_frappe.upper(), "%'" )
- lancesql(ligne)
- conn.commit()
- records = cursor.fetchall()
-
- compte = 0
- Nom_Destination =[]
- Prenom_Destination =[]
- Relation =[]
- canvas = QtGui.QPixmap(1600,1600)
- canvas.fill(QColor("white" ))
- self.label.setPixmap(canvas)
- canvas = self.label.pixmap()
- painter = QtGui.QPainter(canvas)
-
- for row1 in records:
- compte = compte+1
- print(row1[1],row1[0],'=>',row1[4],row1[3],row1[6])
- Nom_Destination.append(row1[4])
- Prenom_Destination.append(row1[3])
- Relation.append(row1[6])
- if compte == 0:
- print("aucune relation" )
- if compte > 0:
- print(Nom_frappe)
- print(Prenom_frappe)
- print(Nom_Destination)
-
- ### PREMIERE BOUCLE : NOM PRENOM DE DEPART =>
- texte = "%s %s" % (Nom_frappe.upper(),Prenom_frappe.capitalize())
- painter.drawText(750,800,texte)
- ### PREMIERE BOUCLE : CENTRE DE DEPART
- center = [800,800]
- ### PREMIERE BOUCLE : TABLEAU DES COORDONNEES D'ARRIVEE
- CoordX=[]
- CoordY=[]
- ### PREMIERE BOUCLE : SI ON A DES DESTINATIONS
- if len(Nom_Destination) >0 :
- painter.setPen(QColor(100, 100, 100, 120))
- for index in range (0,len(Nom_Destination),1):
- ### PREMIERE BOUCLE : INCREMENTATION DES COORDONNEES D'ARRIVEE
- xC = int(center[0] + 250*math.cos((40/(len(Nom_Destination)+1))*index))
- yC = int(center[1] + 250*math.sin((40/(len(Nom_Destination)+1)*index)))
- CoordX.append(xC)
- CoordY.append(yC)
- ### PREMIERE BOUCLE : TRACE DES LIGNES
- print("dessin ligne" )
- painter.drawLine(center[0],center[1],xC,yC)
- painter.setPen(QColor(0, 0, 0, 225))
- painter.setFont(QFont("Arial", 12))
- ### PREMIERE BOUCLE : TRACE DES NOMS
- texte = "%s %s" % (Nom_Destination[index].upper(),Prenom_Destination[index].capitalize())
- print("dessin texte" )
- painter.drawText(xC-40,yC,texte)
- painter.setPen(QColor(0, 0, 0, 225))
- painter.setFont(QFont("Arial", 10))
- texte = Relation[index]
- print("dessin texte" )
- painter.drawText(int(xC/2+center[0]/2)-20,int(yC/2+center[1]/2),texte)
-
- for index in range(0,len(Nom_Destination),1):
- ### DEUXIEME BOUCLE : RECHERCHE DES RELATIONS
- ligne = "%s%s%s%s%s%s%s%s%s" % ("SELECT PRENOM_ORIGINE,NOM_ORIGINE,DATE_NAISSANCE_ORIGINE,PRENOM_DESTINATION,NOM_DESTINATION,DATE_NAISSANCE_DESTINATION,TYPE_DE_RELATION FROM RELATION \
- WHERE UPPER(PRENOM_DESTINATION) NOT LIKE '",Prenom_frappe.upper(), "' AND UPPER(NOM_DESTINATION) NOT LIKE '",Nom_frappe.upper(), "' AND \
- UPPER(PRENOM_ORIGINE) LIKE '",Prenom_Destination[index], "%' AND UPPER(NOM_ORIGINE) LIKE '",Nom_Destination[index], "%'" )
- lancesql(ligne)
- conn.commit()
- records2 = cursor.fetchall()
- compte_2 = 0
- Nom_Destination_indice =[]
- Prenom_Destination_indice =[]
- Relation_indice =[]
- for row2 in records2:
-
- Nom_Destination_indice.append(row2[4])
- Prenom_Destination_indice.append(row2[3])
- Relation_indice.append(row2[6])
- compte_2 = compte_2+1
- if compte_2 > -1:
- compte_2 = compte_2 -1
- center = [CoordX[compte_2],CoordY[compte_2]]
- Nom_Origine = row2[1]
- Prenom_Origine = row2[0]
- #### LANCER UNE DEUXIEME FONCTION
- for index_2 in range(0,compte_2,1):
- ligne = "%s%s%s%s%s" % ("SELECT PRENOM_ORIGINE,NOM_ORIGINE,DATE_NAISSANCE_ORIGINE,PRENOM_DESTINATION,NOM_DESTINATION,DATE_NAISSANCE_DESTINATION,TYPE_DE_RELATION FROM RELATION WHERE \
- UPPER(PRENOM_ORIGINE) LIKE '",Prenom_Origine.upper(), "%' AND UPPER(NOM_ORIGINE) LIKE '",Nom_Origine.upper(), "%'" )
- lancesql(ligne)
- conn.commit()
- records = cursor.fetchall()
- for row3 in records:
- print(Nom_Origine,Prenom_Origine,'=>',row3[6],'=>',row3[4],row3[3])
- ### recherche des liens dans la BDD
- ligne = "%s%s%s%s%s" % ("SELECT PRENOM_ORIGINE,NOM_ORIGINE,DATE_NAISSANCE_ORIGINE,PRENOM_DESTINATION,NOM_DESTINATION,DATE_NAISSANCE_DESTINATION,TYPE_DE_RELATION FROM RELATION WHERE \
- UPPER(PRENOM_ORIGINE) LIKE '",Prenom_Origine.upper(), "%' AND UPPER(NOM_ORIGINE) LIKE '",Nom_Origine.upper(), "%'" )
- lancesql(ligne)
- CoordX=[]
- CoordY=[]
- for row4 in records:
- painter.setPen(QColor(0, 0, 0, 225))
- painter.setFont(QFont("Arial", 12))
- texte = "%s %s" % (Nom_Origine.upper(),Prenom_Origine.capitalize())
- painter.drawText(center[0],center[1],texte)
- print("==>origine:",center[0],center[1],texte)
- xC = int(center[0] + 250*math.cos((40/(len(records)+1))*compte_2))
- yC = int(center[1] + 250*math.sin((40/(len(records)+1)*compte_2)))
- CoordX.append(xC)
- CoordY.append(yC)
- painter.drawLine(center[0],center[1],xC,yC)
- painter.setPen(QColor(0, 0, 0, 225))
- painter.setFont(QFont("Arial", 12))
- texte = "%s %s" % (row4[4].upper(),row4[3].capitalize())
- painter.drawText(xC,yC,texte)
-
- print("fin painter" )
- painter.end()
- if __name__ == '__main__':
- app = QtWidgets.QApplication(sys.argv)
- w = ClassWidget()
- w.show()
- sys.exit(app.exec())
|
---------------
https://www.oise-net-multiservices.com
|