91 lines
2.7 KiB
Python
91 lines
2.7 KiB
Python
from PyQt5.QtCore import Qt, pyqtSignal
|
|
from PyQt5.QtWidgets import (
|
|
QWidget,
|
|
QVBoxLayout,
|
|
QLineEdit,
|
|
QComboBox,
|
|
QPushButton,
|
|
QFormLayout,
|
|
QMessageBox,
|
|
QSpacerItem,
|
|
QSizePolicy,
|
|
QHBoxLayout,
|
|
QGroupBox,
|
|
QSpinBox
|
|
)
|
|
|
|
|
|
class Participant(QWidget):
|
|
reg_success = pyqtSignal()
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
main_layout = QVBoxLayout()
|
|
main_layout.addSpacerItem(
|
|
QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
|
|
|
|
forms_container = QGroupBox()
|
|
forms_container.setFixedSize(600, 500)
|
|
|
|
forms_layout = QFormLayout()
|
|
|
|
# Identifier
|
|
self.identifier_input = QLineEdit()
|
|
self.identifier_input.setPlaceholderText("Enter Identifier")
|
|
forms_layout.addRow("Participant Identifier:", self.identifier_input)
|
|
|
|
# Age
|
|
self.age_input = QSpinBox()
|
|
self.age_input.setRange(0, 120)
|
|
forms_layout.addRow("Participant Age (0-120):", self.age_input)
|
|
|
|
# Sex
|
|
self.sex_input = QComboBox()
|
|
self.sex_input.addItems(["Select", "Male", "Female", "Other"])
|
|
forms_layout.addRow("Sex:", self.sex_input)
|
|
|
|
# Begin button
|
|
self.begin_button = QPushButton("Begin")
|
|
self.begin_button.clicked.connect(self.on_begin_clicked)
|
|
forms_layout.addWidget(self.begin_button)
|
|
|
|
box_layout = QVBoxLayout()
|
|
box_layout.setAlignment(Qt.AlignCenter)
|
|
box_layout.addLayout(forms_layout)
|
|
forms_container.setLayout(box_layout)
|
|
|
|
centered_layout = QHBoxLayout()
|
|
centered_layout.addStretch()
|
|
centered_layout.addWidget(forms_container, alignment=Qt.AlignCenter)
|
|
centered_layout.addStretch()
|
|
|
|
main_layout.addLayout(centered_layout)
|
|
main_layout.addSpacerItem(
|
|
QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
|
|
|
|
self.setLayout(main_layout)
|
|
|
|
def on_begin_clicked(self):
|
|
"""Handler for begin button"""
|
|
# include logic for saving participant data to file here also
|
|
identifier = self.identifier_input.text().strip()
|
|
age = self.age_input.value()
|
|
sex = self.sex_input.currentText()
|
|
|
|
if not identifier:
|
|
QMessageBox.warning(
|
|
self, 'Input Error', 'Please enter a Participant Identifier.')
|
|
elif sex == 'Select':
|
|
QMessageBox.warning(
|
|
self, 'Input Error', 'Please select your sex.')
|
|
else:
|
|
result = QMessageBox.information(
|
|
self,
|
|
'Success',
|
|
f'Participant Registered: {identifier}, Age: {age}, Sex: {sex}'
|
|
)
|
|
|
|
if result == QMessageBox.Ok:
|
|
self.reg_success.emit()
|