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
|
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class BoitesImbriquees(QScrollArea):
def __init__(self):
super().__init__()
window = QWidget()
window_layout = QVBoxLayout()
self.ui_questionnaire(window_layout)
window.setLayout(window_layout)
self.setWidget(window)
self.show()
def etat_checkbox(self):
Cb = self.sender()
print('\nCase cochée !!!!!!!!!!!!!!!\n')
print("Cb = self.sender()\n")
print("En inspectant la structure :")
print("[w.text() for w in Cb.parent().parent().parent().children() if isinstance(w, QLabel)][0] :", [w.text() for w in Cb.parent().parent().parent().children() if isinstance(w, QLabel)][0])
print("[w.title() for w in Cb.parent().parent().parent().children() if isinstance(w, QGroupBoxl)][0] :", [w.title() for w in Cb.parent().parent().parent().children() if isinstance(w, QGroupBox)][0])
print("[w.text() for w in Cb.parent().children() if isinstance(w, QLabel)][0] :", [w.text() for w in Cb.parent().children() if isinstance(w, QLabel)][0])
print("[Cb.text() :", Cb.text())
print("\nEn donnant un nouvel attribut :")
print(f"Cb.section_name : {Cb.section_name}")
print(f"Cb.sub_section_name : {Cb.sub_section_name}")
print(f"Cb.question_text : {Cb.question_text}")
def ui_questionnaire(self, parent):
from itertools import islice, count, cycle, product
from string import ascii_lowercase as a_lc, ascii_uppercase as a_uc
# Un générateur ésotérique de sections!
SECTIONS = a_uc[:4]
sub_section_gen = (islice(count(), i, i+3) for i in count(0,3))
question_gen = (islice((''.join(x) for x in product(a_lc, a_lc)), i, i+3) for i in count(0, 3))
for s in SECTIONS:
SOUS_SECTIONS = next(sub_section_gen)
section_frame = QFrame()
section_label = QLabel(f"section {s}")
section_layout = QVBoxLayout()
section_layout.addWidget(section_label)
for ss in SOUS_SECTIONS:
QUESTIONS = next(question_gen)
sub_section_box = QGroupBox(f"Sous Section {ss}")
sub_section_layout = QHBoxLayout()
for q in QUESTIONS:
question_frame = QFrame()
question_layout = QHBoxLayout()
question_label=QLabel(f"Question {q}")
question_Cb = QCheckBox(str(q))
question_Cb.clicked.connect(self.etat_checkbox)
question_Cb.section_name = s
question_Cb.sub_section_name = ss
question_Cb.question_text = q
question_layout.addWidget(question_label)
question_layout.addWidget(question_Cb)
question_frame.setLayout(question_layout)
sub_section_layout.addWidget(question_frame)
sub_section_box.setLayout(sub_section_layout)
section_layout.addWidget(sub_section_box)
section_frame.setLayout(section_layout)
parent.addWidget(section_frame)
app=QApplication([])
appli=BoitesImbriquees()
app.exec_() |
Partager