Не правильно выполняеться автолог на PyQt6
Мне нужно реализовать автологин в приложении. Данные пользователя у меня запоминаются. При проверке, если данные логина и пароля верны, нужно перейти на другой виджет (AboutTheProgram). Я сделал проверку в функции входа в систему, которая находится в модуле MainWindows. Но у меня получается, что открываются два окна вместо одного.
main.py
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QStackedWidget()
maindow = MainWindows()
maindow.show()
sys.exit(app.exec())
MainWindows.py
class MainWindows(QDialog, Ui_ImageDialog):
homeAction = None
oldPos = QPoint()
def __init__(self):
super().__init__()
self.password = None
self.offset = None
self.username = None
self.dragPos = None
self.reg = None
self.abouttheprogram = None
MainWindows.id_Profile = 6
self.MainMenu = Ui_ImageDialog
self.setupUi(self)
self.setWindowTitle('ZoomApp')
self.setWindowIcon(QtGui.QIcon('image/icon/logo.png'))
RemoveWindowsMenu(self)#Убирает windows форму
#БД
self.client = client
self.db = db
self.coll = coll
self.collLoggedIn = collLoggedIn
#Запомнить пользователя
self.settings = QSettings("ZoomIndistinct", 'AppWise')
self.lineEdit.setText(self.settings.value("login", ""))
self.lineEdit_2.setText(self.settings.value("password", ""))
self.checkBox.setChecked(bool(self.settings.value("remember", "")))
self.login()
# Кнопки
self.pushClose.clicked.connect(self.CloseWindow) # При нажатии на кнопку login перейти на новую страницу
self.pushUrlYouTube.clicked.connect(lambda: webbrowser.open('https://www.youtube.com/'))
self.pushUrlDiscord.clicked.connect(lambda: webbrowser.open('https://discord.gg/JWTcSq3Y'))
self.pushUrlFacebook.clicked.connect(lambda: webbrowser.open('https://www.facebook.com/rrarrkfacit'))
self.pushUrlGitHub.clicked.connect(lambda: webbrowser.open('https://github.com/'))
self.status = self.label_4
self.status.setStyleSheet('font-size:10px; color: red;text-align: center;')
self.pushReg.clicked.connect(self.WindowReg)
#Перемещение окна UpBar
self.UpBar.setStyleSheet("border-top-left-radius: 1px; ")
self.UpBar.move(45, 35)
self.UpBar.show()
def mousePressEvent(self, event: QMouseEvent) -> None:
if event.button() == Qt.MouseButton.LeftButton and self.UpBar.underMouse():
self.offset = event.pos()
else:
self.offset = None
def mouseMoveEvent(self, event: QMouseEvent) -> None:
if self.offset is not None and event.buttons() == Qt.MouseButton.LeftButton and self.UpBar.underMouse():
self.move(self.mapToGlobal(event.pos() - self.offset))
else:
self.offset = None
def login(self):
self.username = self.lineEdit.text()
self.password = self.lineEdit_2.text()
result_pass = db.users.find_one({'firstname': self.username, 'password': self.password})
self.id_Profile = result_pass['_id'] # запомнить id пользователя после логина
if self.settings.contains("login") and self.settings.contains("password"):
self.TransitionAboutTheProgram()
else:
pass
@staticmethod
def CloseWindow():
sys.exit()
def TransitionAboutTheProgram(self):
self.hide()
self.abouttheprogram = AboutTheProgram(self.id_Profile)
self.abouttheprogram.show()
def WindowReg(self):
self.reg = Class.Registration.Refistration()
self.reg.show()
self.hide()
AbountTheProgram.py
class AboutTheProgram(QDialog, Ui_AboutTheProgram,Ui_ImageDialog):
def __init__(self,id_Profile):
super().__init__()
self.offset = None
self.oldPos = None
self.ui = None
self.logo_text = None
self.abouttheprogram = Ui_AboutTheProgram
self.setupUi(self)
RemoveWindowsMenu(self) # Убирает windows форму
self.id_Profile = id_Profile
print(self.id_Profile)
self.importmainclass = main.MainWindows
self.importregclass = main.Refistration
self.nameUsers = os.getlogin()
if os.path.isfile(f'/Users/{self.nameUsers}\Downloads/soft.txt'):
os.remove(f'/Users/{self.nameUsers}\Downloads/soft.txt')
print("success")
else:
print("File doesn't exists!")
#Импорт основных методов передвижение окна windows и убарать windows элементы из виджета.
self.pushClose.clicked.connect(self.importmainclass.CloseWindow)#кнопка завершение программы
self.pushCollapse.clicked.connect(self.showMinimized)#Сворачивание окна
self.pushExit.clicked.connect(self.PushBack)#кнопка для выхода с аккаунта
self.pushDownload.clicked.connect(self.download)
#Достаем логин и email из бд для Profile
Profile = coll.find_one({"_id": self.id_Profile})
self.ProfileLogin = Profile.get("firstname")
self.ProfileEmail = Profile.get("email")
if Profile:
print("login", self.ProfileLogin)
print("Email", self.ProfileEmail)
else:
print("User not dound")
#Перенос окна по используя frame в методах mouse press and event
self.header_frame.move(0, 0)
self.header_frame.show()
#Работа с кнопкой профиль
self.layout = QVBoxLayout()
self.layout.addWidget(self.pushButtonProfile)
self.setLayout(self.layout)
self.pushButtonProfile.clicked.connect(self.on_button_clicked)
self.animation = QPropertyAnimation(self.pushButtonProfile, b"size")
self.animation.setDuration(600)
self.is_expanded = False
def on_button_clicked(self):
if self.animation.state() == QAbstractAnimation.State.Stopped:
if not self.is_expanded:
# Увеличение кнопки при нажатии
self.animation.setStartValue(QSize(self.pushButtonProfile.width(), 51))
self.animation.setEndValue(QSize(self.pushButtonProfile.width(), 115))
self.animation.start()
self.pushButtonProfile.setText("")
timer = QTimer()
timer.singleShot(500, self.AppealProfileLabelVisibility)
print('Увеличилась')
self.is_expanded = True
else:
# Уменьшение кнопки при нажатии
self.animation.setStartValue(QSize(self.pushButtonProfile.width(), 115))
self.animation.setEndValue(QSize(self.pushButtonProfile.width(), 51))
self.animation.start()
# Добавление контента внутри кнопки
timer = QTimer()
timer.singleShot(0, self.AppealProfileLabelHide)
print('Уменьшилась')
self.is_expanded = False
def AppealProfileLabelVisibility(self):
self.label_ProfileLogo.setStyleSheet('background-color:transparent;color:white;')
self.label_ProfileName.setStyleSheet('background-color:transparent;color:white;')
self.label_ProfileEmail.setStyleSheet('background-color:transparent;color:white;')
self.label_ProfileSub.setStyleSheet('background-color:transparent;color:white;')
self.label_EnterProfileName.setText(self.ProfileLogin)
self.label_EnterProfileEmail.setText(self.ProfileEmail)
self.label_EnterProfileName.setStyleSheet('background-color:transparent;color:white;')
self.label_EnterProfileEmail.setStyleSheet('background-color:transparent;color:white;')
def AppealProfileLabelHide(self):
self.pushButtonProfile.setText("Profile")
self.label_ProfileLogo.setStyleSheet('background-color:transparent;color:transparent;')
self.label_ProfileName.setStyleSheet('background-color:transparent;color:transparent;')
self.label_ProfileEmail.setStyleSheet('background-color:transparent;color:transparent;')
self.label_ProfileSub.setStyleSheet('background-color:transparent;color:transparent;')
self.label_EnterProfileName.setText("")
self.label_EnterProfileEmail.setText("")
self.label_EnterProfileName.setStyleSheet('background-color:transparent;color:transparent;')
self.label_EnterProfileEmail.setStyleSheet('background-color:transparent;color:transparent;')
def download(self):
self.ui = Class.download.Download()
self.ui.show()
self.hide()
def PushBack(self):
self.ui = main.MainWindows()
self.ui.show()
self.hide()
def mousePressEvent(self, event: QMouseEvent) -> None:
if event.button() == Qt.MouseButton.LeftButton and self.header_frame.underMouse():
self.offset = event.pos()
else:
self.offset = None
def mouseMoveEvent(self, event: QMouseEvent) -> None:
if self.offset is not None and event.buttons() == Qt.MouseButton.LeftButton and self.header_frame.underMouse():
self.move(self.mapToGlobal(event.pos() - self.offset))
else:
self.offset = None