Set up the main window with a stacked widget containing home, admin, and employee pages.
(main_window: QtWidgets.QMainWindow)
| 1096 | |
| 1097 | |
| 1098 | def setup_main_window(main_window: QtWidgets.QMainWindow): |
| 1099 | """Set up the main window with a stacked widget containing home, admin, and employee pages.""" |
| 1100 | main_window.setObjectName("MainWindow") |
| 1101 | main_window.resize(800, 600) |
| 1102 | main_window.setStyleSheet("background-color: #f0f2f5;") |
| 1103 | |
| 1104 | central_widget = QtWidgets.QWidget(main_window) |
| 1105 | main_layout = QtWidgets.QHBoxLayout(central_widget) |
| 1106 | |
| 1107 | stacked_widget = QtWidgets.QStackedWidget(central_widget) |
| 1108 | |
| 1109 | # Create pages |
| 1110 | def switch_to_admin(): |
| 1111 | stacked_widget.setCurrentIndex(ADMIN_PAGE) |
| 1112 | |
| 1113 | def switch_to_employee(): |
| 1114 | stacked_widget.setCurrentIndex(EMPLOYEE_PAGE) |
| 1115 | |
| 1116 | def exit_app(): |
| 1117 | QtWidgets.QApplication.quit() |
| 1118 | |
| 1119 | def admin_login_menu_page(name, password): |
| 1120 | try: |
| 1121 | # Ideally, here you'd call a backend authentication check |
| 1122 | success = backend.check_admin(name, password) |
| 1123 | if success: |
| 1124 | QtWidgets.QMessageBox.information( |
| 1125 | stacked_widget, "Login Successful", f"Welcome, {name}!" |
| 1126 | ) |
| 1127 | stacked_widget.setCurrentIndex(ADMIN_MENU_PAGE) |
| 1128 | else: |
| 1129 | QtWidgets.QMessageBox.warning( |
| 1130 | stacked_widget, "Login Failed", "Incorrect name or password." |
| 1131 | ) |
| 1132 | except Exception as e: |
| 1133 | QtWidgets.QMessageBox.critical( |
| 1134 | stacked_widget, "Error", f"An error occurred during login: {str(e)}" |
| 1135 | ) |
| 1136 | # show_popup_message(stacked_widget,"Invalid admin credentials",0) |
| 1137 | |
| 1138 | def add_employee_form_submit(name, password, salary, position): |
| 1139 | if ( |
| 1140 | len(name) != 0 |
| 1141 | and len(password) != 0 |
| 1142 | and len(salary) != 0 |
| 1143 | and len(position) != 0 |
| 1144 | ): |
| 1145 | backend.create_employee(name, password, salary, position) |
| 1146 | show_popup_message( |
| 1147 | stacked_widget, "Employee added successfully", ADMIN_MENU_PAGE |
| 1148 | ) |
| 1149 | |
| 1150 | else: |
| 1151 | print("Please fill in all fields") |
| 1152 | show_popup_message( |
| 1153 | stacked_widget, "Please fill in all fields", ADD_EMPLOYEE_PAGE |
| 1154 | ) |
| 1155 |
no test coverage detected