add participant.py for entry window, update main.py to be application entry
This commit is contained in:
parent
e8f9a311b0
commit
7f3cec0144
12
main.py
12
main.py
|
|
@ -0,0 +1,12 @@
|
|||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
|
||||
from modules.participant import Participant
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
window = Participant()
|
||||
window.setWindowTitle("3Dots")
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
||||
BIN
modules/__pycache__/participant.cpython-38.pyc
Normal file
BIN
modules/__pycache__/participant.cpython-38.pyc
Normal file
Binary file not shown.
83
modules/participant.py
Normal file
83
modules/participant.py
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
from PyQt5.QtWidgets import (
|
||||
QWidget,
|
||||
QVBoxLayout,
|
||||
QLineEdit,
|
||||
QComboBox,
|
||||
QPushButton,
|
||||
QFormLayout,
|
||||
QMessageBox,
|
||||
QSpacerItem,
|
||||
QSizePolicy,
|
||||
QHBoxLayout,
|
||||
QGroupBox,
|
||||
QSpinBox
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
|
||||
class Participant(QWidget):
|
||||
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:
|
||||
QMessageBox.information(
|
||||
self, 'Success', f'Participant Registered: {identifier}, Age: {age}, Sex: {sex}')
|
||||
Loading…
Reference in a new issue