from PyQt6.QtCore import pyqtSlot
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox
import sys
import os
from Authorization import Ui_Authorization
from Registration import Ui_Registration
from MainWindow import Ui_MainWindow

DATA_FILE = "user_data.txt"

class AuthorizationWindow(QMainWindow, Ui_Authorization):
    def __init__(self):
        super(AuthorizationWindow, self).__init__()
        self.setupUi(self)
        
        # Handle "Зарегистрироваться" button click
        self.pushButton_3.clicked.connect(self.open_registration)

        # Handle "Войти" button click
        self.pushButton.clicked.connect(self.login)

        self.user_data = self.load_user_data()

    def load_user_data(self):
        """Load user data from a file."""
        if not os.path.exists(DATA_FILE):
            return {}
        
        user_data = {}
        with open(DATA_FILE, "r") as file:
            for line in file:
                parts = line.strip().split(",")
                if len(parts) == 2:  # Старый формат, только имя пользователя и пароль
                    username, password = parts
                    email = ""  # Email отсутствует в старом формате
                elif len(parts) == 3:  # Новый формат, включает email
                    username, password, email = parts
                else:
                    continue  # Неправильный формат строки, пропускаем
                
                user_data[username] = {"password": password, "email": email}
        return user_data

    def save_user_data(self):
        """Save user data to a file."""
        with open(DATA_FILE, "w") as file:
            for username, data in self.user_data.items():
                file.write(f"{username},{data['password']},{data['email']}\n")
    
    @pyqtSlot()
    def open_registration(self):
        self.registration_window = RegistrationWindow(self)
        self.registration_window.show()

    @pyqtSlot()
    def login(self):
        username = self.lineEdit.text()
        password = self.lineEdit_2.text()

        msg_box = QMessageBox(self)
        msg_box.setStyleSheet("background-color: white;")

        if username in self.user_data and self.user_data[username]["password"] == password:
            msg_box.setText("Вы успешно вошли в систему!")
            msg_box.setIcon(QMessageBox.Icon.Information)
        else:
            msg_box.setText("Неверный логин или пароль!")
            msg_box.setIcon(QMessageBox.Icon.Warning)
            
        msg_box.exec()

class RegistrationWindow(QMainWindow, Ui_Registration):
    def __init__(self, auth_window):
        super(RegistrationWindow, self).__init__()
        self.setupUi(self)

        # Reference to the authorization window to store user data
        self.auth_window = auth_window

        # Handle "Сохранить" button click
        self.pushButton.clicked.connect(self.save_registration)

    @pyqtSlot()
    def save_registration(self):
        email = self.lineEdit_3.text()
        username = self.lineEdit.text()
        password = self.lineEdit_2.text()
        confirm_password = self.lineEdit_4.text()

        msg_box = QMessageBox(self)
        msg_box.setStyleSheet("background-color: white;")

        if password != confirm_password:
            msg_box.setText("Пароли не совпадают!")
            msg_box.setIcon(QMessageBox.Icon.Warning)
            msg_box.exec()
            return

        self.auth_window.user_data[username] = {"password": password, "email": email}
        self.auth_window.save_user_data()
        msg_box.setText("Регистрация успешна!")
        msg_box.setIcon(QMessageBox.Icon.Information)
        msg_box.exec()

        self.close()

class MainWindowWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, auth_window):
        super(MainWindowWindow, self).__init__()
        self.setupUi(self)


def main():
    app = QApplication(sys.argv)

    auth_window = AuthorizationWindow()
    auth_window.show()

    sys.exit(app.exec())

if __name__ == "__main__":
    main()


Как сделать чтобы после успешного входа открывалось окно MainWindow