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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
import sys
import Darphil
from VariableGlobal import *
from PyQt6 import QtCore
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel,QFrame, QVBoxLayout,QWidget, QGridLayout,QScrollArea,QHBoxLayout
from PyQt6.QtCore import QBasicTimer,Qt, QMimeData
from PyQt6.QtGui import QDrag
class DpLabel(QLabel):
def __init__(self, numero, tableau=None):
super().__init__(numero,tableau)
self.timer = QBasicTimer()
self.tableau = tableau
self.setStyleSheet("border: none;")
self.setAcceptDrops(True)
self.initUI(numero)
def initUI(self,numero):
self.setText(numero)
def timerEvent(self, event):
self.timer.stop()
def mousePressEvent(self, event):
if event.button() == Qt.MouseButton.LeftButton:
if self.timer.isActive():
self.actionDblClick(self.text())
self.timer.stop()
else:
self.timer.start(250, self)
drag = QDrag(self)
mime_data = QMimeData()
mime_data.setText(self.text())
drag.setMimeData(mime_data)
drag.exec(Qt.DropAction.MoveAction)
def dragEnterEvent(self, event):
if event.mimeData().hasText():
event.acceptProposedAction()
def dropEvent(self, event):
self.setText(event.mimeData().text())
def actionDblClick(self,text):
print(text)
class Cellule(QFrame):
def __init__(self,numero,coulNiv,tableau=None):
super().__init__(tableau)
self.tableau = tableau
self.setStyleSheet(f"color: {coulNiv}; border: {Darphil.calcul_Taille_Font(1)}px solid {coulNiv};")
self.initUI(numero,coulNiv)
def initUI(self,numero,coulNiv):
self.label = DpLabel(numero,self.tableau)
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout = QVBoxLayout()
layout.addWidget(self.label)
self.setLayout(layout)
# Base du tableau----------------------------------------------------------------------------------
class TableauPop(QMainWindow):
"Mise en place de la base pour la construction du tableau"
def __init__(self):
super().__init__()
self.setObjectName("TableauPop")
self.setWindowTitle("Tableau population MA")
self.setStyleSheet(couleur.tableau)
self.cellule = {}
self.setupUi()
def setupUi(self):
self.centralwidget = QWidget(parent=self)
self.horizontalLayout = QHBoxLayout(self.centralwidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setSpacing(0)
self.zoneScroll = QScrollArea(parent=self.centralwidget)
self.zoneScroll.setStyleSheet("border: none;")
self.zoneScroll.setWidgetResizable(True)
self.scrollAreaWidgetContents = QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 1280, 1024))
self.scrollAreaWidgetContents.setMinimumSize(QtCore.QSize(1280, 1024))
self.tableau = QGridLayout(self.scrollAreaWidgetContents)
self.dictCellule = {} # Dictionnaire pour stocker les cellules (qframe)
premierLigne=["21","23","25", "27", "29", "31", "33", "35", "37", "39", "41", "43", "niv", "38", "36", "34", "32", "30", "28", "26", "24", "22"]
deuxiemeLigne=["19", "17", "15", "13", "11", "09", "07", "05", "03", "01", "02", "04", "06", "08", "10", "12", "14", "16", "18", "20"]
annexeLigne=["23", "21", "19", "17", "15", "13", "11", "09", "07", "05", "03", "01", "popaxe", "02", "04", "06", "08", "10", "12", "14", "16", "18", "20", "22", "24"]
for niveau in range(1,9):#9
if niveau==1:
coulNiv=couleur.niveau1
col=0
lig=0
elif niveau==2:
coulNiv=couleur.niveau2
col=0
lig=3
elif niveau==3:
coulNiv=couleur.niveau3
col=0
lig=6
elif niveau==4:
coulNiv=couleur.niveau4
col=0
lig=9
elif niveau==5:
coulNiv=couleur.niveau5
col=26#29
lig=0
elif niveau==6:
coulNiv=couleur.niveau6
col=26
lig=3
elif niveau==7:
coulNiv=couleur.niveau7
col=26
lig=6
elif niveau==8:
coulNiv=couleur.niveau8
col=26
lig=9
cpt=0
#premiere rangee ----------------------------------------------------------------------
for num in premierLigne:
if num=="niv":
separation = QFrame()
separation.setFrameShape(QFrame.Shape.VLine)
separation.setStyleSheet(f"border: {Darphil.calcul_Taille_Font(3)}px dashed {couleur.separation};")
self.tableau.addWidget(separation, lig, col+cpt, 1, 1)
cpt+=1
cell = Cellule(f"{num}",coulNiv,self)
self.tableau.addWidget(cell,lig,col+cpt,1,1)
self.dictCellule[f"{num}"] = cell
cpt+=1
cell = Cellule("00",coulNiv,self)
self.tableau.addWidget(cell,lig,col+cpt,1,2)
self.dictCellule["00"] = cell
# deuxieme rangee ---------------------------------------------------------------------
cell = Cellule("A",coulNiv,self)
self.tableau.addWidget(cell,lig+1,col,1,2)
self.dictCellule["A"] = cell
cpt=2
for num in deuxiemeLigne:
if num=="02":
separation = QFrame()
separation.setFrameShape(QFrame.Shape.VLine)
separation.setStyleSheet(f"border: {Darphil.calcul_Taille_Font(3)}px dashed {couleur.separation};")
self.tableau.addWidget(separation, lig+1, col+cpt, 1, 1)
cpt+=1
cell = Cellule(f"{num}",coulNiv,self)
self.tableau.addWidget(cell,lig+1,col+cpt,1,1)
self.dictCellule[f"{num}"] = cell
cpt+=1
cell = Cellule("B",coulNiv,self)
self.tableau.addWidget(cell,lig+1,col+cpt,1,2)
self.dictCellule["B"] = cell
separation = QFrame()
separation.setFrameShape(QFrame.Shape.HLine)
separation.setStyleSheet(f"border: {Darphil.calcul_Taille_Font(3)}px solid {couleur.separation};")
self.tableau.addWidget(separation, lig+2, 0, 1, 51)
separation = QFrame()
separation.setFrameShape(QFrame.Shape.VLine)
separation.setStyleSheet(f"border: {Darphil.calcul_Taille_Font(3)}px solid {couleur.separation};")
self.tableau.addWidget(separation, 0, 25, 11, 1)
self.zoneScroll.setWidget(self.scrollAreaWidgetContents)
self.horizontalLayout.addWidget(self.zoneScroll)
self.setCentralWidget(self.centralwidget)
|
Partager