from core.models.Result import Result from gui.v2.ui.pages.create_edit.components import SelectionGroup, TextInputGroup from gui.v2.actions.profile_actions import create_profile from gui.v2.presenters.state.fast_registration_state import RegistrationState from gui.v2.ui.styles.css.fast_register import FAST_REGISTER_ONE, FAST_REGISTER_TWO from gui.v2.ui.pages.Page import Page from gui.v2.ui.pages.create_edit.resolution_widget import CustomResolutionDialog from PyQt6.QtWidgets import QWidget, QPushButton, QGridLayout, QVBoxLayout from PyQt6.QtCore import Qt class FastRegistrationPage(Page): def __init__(self, page_stack, main_window, prepared=None): super().__init__("FastRegistration", page_stack, main_window) # 1. Initialize State self.state = RegistrationState(btn_path=self.btn_path) # Banner temp disabled: # self.title.setGeometry(550, 40, 250, 40) # self.title.setText("Fast Registration") self.button_apply.setVisible(True) self.button_back.setVisible(True) self.button_apply.clicked.connect(self.submit_registration) self.button_back.clicked.connect(self.reverse) self.setFixedSize(800, 600) self.content_area = QWidget(self) self.main_layout = QVBoxLayout(self) self.main_layout.setContentsMargins(40, 60, 40, 60) self.grid = QGridLayout(self.content_area) self.grid.setSpacing(30) self.grid.setContentsMargins(0, 0, 0, 0) # 1. Create groups, passing the category string and the state object self.group_type = SelectionGroup(self.content_area, title="Profile Type", category="type", state=self.state, sync_required=False, btn_path=self.btn_path) self.group_name = TextInputGroup(self.content_area, title="Name", category="name", state=self.state) self.group_proto = SelectionGroup(self.content_area, title="Protocol", category="protocol", state=self.state, sync_required=False, btn_path=self.btn_path) self.group_loc = SelectionGroup(self.content_area, title="Location", category="location", state=self.state, sync_required=False, btn_path=self.btn_path) self.group_browser = SelectionGroup(self.content_area, title="Browser", category="browser", state=self.state, sync_required=False, btn_path=self.btn_path) self.group_res = SelectionGroup(self.content_area, title="Resolution", category="resolution", state=self.state, sync_required=False, btn_path=self.btn_path) # 2. Quality Control: Force columns to share width equally self.grid.setColumnStretch(0, 1) self.grid.setColumnStretch(1, 1) # 3. adding groups in rows of 2 items each: self.grid.addWidget(self.group_type, 0, 0, Qt.AlignmentFlag.AlignTop) self.grid.addWidget(self.group_name, 0, 1, Qt.AlignmentFlag.AlignTop) self.grid.addWidget(self.group_proto, 1, 0, Qt.AlignmentFlag.AlignTop) self.grid.addWidget(self.group_loc, 1, 1, Qt.AlignmentFlag.AlignTop) self.grid.addWidget(self.group_browser, 2, 0, Qt.AlignmentFlag.AlignTop) self.grid.addWidget(self.group_res, 2, 1, Qt.AlignmentFlag.AlignTop) self.grid.setRowStretch(3, 1) # Add the content area to the main window layout self.main_layout.addWidget(self.content_area) # 4. Custom options, such as Resolution: custom_button = QPushButton("Custom Res", self) custom_button.setGeometry(307, 500, 185, 30) custom_button.setStyleSheet(FAST_REGISTER_ONE) custom_button.clicked.connect(self.show_custom_res_dialog) custom_button.show() self.grid.addWidget(custom_button, 3, 1, Qt.AlignmentFlag.AlignCenter) self.grid.setRowStretch(4, 1) def show_custom_res_dialog(self): # Shows the popup asking for the custom choice: dialog = CustomResolutionDialog( style_sheet=FAST_REGISTER_TWO, parent=self ) # if it passes the validation screen inside it, then update state: dialog.resolution_selected.connect(self.handle_resolution_update) dialog.exec() def handle_resolution_update(self, resolution): """Update State with the selected Resolution""" success = self.state.set_selection("resolution", resolution) if success: print(f"Resolution updated to {resolution}") else: print("Custom resolution failed validation.") def after_submission(self, result: Result): """Navigate to the homepage after the completion of the registration""" if result.valid: self.custom_window.navigator.navigate("menu") def submit_registration(self): """Get current choices from state, and submit.""" final_choices = self.state.get_final_choices() input_text = self.group_name.text_input.text() if not input_text: self.show_a_popup("Pick a name in the top right box.") return final_choices["name"] = input_text print(f"Submitting choices: {final_choices}") create_profile(potential_data=final_choices, ui_caller=self.after_submission) def reverse(self): self.custom_window.navigator.navigate("menu")