import sys from os.path import join from PyQt5 import QtWidgets, QtGui from database import dbuser class mainWindow(QtWidgets.QMainWindow): VERSION = 0.1 def __init__(self): super(mainWindow, self).__init__() logo = join("./ressources", "icon.ico") self.setWindowIcon(QtGui.QIcon(logo)) menu = self.menuBar() menu_options = menu.addMenu("Options") btn_apropos = QtWidgets.QAction("A propos", self) btn_apropos.triggered.connect(self.a_propos) menu_options.addAction(btn_apropos) self.setWindowTitle("Alphajob") self.home() def home(self): self.label1 = QtWidgets.QLabel("Home page") btn1 = QtWidgets.QPushButton("Aller à la page de connexion") btn1.clicked.connect(self.page_login) self.layoutMain = QtWidgets.QVBoxLayout() self.layoutMain.addWidget(self.label1) self.layoutMain.addWidget(btn1) if hasattr(self, "mainWidget"): self.mainWidget.deleteLater() self.mainWidget = QtWidgets.QWidget() self.mainWidget.setLayout(self.layoutMain) self.setCentralWidget(self.mainWidget) self.show() def page_login(self): btnAccueil = QtWidgets.QPushButton("Accueil") btnAccueil.clicked.connect(self.home) self.emailConnexion = QtWidgets.QLineEdit("Email") self.passwordConnexion = QtWidgets.QLineEdit("Password") btnConnexion = QtWidgets.QPushButton("Connexion") btnConnexion.clicked.connect(self.login) self.layoutMain = QtWidgets.QVBoxLayout() self.layoutNavigation = QtWidgets.QHBoxLayout() self.layoutPassword = QtWidgets.QHBoxLayout() self.layoutPasswordWidgets = QtWidgets.QVBoxLayout() self.layoutMain.addLayout(self.layoutNavigation) self.layoutNavigation.addWidget(btnAccueil) self.layoutNavigation.addStretch() self.layoutMain.addLayout(self.layoutPassword) self.layoutPassword.addStretch() self.layoutPassword.addLayout(self.layoutPasswordWidgets) self.layoutPassword.addStretch() self.layoutPasswordWidgets.addWidget(self.emailConnexion) self.layoutPasswordWidgets.addWidget(self.passwordConnexion) self.layoutPasswordWidgets.addWidget(btnConnexion) self.mainWidget.deleteLater() self.mainWidget = QtWidgets.QWidget() self.mainWidget.setLayout(self.layoutMain) self.setCentralWidget(self.mainWidget) def login(self): user = dbuser.DbUser() if user.check_exist_email(self.emailConnexion.text()): res = user.check_user_credential( self.emailConnexion.text(), self.passwordConnexion.text() ) if res: QtWidgets.QMessageBox.information( self, "Connexion", "Vous êtes connecté" ) else: QtWidgets.QMessageBox.warning( self, "Connexion", "Mauvaise combinaison mail & mot de passe" ) else: QtWidgets.QMessageBox.warning( self, "Connexion", "Mauvais email" ) def a_propos(self): QtWidgets.QMessageBox.information( self, "A propos", "Logiciel pour mon dossier professionnel.\
Version: %s\
Auteur: Debulois Quentin\
Code source: \ git.debulois.fr/" % self.VERSION ) if __name__ == "__main__": def main(): """Démarrage de l'app """ app = QtWidgets.QApplication(sys.argv) GUI = mainWindow() sys.exit(app.exec_()) main()