def __init__(self): """ Dialog to manage the settings of the application """ super().__init__() self.setWindowTitle("Settings") self.setFixedSize(310, 250) # Create the general settings widgets for managing the text color, # text alignment, and author of the app's content # NOTE: Altering the default CSS attributes, such as the color, of a # widget can change its appearance. Hence, the button may appear # rectangular depending upon your platform self.text_color_button = QPushButton() self.text_color_button.setStyleSheet( "background-color: #000000") # Black self.text_color_button.clicked.connect(self.selectTextColor) self.align_left = QRadioButton(text="Left") # Default self.align_left.setChecked(True) self.align_center = QRadioButton(text="Center") self.align_center.setChecked(False) self.align_right = QRadioButton(text="Right") self.align_right.setChecked(False) # Layout and container for alignment radio buttons align_v_box = QVBoxLayout() align_v_box.setContentsMargins(0, 5, 0, 0) align_v_box.addWidget(self.align_left) align_v_box.addWidget(self.align_center) align_v_box.addWidget(self.align_right) align_frame = QFrame() align_frame.setFrameShape(QFrame.Shape.NoFrame) align_frame.setLayout(align_v_box) self.author_name = QLineEdit() self.author_name.setMinimumWidth(160) self.button_box = QDialogButtonBox( QDialogButtonBox.StandardButtons.Ok | QDialogButtonBox.StandardButtons.Cancel) self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject) dialog_layout = QFormLayout() dialog_layout.addRow("<b>Text Color:</b>", self.text_color_button) dialog_layout.addRow(HorizontalSeparator()) dialog_layout.addRow("<b>Text Alignment:</b>", align_frame) dialog_layout.addRow(HorizontalSeparator()) dialog_layout.addRow("<b>Author:</b>", self.author_name) dialog_layout.addWidget(self.button_box) self.setLayout(dialog_layout)
class CreatePatientDialog(QDialog): def __init__(self, classification, patient, infoLabel, parent=None): super(CreatePatientDialog, self).__init__(parent) self.setWindowTitle('Create new patient') layout = QVBoxLayout() self.setLayout(layout) self.setMinimumWidth(200) self.patient = patient self.classifyExercises = classification self.infoLabel = infoLabel self.subjectEdit = QLineEdit() self.subjectEdit.setFixedHeight(30) self.subjectEdit.setText('Jozsika') self.subjectEdit.setStyleSheet(CustomQStyles.lineEditStyle) self.ageEdit = QLineEdit() self.ageEdit.setFixedHeight(30) self.ageEdit.setValidator(QIntValidator()) self.ageEdit.setText('5') self.ageEdit.setStyleSheet(CustomQStyles.lineEditStyle) self.subjectButton = QPushButton('Add patient') self.subjectButton.setFixedHeight(30) self.subjectButton.setStyleSheet(CustomQStyles.outlineButtonStyle) self.subjectButton.clicked.connect(self.onSubjectSelected) self.subjectButton.setContentsMargins(5, 15, 5, 5) formContainer = QWidget() self.formLayout = QFormLayout() self.formLayout.addRow('Name', self.subjectEdit) self.formLayout.addRow('Age', self.ageEdit) self.formLayout.addWidget(self.subjectButton) self.formLayout.setFormAlignment(Qt.Alignment.AlignCenter) formContainer.setLayout(self.formLayout) formContainer.setStyleSheet( "background-color: white; border-radius: 7px;") layout.addWidget(formContainer) def onSubjectSelected(self): if self.classifyExercises is not None \ and "" != self.subjectEdit.text() \ and "" != self.ageEdit.text(): self.subject = self.subjectEdit.text() self.classifyExercises.subject = self.subject self.classifyExercises.age = self.ageEdit.text() self.infoLabel.setText("Subject name set to " + self.subject + ", age " + self.classifyExercises.age) self.close()
class Authenticate(QDialog): def __init__(self): cred = { 'user': os.getenv('USER'), 'password': os.getenv('PASS'), 'host': os.getenv('HOST'), 'database': os.getenv('DATA'), } self.success(cred) def success(self, cred): try: return CONNECT(cred) except (sql.errors.InterfaceError, UnicodeError): self.start() def start(self): super().__init__() self.setWindowTitle("Enter your credentials") QBtn = QDialogButtonBox.StandardButton.Ok self.buttonBox = QDialogButtonBox(QBtn) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.layout = QFormLayout() self.layout.addRow('Username:'******'Password:'******'Hostname:', QLineEdit()) self.layout.addRow('Database:', QLineEdit()) self.layout.addWidget(self.buttonBox) self.setLayout(self.layout) self.exec() if QBtn == QDialogButtonBox.StandardButton.Ok: cred = { 'user': self.layout.itemAt(1).widget().text(), 'password': self.layout.itemAt(3).widget().text(), 'host': self.layout.itemAt(5).widget().text(), 'database': self.layout.itemAt(7).widget().text() } try: success = CONNECT(cred) env = dotenv.find_dotenv() dotenv.set_key(env, 'USER', cred['user']) dotenv.set_key(env, 'PASS', cred['password']) dotenv.set_key(env, 'HOST', cred['host']) dotenv.set_key(env, 'DATA', cred['database']) return success except (sql.errors.InterfaceError, ValueError): message = QMessageBox(self) message.setWindowTitle('Error') message.setText('The entered credentials are incorrect') message.setStandardButtons(QMessageBox.StandardButton.Ok) if message == QMessageBox.StandardButton.Ok: self.start()