0

SignIn.py

from PyQt5 import QtCore, QtGui, QtWidgets
from HomePage import Ui_HomePage
from PyQt5.QtWidgets import QMessageBox
import cx_Oracle

class Ui_SignIn(object):
    def openConnection(self):
        con=cx_Oracle.connect('lab/oracle@localhost:1521/xe')

    def showMessageBox(self,title,message):
        #QMessageBox.about(self, "Title", "Message")
        msgBox = QtWidgets.QMessageBox()
        msgBox.setIcon(QtWidgets.QMessageBox.Warning)
        msgBox.setWindowTitle(title)
        msgBox.setText(message)
        msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
        msgBox.exec_()

    def loginCheck(self):
        username = self.ledt_username.text()
        password = self.ledt_password.text()
        #print(username)
        #print(password)
        con=cx_Oracle.connect('lab/oracle@localhost:1521/xe')
        cur=con.cursor()
        cur.execute('select * from user_tbl where username=:1 and password=:2', (username, password))
        #cur.execute('select * from user_tbl')
        cur.fetchall()
        #n=0
        #for result in cur:
            #n=n+1
        #m=cur.rowcount
        #print(n)
        #print(m)
        if(cur.rowcount > 0):
            print("User Found ! ")
            Dialog.hide()
            self.welcomeWindowShow()
        else:
            print("User Not Found !")
            #self.showMessageBox()
            self.showMessageBox('Warning','Invalid Username And Password')
            #self.welcomeWindowShow()
        con.close()

    def welcomeWindowShow(self):
        self.window=QtWidgets.QDialog()
        self.ui=Ui_HomePage()
        self.ui.setupUi(self.window)
        self.window.show()

    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(690, 450)
        Dialog.setBaseSize(QtCore.QSize(0, 0))
        self.lbl_username = QtWidgets.QLabel(Dialog)
        self.lbl_username.setGeometry(QtCore.QRect(250, 100, 61, 21))
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.lbl_username.setFont(font)
        self.lbl_username.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.lbl_username.setAutoFillBackground(False)
        self.lbl_username.setObjectName("lbl_username")
        self.ledt_username = QtWidgets.QLineEdit(Dialog)
        self.ledt_username.setGeometry(QtCore.QRect(330, 100, 141, 21))
        self.ledt_username.setObjectName("ledt_username")
        self.lbl_password = QtWidgets.QLabel(Dialog)
        self.lbl_password.setGeometry(QtCore.QRect(250, 150, 71, 21))
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.lbl_password.setFont(font)
        self.lbl_password.setAutoFillBackground(False)
        self.lbl_password.setObjectName("lbl_password")
        self.ledt_password = QtWidgets.QLineEdit(Dialog)
        self.ledt_password.setGeometry(QtCore.QRect(330, 150, 141, 20))
        self.ledt_password.setObjectName("ledt_password")
        self.pbtn_signin = QtWidgets.QPushButton(Dialog)
        self.pbtn_signin.setGeometry(QtCore.QRect(270, 200, 75, 23))
        self.pbtn_signin.setObjectName("pbtn_signin")
        ############## logincheck calling ######
        self.pbtn_signin.clicked.connect(self.loginCheck)
        ###################################################
        self.pbtn_signup = QtWidgets.QPushButton(Dialog)
        self.pbtn_signup.setGeometry(QtCore.QRect(380, 200, 75, 23))
        self.pbtn_signup.setObjectName("pbtn_signup")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.lbl_username.setText(_translate("Dialog", "Username"))
        self.lbl_password.setText(_translate("Dialog", "Password"))
        self.pbtn_signin.setText(_translate("Dialog", "Sign In"))
        self.pbtn_signup.setText(_translate("Dialog", "Sign Up"))

   # from HomePage import Ui_HomePage


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_SignIn()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

HomePage.py

from PyQt5 import QtCore, QtGui, QtWidgets
#from SignIn import Ui_SignIn

class Ui_HomePage(object):
    def importSignIn(self):
        from SignIn import Ui_SignIn

    def signInWindowShow(self):
        Dialog.hide()
        from SignIn import Ui_SignIn
        self.window=QtWidgets.QDialog()
        self.ui=Ui_SignIn()
        self.ui.setupUi(self.window)
        self.window.show()
        #self.Dialog.hide()

    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(696, 395)
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(210, 50, 161, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.pushButton = QtWidgets.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(300, 220, 75, 23))
        self.pushButton.setObjectName("pushButton")
        ############## logincheck calling ######
        self.pushButton.clicked.connect(self.signInWindowShow)
        ###################################################
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.label.setText(_translate("Dialog", "Welcome"))
        self.pushButton.setText(_translate("Dialog", "Logout"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_HomePage()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

The error I am getting while running

Getting an error while trying to close and open current dialog window in python I need to open and close two windows in loop.

also attaching the error that i got.

enter image description here

2
  • removed unneeded text and inlined an image for you but it is preferred you add the text of the error message in your question. Commented Aug 5, 2018 at 10:16
  • Dialog is not defined in loginCheck ,is it? Commented Aug 5, 2018 at 10:35

1 Answer 1

0

The reason of the error is that Dialog is not available in scope of loginCheck method and need to be passed explicitly as a param in the following line:

self.pbtn_signin.clicked.connect(self.loginCheck)

Here is the question with the answers, how to do it.

One of the options would be import partial from functools:

from functools import partial

And use this function to pass Dialog to loginCheck:

self.pbtn_signin.clicked.connect(partial(self.loginCheck, Dialog))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.