Python Forum
[PyQt] [Solved]Help Getting Started on Scene Swapping
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] [Solved]Help Getting Started on Scene Swapping
#9
try this

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox
 
from DataBases.UserDatabase import StandardUsers, SuperUsers
 
from Test import Ui_MainDisplay
 
class Ui_Loginscreen(QtWidgets.QMainWindow):
    def __init__(self, parent = None):
        super(Ui_Loginscreen, self).__init__(parent)
        self.setObjectName("Loginscreen")
        self.resize(1108, 895)
        self.setStyleSheet("background-color: rgb(0, 170, 255);")
        self.centralwidget = QtWidgets.QWidget()
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.Header = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.Header.setFont(font)
        self.Header.setAlignment(QtCore.Qt.AlignCenter)
        self.Header.setObjectName("Header")
        self.gridLayout.addWidget(self.Header, 0, 0, 1, 1)
        self.formLayout_2 = QtWidgets.QFormLayout()
        self.formLayout_2.setObjectName("formLayout_2")
        self.NameLabel = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.NameLabel.setFont(font)
        self.NameLabel.setObjectName("NameLabel")
        self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.NameLabel)
        self.NameInput = QtWidgets.QLineEdit(self.centralwidget)
        self.NameInput.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.NameInput.setText("")
        self.NameInput.setObjectName("NameInput")
        self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.NameInput)
        self.PasswordLabel = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.PasswordLabel.setFont(font)
        self.PasswordLabel.setObjectName("PasswordLabel")
        self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.PasswordLabel)
        self.PasswordInput = QtWidgets.QLineEdit(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Wingdings")
        self.PasswordInput.setFont(font)
        self.PasswordInput.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.PasswordInput.setText("")
        self.PasswordInput.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
        self.PasswordInput.setObjectName("PasswordInput")
        self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.PasswordInput)
        self.label = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(8)
        font.setItalic(True)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.label)
        spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.formLayout_2.setItem(3, QtWidgets.QFormLayout.FieldRole, spacerItem)
        self.LoginButton = QtWidgets.QPushButton(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.LoginButton.setFont(font)
        self.LoginButton.setStyleSheet("background-color: rgb(211, 211, 211);\n"
"border-style: outset;\n"
"border-width: 2px;\n"
"border-radius: 15px;\n"
"border-color: black;\n"
"padding: 4px;\n"
"")
        self.LoginButton.setObjectName("LoginButton")
        self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.LoginButton)
        self.gridLayout.addLayout(self.formLayout_2, 1, 0, 1, 1)
        self.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar()
        self.statusbar.setObjectName("statusbar")
        self.setStatusBar(self.statusbar)
 
        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self)
 
    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("Loginscreen", "E.I.S"))
        self.Header.setText(_translate("Loginscreen", "Electronic Inventory System (E.I.S)"))
        self.NameLabel.setText(_translate("Loginscreen", "Name"))
        self.PasswordLabel.setText(_translate("Loginscreen", "Password"))
        self.label.setText(_translate("Loginscreen", "\n"
"\n"
"\n"
"\n"
"Electronic Inventory System (E.I.S)\n"
"Version: 2.6\n"
"Developed By: Paglia Industries\n"
"Last Updated: 05/11/2022\n"
"\n"
"\n"
""))
        self.LoginButton.setText(_translate("Loginscreen", "Log In"))
 
        #------------------------------------------
                        #Actions
        #------------------------------------------
        #When the Login button is clicked -> LoginClicked Function
        LoginButton = self.LoginButton
        LoginButton.clicked.connect(self.LoginClicked)
        #------------------------------------------
#----------------------------------
    #Store Name and Password
    def LoginClicked(self):
        userInputName = self.NameInput.text()
        userInputPassword = self.PasswordInput.text()
        #Print in terminal for testing:
        print("The Login Button was clicked")
        print("Name: " + userInputName)
        print("Password: " + userInputPassword)
 
        #Validate Login Info
        if StandardUsers().get(userInputName) == userInputPassword:
            print('Success! You are now logged in as: ' + userInputName)
            #Switch from this screen to the MainMenu Screen
            #mainMenu()
 
        if SuperUsers().get(userInputName) == userInputPassword:
            print('Success! You are now logged in as: ' + userInputName)
            #Switch from this screen to the AdminMenu Screen
            #adminMenu()
 
            #Scene Swap Test:
            self.win = Ui_MainDisplay.Ui_MainDisplay()
            self.win.show()
            self.close()
 
        else:
            #Call Invalid Credentials Popup
            self.invalidCredentials()
            print('You are not registered to use this program')
#----------------------------------
#-----------------------------------------------------------------
    #Invalid Credentails Popup:
    def invalidCredentials(self):
        msgBox = QMessageBox()
        msgBox.setIcon(QMessageBox.Critical)
        msgBox.setText("You are not registered to use this program")
        msgBox.setWindowTitle("Invalid Credentials")
        msgBox.setStandardButtons(QMessageBox.Ok)
        msgBox.buttonClicked.connect(msgButtonClick)
 
        returnValue = msgBox.exec()
        if returnValue == QMessageBox.Ok:
            print('OK was clicked')
         
def msgButtonClick(i):
    print("Button clicked is:",i.text())
#-----------------------------------------------------------------
 
 
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ui = Ui_Loginscreen()
    ui.show()
    sys.exit(app.exec_())
Reply


Messages In This Thread
RE: Help Getting Started on Scene Swapping - by Axel_Erfurt - May-14-2022, 09:26 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020