def loginCheck1(self): print("signin clicked") from login import Ui_Dialog self.login = QtWidgets.QDialog() self.ui = Ui_Dialog() self.ui.setupUi(self.login) # self. Dialog1.hide() #error=AttributeError: 'Ui_Dialog1' object has no attribute 'Dialog1' self.login.show()
def __init__(self): super(Login, self).__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.notificacion = False self.setSignals() self.show()
def signInCheck(self): print("hello signin button") self.signInWindow = QtGui.QDialog() self.ui = Ui_Dialog() print("i'm in self signin") self.ui.setinUi(self.signInWindow) print("i'm in self setupUi method") self.signInWindow.show() print("i'm in self signin windows")
def configLoginDialog(self): self.Dialog = QtWidgets.QDialog() self.ui_login = Ui_Dialog() self.ui_login.setupUi(self.Dialog) self.ui_login.btn_register.clicked.connect(self.registerUser) self.ui_login.btn_login.clicked.connect(self.login) self.ui_main.actionLog_in.triggered.connect(self.Dialog.show) if not hasattr(self, "user"): self.MainWindow.hide() self.Dialog.show()
def __init__(self, ac_mgt=None): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.browser = WebEngineView(self) # self.ui.browser.page().runJavaScript(js_input_func) self.ui.browser_layout.addWidget(self.ui.browser) self.ac_mgt = ac_mgt or AccountManagement('', '') self.ac = self.ac_mgt.next() or Account() self.update_curr_ac(self.ac) auto_connect(self, self.ui)
def login(self): dia = QtWidgets.QDialog() lgin = Ui_Dialog() lgin.setupUi(dia, self) dia.show() dia.exec() if self.menu.to_login(self.username, self.passwd): utils.notify('登录成功') self.pushButton_2.setStyleSheet \ ("background-color:#99FFFF;border:2px groove gray;border-radius:10px;padding:2px 4px;") self.pushButton_2.setText(self.menu.user['nickname']) else: utils.notify('登录失败,请重新登录')
def signUpCheck(self): print("hello signup button") self.signUpWindow = QtGui.QDialog() self.ui = Ui_signUp() print("i'm in self signup") self.ui.setupUi(self.signUpWindow) print("i'm in self setupUi method") self.signUpWindow.show() print("i'm in self signup windows")
def __init__(self, parent=None): super(Login, self).__init__(parent) self.ui = Login_Dialog() self.ui.setupUi(self) self.oldPos = self.pos() self.setWindowIcon(QtGui.QIcon('src/python.png')) self.ui.pushButton.clicked.connect(self.trylogin)
class choosefunction(QtWidgets.QMainWindow): def __init__(self): QtWidgets.QMainWindow.__init__(self) self.ui = Ui_Dialog() self.ui.setupUi(self) QMessageBox.critical(self, '错误', '用户名或密码错误') #初始化当选框 # self.ui.login.clicked.connect(self.a1) # self.ui.Scan.clicked.connect(self.test) # self.ui.loginButton.clicked.connect(self.query_formula) # # 给button 的 点击动作绑定一个事件处理函数 # self.ui.lineEdit_2.returnPressed.connect(self.log_returnPressed) def a1(self): QMessageBox.critical(self, '错误', '用户名或密码错误') def test(self): #单选框逻辑处理 if self.ui.localAddress.isChecked(): print(self.ui.AddressText.text()) elif self.ui.NetWorkAddress.isChecked(): print(self.ui.NetWorkAddress_2.text()) elif self.ui.localAddressS.isChecked(): print(self.ui.AddressTextS.text())
if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) from login import Ui_Dialog as UiLogin DialogLogin = QtWidgets.QDialog() uiLogin = UiLogin() uiLogin.setupUi(DialogLogin) uiLogin.label.setText("Enter Your Username") uiLogin.buttonBox.accepted.connect(getUsername) DialogLogin.exec() DialogLogin.show() file_path = filedialog.askopenfilename() file_extension = file_path.split('.') file_extension = file_extension[1] accepted_file_extensions = ['jpeg', 'jpg', 'png', 'bmp'] if file_extension not in accepted_file_extensions: uiLogin.label.setText('.'+file_extension + ' is not acceptable !')
class Ui_MainWindow(object): def signUpButton(self): self.signUpCheck() def signInButton(self): self.signInCheck() def signUpCheck(self): print("hello signup button") self.signUpWindow = QtGui.QDialog() self.ui = Ui_signUp() print("i'm in self signup") self.ui.setupUi(self.signUpWindow) print("i'm in self setupUi method") self.signUpWindow.show() print("i'm in self signup windows") def signInCheck(self): print("hello signin button") self.signInWindow = QtGui.QDialog() self.ui = Ui_Dialog() print("i'm in self signin") self.ui.setinUi(self.signInWindow) print("i'm in self setupUi method") self.signInWindow.show() print("i'm in self signin windows") def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWin41dow")) MainWindow.resize(1300, 800) MainWindow.setStyleSheet( _fromUtf8("\n" "background-image: url(hgr2.jpg);\n" "")) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) ############################################################################# self.sign_up1 = QtGui.QPushButton(self.centralwidget) self.sign_up1.setGeometry(QtCore.QRect(200, 30, 200, 35)) self.sign_up1.setObjectName(_fromUtf8("sign_up1")) self.sign_up1.setStyleSheet("background-color: black") ############################################################################## self.sign_up1.clicked.connect(self.signUpButton) ################################################################################### self.sign_in1 = QtGui.QPushButton(self.centralwidget) self.sign_in1.setGeometry(QtCore.QRect(500, 30, 200, 35)) self.sign_in1.setObjectName(_fromUtf8("sign_in1")) self.sign_in1.setStyleSheet("background-color: black") ############################################################################## self.sign_in1.clicked.connect(self.signInButton) ################################################################################### MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle( _translate("MainWindow", "TWO WAY COMMUNICATION SYSTEM", None)) self.sign_up1.setText(_translate("MainWindow", "REGISTER", None)) self.sign_in1.setText(_translate("MainWindow", "LOGIN", None))
class LoginDialog(QDialog): def __init__(self, ac_mgt=None): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.browser = WebEngineView(self) # self.ui.browser.page().runJavaScript(js_input_func) self.ui.browser_layout.addWidget(self.ui.browser) self.ac_mgt = ac_mgt or AccountManagement('', '') self.ac = self.ac_mgt.next() or Account() self.update_curr_ac(self.ac) auto_connect(self, self.ui) def set_curr_ac(self, ac): self.ac = ac or Account() self.update_curr_ac(ac) def set_account_data(self, ac_mgt: AccountManagement): self.ac_mgt = ac_mgt or AccountManagement('', '') self.ac = self.ac_mgt.next() or Account() self.update_curr_ac(self.ac) def set_url(self, url): self.ui.url.setText(str(url)) def set_cookies_path(self, path): self.ui.cookies_dir.setText(path) def set_ac_path(self, path): self.ui.id_path.setText(path) def update_curr_ac(self, ac): if isinstance(ac, Account): self.ui.id.setText(str(ac.id)) self.ui.pwd.setText(str(ac.password)) self.ui.cookies_file_name.setText(ac.cookies_file_name) @wrap_exception def next_btn_clicked(self): self.ac.set_cookies(self.ui.browser.get_cookie()) self.ui.browser.deleteAllCookies() self.ui.browser.load(QUrl(self.ui.url.text())) ac = self.ac_mgt.next() if not ac: QMessageBox.warning(self, '警告', '没有下一个了') self.set_curr_ac(ac) @wrap_exception def save_btn_clicked(self): self.ac_mgt.save() @wrap_exception def close_btn_clicked(self): self.close() @wrap_exception def load_btn_clicked(self): ac_path = self.ui.id_path.text() cookies_dir = self.ui.cookies_dir.text() if os.path.isfile(ac_path) and os.path.isdir(cookies_dir): self.set_account_data(AccountManagement(ac_path, cookies_dir)) self.ui.browser.deleteAllCookies() self.ui.browser.load(QUrl(self.ui.url.text())) @wrap_exception def cookies_dir_editingFinished(self): self.ac_mgt.set_cookies_dir(self.ui.cookies_dir.text()) @wrap_exception def cookies_file_name_editingFinished(self): name = self.ui.cookies_file_name.text() if is_file_name(name): QMessageBox.warning(self, '错误', '请输入有效文件名') return self.ac.set_cookies_file(name)
def __init__(self): super(MainClass, self).__init__() self.uilog = Ui_Dialog() self.uilog.setupUi(self) self.uilog.pb_login.clicked.connect(self.loginCheck)
class Login(QtWidgets.QDialog): def __init__(self, parent=None): super(Login, self).__init__(parent) self.ui = Login_Dialog() self.ui.setupUi(self) self.oldPos = self.pos() self.setWindowIcon(QtGui.QIcon('src/python.png')) self.ui.pushButton.clicked.connect(self.trylogin) def close(self): self.hide() def center(self): qr = self.frameGeometry() cp = QtWidgets.QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def mousePressEvent(self, event): self.oldPos = event.globalPos() def mouseMoveEvent(self, event): delta = QtCore.QPoint(event.globalPos() - self.oldPos) self.move(self.x() + delta.x(), self.y() + delta.y()) self.oldPos = event.globalPos() def trylogin(self): with pymongo.MongoClient(myserver) as conn: try: db = conn.get_database("PyProject") found = db.Users.count_documents( {"Username": self.ui.lineEdit.text()}) if found > 0: users = {} cur = db.Users.find_one( {"Username": self.ui.lineEdit.text()}) try: newkey = hashlib.pbkdf2_hmac( 'sha256', self.ui.lineEdit_2.text().encode('utf-8'), salt.encode(), 100000) if cur['Password'] == binascii.hexlify( newkey).decode(): msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Information) msg.setWindowTitle("Success") msg.setText( f"Login Complete! - Welcome {cur['Username']}") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec_() self.parent().ui.login = True self.hide() else: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setWindowTitle("Warnning") msg.setText("Username / Password Incorrect") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec_() except Exception as e: print(e) else: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setWindowTitle("Warnning") msg.setText("Username / Password Incorrect") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec_() except Exception as e: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setWindowTitle("Error") msg.setText(e) msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec_()
import sqlite3 from PyQt5 import QtCore, QtGui, QtWidgets from singup import signUp_Dialog from login import Ui_Dialog if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_())
class Login(QtGui.QDialog): def __init__(self): super(Login, self).__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.notificacion = False self.setSignals() self.show() def setSignals(self): self.ui.btn_Entrar.clicked.connect(self.login) self.ui.btn_recordar_contrasena.clicked.connect( self.recordar_contrasena) def login(self): input_usuario = self.ui.le_usuario.text().lstrip() input_contrasena = self.ui.le_contrasena.text().lstrip() if (input_usuario == "" or input_contrasena == ""): controlador_login.correctMessage(self, "Existen campos en blanco") else: clave_encriptada = controlador_login.encriptar_clave( input_contrasena) resultado = controlador_login.buscaTrabajador( self, input_usuario, clave_encriptada) if (resultado == None): controlador_login.errorMessage(self, "Datos invalidos") else: if (len(resultado) > 0): if (self.notificacion == True): controlador_login.registrarIngreso(input_usuario) self.menu = Menu(resultado[0]) self.menu.show() self.close() self.recordar_contrasena = Recordar_Contrasena( resultado[0]) self.recordar_contrasena.exec_() self.notificacion = False else: controlador_login.registrarIngreso(input_usuario) self.menu = Menu(resultado[0]) self.menu.show() self.close() def recordar_contrasena(self): rut_trabajador = self.ui.le_usuario.text().lstrip() trabajador = controlador_login.buscaTrabajadorPorRut( self, rut_trabajador) if (trabajador != None): # ENVIO CORREO ELECTRONICO CON SMTPLIB self.notificacion = True #Booleano para saber si se recupero contraseña o no, y pedir nueva contraseña al inciar el sistema. email_trabajador = trabajador[3] clave_generada = controlador_login.generar_clave() controlador_login.correctMessage( self, "Clave enviada al correo electronico") controlador_login.enviar_email(email_trabajador, clave_generada) controlador_login.modificar_clave(rut_trabajador, clave_generada) # ENVIO SMS CON TWILIO # account_sid = "AC6c5ab8dd17c29e38dae1442aeb88c0d0" # auth_token = "85820a2f9cd30c197f6ea7c1291c68e5" # client = Client(account_sid, auth_token) # message = client.messages.create(to="+56982655627", from_="+56945950795", body="HOLAAA") # print(message.sid) else: controlador_login.errorMessage(self, "Datos Invalidos")
class Ui_signUp(object): def insertData(self): username1 = self.uname_lineEdit.text() username = str(username1) email1 = self.email_lineEdit.text() email = str(email1) mob1 = self.mob_lineEdit.text() mob = str(mob1) password1 = self.password_lineEdit.text() password = str(password1) gender1 = self.gender_lineEdit.text() gender = str(gender1) connection = sqlite3.connect("sign.db") s = "insert into registration (username,email,mob,password,gender) values('" + username + "','" + email + "','" + mob + "','" + password + "','" + gender + "')" print("query is:-" + s) result = connection.execute(s) if result: s1 = "select * from registration" result = connection.execute(s1) print("Success" + s1) connection.commit() connection.close() self.showmsg() def showmsg(self): self.showdialog() def showdialog(self): msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setText("Registration Status") msg.setInformativeText("Registration Successful") msg.setWindowTitle("Status") # msg.setDetailedText("The details are as follows:") msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) retval = msg.exec_() print "value of pressed message box button:", retval def signInCheck(self): print("hello signin button") self.signInWindow = QtGui.QDialog() self.ui = Ui_Dialog() print("i'm in self signin") self.ui.setinUi(self.signInWindow) print("i'm in self setupUi method") self.signInWindow.show() print("i'm in self signin windows") def signInButton(self): self.signInCheck() def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(1300, 800) Dialog.setStyleSheet( _fromUtf8("\n" "background-image: url(hgr2.jpg);\n" "")) ############################################################################# self.label = QtGui.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(100, 100, 91, 20)) self.label.setObjectName(_fromUtf8("label")) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label_2 = QtGui.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(100, 150, 91, 20)) self.label_2.setObjectName(_fromUtf8("label_2")) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label_2.setFont(font) self.label_M = QtGui.QLabel(Dialog) self.label_M.setGeometry(QtCore.QRect(100, 200, 91, 20)) self.label_M.setObjectName(_fromUtf8("label_M")) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label_M.setFont(font) self.label_3 = QtGui.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(100, 250, 91, 20)) self.label_3.setObjectName(_fromUtf8("label_3")) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label_3.setFont(font) self.label_G = QtGui.QLabel(Dialog) self.label_G.setGeometry(QtCore.QRect(100, 300, 91, 20)) self.label_G.setObjectName(_fromUtf8("label_G")) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label_G.setFont(font) ############################################################# self.uname_lineEdit = QtGui.QLineEdit(Dialog) self.uname_lineEdit.setGeometry(QtCore.QRect(210, 100, 211, 27)) self.uname_lineEdit.setObjectName(_fromUtf8("uname_lineEdit")) self.email_lineEdit = QtGui.QLineEdit(Dialog) self.email_lineEdit.setGeometry(QtCore.QRect(210, 150, 211, 27)) self.email_lineEdit.setObjectName(_fromUtf8("email_lineEdit")) self.mob_lineEdit = QtGui.QLineEdit(Dialog) self.mob_lineEdit.setGeometry(QtCore.QRect(210, 200, 211, 27)) self.mob_lineEdit.setObjectName(_fromUtf8("mob_lineEdit")) self.password_lineEdit = QtGui.QLineEdit(Dialog) self.password_lineEdit.setGeometry(QtCore.QRect(210, 250, 211, 27)) self.password_lineEdit.setObjectName(_fromUtf8("password_lineEdit")) self.gender_lineEdit = QtGui.QLineEdit(Dialog) self.gender_lineEdit.setGeometry(QtCore.QRect(210, 300, 211, 27)) self.gender_lineEdit.setObjectName(_fromUtf8("gender_lineEdit")) ################################################################### self.label_4 = QtGui.QLabel(Dialog) self.label_4.setGeometry(QtCore.QRect(217, 19, 191, 51)) font = QtGui.QFont() font.setPointSize(15) font.setBold(True) font.setWeight(75) self.label_4.setFont(font) self.label_4.setObjectName(_fromUtf8("label_4")) self.signup_btn = QtGui.QPushButton(Dialog) self.signup_btn.setGeometry(QtCore.QRect(210, 350, 91, 27)) self.signup_btn.setObjectName(_fromUtf8("signup_btn")) self.signup_btn.setStyleSheet("background-color: black") #########################EVENT############## self.signup_btn.clicked.connect(self.insertData) ############################################ self.login_btn = QtGui.QPushButton(Dialog) self.login_btn.setGeometry(QtCore.QRect(328, 350, 91, 27)) self.login_btn.setObjectName(_fromUtf8("login_btn")) self.login_btn.setStyleSheet("background-color: black") self.login_btn.clicked.connect(self.signInButton) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Dialog", None)) self.label.setText(_translate("Dialog", "USERNAME", None)) self.label_2.setText(_translate("Dialog", "EMAIL ID", None)) self.label_M.setText(_translate("Dialog", "MOBILE", None)) self.label_3.setText(_translate("Dialog", "PASSWORD", None)) self.label_G.setText(_translate("Dialog", "GENDER", None)) self.label_4.setText(_translate("Dialog", "Registration Form", None)) self.signup_btn.setText(_translate("Dialog", "REGISTER", None)) self.login_btn.setText(_translate("Dialog", "LOGIN", None))
class EventHandler(object): def openMainWindow(self): app = QtWidgets.QApplication(sys.argv) self.MainWindow = QtWidgets.QMainWindow() self.ui_main = Ui_MainWindow() self.ui_main.setupUi(self.MainWindow) self.ui_main.actionLog_in.triggered.connect(self.MainWindow.hide) self.ui_main.btn_fileUpload.clicked.connect(self.selectUploadFile) self.ui_main.btn_filesUpload.clicked.connect(self.selectUploadFiles) self.ui_main.btn_dirUpload.clicked.connect(self.selectUploadDir) self.ui_main.btn_fileDownload.clicked.connect(self.selectFileDownload) self.MainWindow.show() self.configLoginDialog() sys.exit(app.exec_()) def configLoginDialog(self): self.Dialog = QtWidgets.QDialog() self.ui_login = Ui_Dialog() self.ui_login.setupUi(self.Dialog) self.ui_login.btn_register.clicked.connect(self.registerUser) self.ui_login.btn_login.clicked.connect(self.login) self.ui_main.actionLog_in.triggered.connect(self.Dialog.show) if not hasattr(self, "user"): self.MainWindow.hide() self.Dialog.show() def registerUser(self): name = self.ui_login.txt_name.text() password = self.ui_login.txt_password.text() TCPClient().send(("addUser", (name, password))) def login(self): name = self.ui_login.txt_name.text() password = self.ui_login.txt_password.text() user = TCPClient().send(("getUserByName", (name,))) if user != None and user[2] == password: self.user = user self.MainWindow.show() self.Dialog.close() self.showUserListTable() return True else: return False def showUserListTable(self): users = TCPClient().send(("getUsers",())) print(users) try: if users != None: index = 0 for user in users: self.createUserListTableRow(index, user) index += 1 except Exception as e: print("Show user list table failed.", e) def createUserListTableRow(self, index, user): # set table row count _translate = QtCore.QCoreApplication.translate self.ui_main.userList_table.setRowCount(index + 1) # set vertical item # item = QtWidgets.QTableWidgetItem() # self.ui_main.userList_table.setVerticalHeaderItem(index, item) # item = self.ui_main.userList_table.verticalHeaderItem(index) # item.setText(_translate("MainWindow", str(index))) # set row item item = QtWidgets.QTableWidgetItem() self.ui_main.userList_table.setItem(index, 0, item) # item = self.ui_main.userList_table.item(index, 0) item.setText(_translate("MainWindow", user[1])) # set row item item = QtWidgets.QTableWidgetItem() self.ui_main.userList_table.setItem(index, 1, item) # item = self.ui_main.userList_table.item(index, 1) item.setText(_translate("MainWindow", user[2])) def analysisFile(self, lines): client = TCPClient() for line in lines: client.send(("analysisFile", (line,)), self.analysisFileCallBack) def analysisFileCallBack(self, params): print(params) def selectUploadFile(self): try: fileName1, filetype = QFileDialog.getOpenFileName(self.MainWindow, "选取文件", os.path.realpath("/"), "Log Files (*.log)") #设置文件扩展名过滤,注意用双分号间隔 print(fileName1, filetype) file = open(fileName1) lines = file.readlines() # self.analysisFile(lines) Thread(target=self.analysisFile, args=(lines,)).start() except Exception as e: print(e) def selectUploadFiles(self): try: files, ok1 = QFileDialog.getOpenFileNames(self.MainWindow, "多文件选择", os.path.realpath("/"), "All Files (*);;Text Files (*.log);;Text Files (*.txt)") print(files, ok1) except Exception as e: print(e) def selectUploadDir(self): try: directory1 = QFileDialog.getExistingDirectory(self.MainWindow, "选取文件夹", os.path.realpath("/")) #起始路径 print(directory1) except Exception as e: print(e) def selectFileDownload(self): try: fileName2, ok2 = QFileDialog.getSaveFileName(self.MainWindow, "文件保存", os.path.realpath("/"), "All Files (*);;Text Files (*.log);;Text Files (*.txt)") print(fileName2, ok2) except Exception as e: print(e)
class Ui_Dialog1(object): def isValidEmail(email): if len(email) > 7: if re.match( "^.+@([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$", email) != None: return True else: return False #else: # return False def signupCheck1(self): username = self.lineEdit.text() # password=self.pass1_lineEdit.text() connection = sqlite3.connect("login.db") result = connection.execute("SELECT * FROM USERS WHERE USERNAME=?", (username, )) if (len(result.fetchall()) > 0): print("Username already exists..!") else: email = self.lineEdit_2.text() if ( (self.isValidEmail(email)) == True ): #TypeError: isValidEmail() takes 1 positional argument but 2 were given print("This is a valid email address") connection = sqlite3.connect("login.db") username = self.lineEdit.text() email = self.lineEdit_2.text() password = self.lineEdit_4.text() cpassword = self.lineEdit_5.text() connection.execute("INSERT INTO USERS VALUES(?,?,?)", (username, email, password)) if (password == cpassword): connection.commit() print("Registered...!") else: print("password and cpass dont match...!") else: print("not a valid email address") def loginCheck1(self): print("signin clicked") from login import Ui_Dialog self.login = QtWidgets.QDialog() self.ui = Ui_Dialog() self.ui.setupUi(self.login) # self. Dialog1.hide() #error=AttributeError: 'Ui_Dialog1' object has no attribute 'Dialog1' self.login.show() def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(560, 530) Dialog.setStyleSheet( "QDialog{\n" "background-image: url(C:/Users/OFFICE/Desktop/neurons1.jpg);\n" "}\n" "QPushButton#signup2_btn{\n" "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 72, 255, 255), stop:0.982955 rgba(235, 230, 224, 255), stop:1 rgba(0, 0, 0, 255));\n" "border:none;\n" "}\n" "QPushButton#signin2_btn{\n" "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 180, 255, 255), stop:0.801136 rgba(235, 230, 224, 255), stop:0.982955 rgba(235, 230, 224, 255), stop:1 rgba(0, 0, 0, 255));\n" "border:none;\n" "}") self.user_name1_label = QtWidgets.QLabel(Dialog) self.user_name1_label.setGeometry(QtCore.QRect(50, 140, 141, 31)) font = QtGui.QFont() font.setPointSize(12) self.user_name1_label.setFont(font) self.user_name1_label.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.user_name1_label.setObjectName("user_name1_label") self.email_label_2 = QtWidgets.QLabel(Dialog) self.email_label_2.setGeometry(QtCore.QRect(50, 200, 141, 31)) font = QtGui.QFont() font.setPointSize(12) self.email_label_2.setFont(font) self.email_label_2.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.email_label_2.setObjectName("email_label_2") self.pass1_label = QtWidgets.QLabel(Dialog) self.pass1_label.setGeometry(QtCore.QRect(50, 260, 141, 31)) font = QtGui.QFont() font.setPointSize(12) self.pass1_label.setFont(font) self.pass1_label.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.pass1_label.setObjectName("pass1_label") self.cpassl_label = QtWidgets.QLabel(Dialog) self.cpassl_label.setGeometry(QtCore.QRect(50, 330, 141, 31)) font = QtGui.QFont() font.setPointSize(12) self.cpassl_label.setFont(font) self.cpassl_label.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.cpassl_label.setObjectName("cpassl_label") self.lineEdit = QtWidgets.QLineEdit(Dialog) self.lineEdit.setGeometry(QtCore.QRect(290, 140, 161, 31)) self.lineEdit.setObjectName("lineEdit") self.signup2_btn = QtWidgets.QPushButton(Dialog) self.signup2_btn.setGeometry(QtCore.QRect(110, 440, 91, 31)) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.signup2_btn.setFont(font) self.signup2_btn.setObjectName("signup2_btn") self.signup2_btn.clicked.connect(self.signupCheck1) self.lineEdit_2 = QtWidgets.QLineEdit(Dialog) self.lineEdit_2.setGeometry(QtCore.QRect(290, 200, 161, 31)) self.lineEdit_2.setObjectName("lineEdit_2") self.lineEdit_4 = QtWidgets.QLineEdit(Dialog) self.lineEdit_4.setGeometry(QtCore.QRect(290, 330, 161, 31)) self.lineEdit_4.setObjectName("lineEdit_4") self.lineEdit_5 = QtWidgets.QLineEdit(Dialog) self.lineEdit_5.setGeometry(QtCore.QRect(290, 260, 161, 31)) self.lineEdit_5.setObjectName("lineEdit_5") self.signin2_btn = QtWidgets.QPushButton(Dialog) self.signin2_btn.setGeometry(QtCore.QRect(330, 440, 91, 31)) font = QtGui.QFont() font.setPointSize(10) self.signin2_btn.setFont(font) self.signin2_btn.setObjectName("signin2_btn") self.signin2_btn.clicked.connect(self.loginCheck1) ############### self.user_name_label_2 = QtWidgets.QLabel(Dialog) self.user_name_label_2.setGeometry(QtCore.QRect(150, 30, 261, 51)) font = QtGui.QFont() font.setPointSize(16) self.user_name_label_2.setFont(font) self.user_name_label_2.setAutoFillBackground(False) self.user_name_label_2.setStyleSheet(";") self.user_name_label_2.setAlignment(QtCore.Qt.AlignCenter) self.user_name_label_2.setObjectName("user_name_label_2") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.user_name1_label.setText(_translate("Dialog", "Username")) self.email_label_2.setText(_translate("Dialog", "EMAIL")) self.pass1_label.setText(_translate("Dialog", "Password ")) self.cpassl_label.setText(_translate("Dialog", "Confirm Password")) self.signup2_btn.setText(_translate("Dialog", "SIGN UP")) self.signin2_btn.setText(_translate("Dialog", "SIGN IN")) self.user_name_label_2.setText(_translate("Dialog", "Sign Up Form"))
class AppWindow(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.show()
def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.show()
class MainClass(QDialog): def __init__(self): super(MainClass, self).__init__() self.uilog = Ui_Dialog() self.uilog.setupUi(self) self.uilog.pb_login.clicked.connect(self.loginCheck) def loginCheck(self): if self.uilog.le_username.text( ) == "ad" and self.uilog.le_password.text() == "q": self.openMain() self.close() else: self.showMessageBox("Warning", "Incorrect Password", QtWidgets.QMessageBox.Warning) def openMain(self): self.obj = QMainWindow() self.ui = main.Ui_MainWindow() self.ui.setupUi(self.obj) self.obj.show() self.ui.t3_pb_add.clicked.connect(self.addDetails) self.ui.t3_pb_mod.clicked.connect(self.modDetails) self.ui.t3_pb_del.clicked.connect(self.delDetails) self.ui.t3_pb_reset.clicked.connect(self.t3reset) self.ui.t2_pb_VD.clicked.connect(self.viewDetails) self.ui.t2_pb_search.clicked.connect(self.searchDetails) self.ui.t2_pb_reset.clicked.connect(self.t2reset) self.ui.t1_pb_GD.clicked.connect(self.getDetails) self.ui.t1_pb_ATC.clicked.connect(self.addToCart) self.row = 0 self.total = 0 self.ui.t1_pb_del_itm.clicked.connect(self.deleteItem) self.ui.t1_pb_receipt.clicked.connect(self.receipt) self.ui.t1_pb_new_order.clicked.connect(self.newOrder) self.ui.t4_pb_GR.clicked.connect(self.getReport) self.ui.t4_pb_download.clicked.connect(self.download) def download(self): self.getReport() data = [["YEAR", "MONTH", "TOTAL ORDERS", "TOTAL AMOUNT"]] for row in range(self.ui.t4_tw.rowCount()): data.append([ self.ui.t4_tw.item(row, 0).text(), self.ui.t4_tw.item(row, 1).text(), self.ui.t4_tw.item(row, 2).text(), self.ui.t4_tw.item(row, 3).text() ]) print(data) c = canvas.Canvas("report.pdf", pagesize=letter) c.setFillColor(colors.red) c.setFont("Helvetica-Bold", 48) c.drawCentredString(300, 700, "XYZ RESTAURENT") c.setFillColor(colors.black) c.setFont("Helvetica-Bold", 36) c.drawCentredString(200, 600, "Monthly Sales Report") t = Table(data) style = TableStyle([("BACKGROUND", (0, 0), (-1, 0), colors.green), ("TEXTCOLOR", (0, 0), (-1, 0), colors.whitesmoke), ("ALIGN", (0, 0), (-1, -1), "CENTER"), ("FONTNAME", (0, 0), (-1, -1), "Courier-Bold"), ("FONTSIZE", (0, 0), (-1, -1), 12), ("BOTTOMPADDING", (0, 0), (-1, 0), 12), ("BOX", (0, 0), (-1, -1), 2, colors.black), ("GRID", (0, 0), (-1, -1), 2, colors.black)]) t.setStyle(style) # Adding Alternate background color for rows total_rows = len(data) for i in range(1, total_rows): if i % 2 == 0: bc = colors.lightpink else: bc = colors.lightcyan ts = TableStyle([("BACKGROUND", (0, i), (-1, i), bc)]) t.setStyle(ts) t.wrapOn(c, 100, 450) t.drawOn(c, 100, 450) c.showPage() c.save() def getReport(self): start_month = self.ui.t4_from.text() sm = start_month[:4] + '-' + start_month[5:] + '-' + '01' end_month = self.ui.t4_to.text() em = end_month[:4] + '-' + end_month[5:] + '-' + '31' print(start_month) print(end_month) print(int(start_month[5:])) print(int(end_month[5:])) if int(start_month[5:]) <= int(end_month[5:]): self.ui.t4_tw.setRowCount(0) con = sqlite3.connect("XYZ.db") result = con.execute( '''SELECT strftime('%Y',odate),strftime('%m',odate) as "m",count(ono),sum(oamount) FROM ORDERS GROUP BY "m" HAVING odate BETWEEN ? AND ?''', (sm, em)) to = 0 total = 0 for row, form in enumerate(result.fetchall()): self.ui.t4_tw.insertRow(row) for col, item in enumerate(form): if col == 2: to = to + item elif col == 3: total = total + item self.ui.t4_tw.setItem( row, col, QtWidgets.QTableWidgetItem(str(item))) con.close() self.ui.t4_tot_orders.setText(str(to)) self.ui.t4_total.setText(str(round(total, 2))) else: self.showMessageBox( "Warning", "start month should be less than the ending month", QtWidgets.QMessageBox.Warning) def newOrder(self): self.ui.t1_le_ono.setText("") self.ui.t1_le_fid.setText("") self.ui.t1_le_fname.setText("") self.ui.t1_le_qty.setText("") self.ui.t1_le_price.setText("") self.ui.t1_tw.setRowCount(0) self.ui.t1_displaytotal.setText("") self.ui.t1_displaytax.setText("") self.ui.t1_grandtotal.setText("") self.row = 0 self.total = 0 def receipt(self): con = sqlite3.connect("XYZ.db") con.execute( "CREATE TABLE IF NOT EXISTS ORDERS(ono TEXT PRIMARY KEY,odate DATE,oamount NUMERIC)" ) on = self.onoGenerator() try: while (True): result = con.execute("Select ono from ORDERS") for count, row in enumerate(result.fetchall()): for i, col in enumerate(row): if col == on: on = self.onoGenerator() else: orderno = on con.close() break except: self.ui.t1_le_ono.setText(orderno) now = QDate.currentDate() now = now.toString(Qt.ISODate) amt = self.ui.t1_grandtotal.text() o = self.ui.t1_le_ono.text() con = sqlite3.connect("XYZ.db") con.execute("INSERT INTO ORDERS(ono,odate,oamount)VALUES(?,?,?)", (o, now, amt)) con.commit() con.close() data = [] for row in range(self.ui.t1_tw.rowCount()): data.append([ self.ui.t1_tw.item(row, 0).text(), self.ui.t1_tw.item(row, 1).text(), self.ui.t1_tw.item(row, 2).text(), self.ui.t1_tw.item(row, 3).text() ]) myformat = "{:<20}{:<10}{:<5}{}" with open("bill.txt", "w") as target: target.write("\t\t\t\tXYZ RESTAURENT\n") target.write("\t\t\tTel : 0452 - 4321098\n") target.write( "\n----------------------------------------------") target.write( f"\nOrder No : {self.ui.t1_le_ono.text()}\t\t\t\tDate : {now}" ) target.write( "\n----------------------------------------------\n") target.write(myformat.format('Items', 'Price', 'QTY', 'Amount')) target.write( "\n----------------------------------------------\n") for row in data: target.write( myformat.format(row[0], row[1], row[2], row[3])) target.write("\n") target.write( "----------------------------------------------\n") target.write( f"\t\t\t\t\t\tTotal : {self.ui.t1_displaytotal.text()}\n" ) target.write( f"\t\t\t\t\t\tTax(10%) : {self.ui.t1_displaytax.text()}\n") target.write( f"\t\t\t\t\t\tNetTotal : {self.ui.t1_grandtotal.text()}\n") target.write( "----------------------------------------------\n") target.write("\t\t\t\tThanks! Visit Again") def deleteItem(self): rows = self.ui.t1_tw.selectionModel().selectedRows() for r in rows: deductamount = int( self.ui.t1_tw.item(self.ui.t1_tw.currentRow(), 3).text()) self.total = self.total - deductamount tax = self.total * 0.1 tax = round(tax, 2) gtotal = self.total + tax self.row = self.row - 1 self.ui.t1_tw.removeRow(r.row()) self.ui.t1_displaytotal.setText(str(self.total)) self.ui.t1_displaytax.setText(str(tax)) self.ui.t1_grandtotal.setText(str(gtotal)) def onoGenerator(self): global ono pstart = 1 pinterval = 1 if ono == 0: ono = pstart else: ono = ono + pinterval orderno = str(ono).zfill(3) return orderno def addToCart(self): name = self.ui.t1_le_fname.text() price = self.ui.t1_le_price.text() qty = self.ui.t1_le_qty.text() status = 0 if name != "" and price != "" and qty != "": try: temp = int(price) * int(qty) except: self.showMessageBox("Warning", "price and quantity should be a number", QtWidgets.QMessageBox.Warning) status = 1 if status == 0: self.ui.t1_tw.insertRow(self.row) self.ui.t1_tw.setItem(self.row, 0, QtWidgets.QTableWidgetItem(name)) self.ui.t1_tw.setItem(self.row, 1, QtWidgets.QTableWidgetItem(price)) self.ui.t1_tw.setItem(self.row, 2, QtWidgets.QTableWidgetItem(qty)) self.ui.t1_tw.setItem(self.row, 3, QtWidgets.QTableWidgetItem(str(temp))) self.total = self.total + temp self.ui.t1_displaytotal.setText(str(self.total)) tax = self.total * 0.1 tax = (round(tax, 2)) self.ui.t1_displaytax.setText(str(tax)) gt = self.total + tax self.ui.t1_grandtotal.setText(str(gt)) self.row += 1 else: self.showMessageBox("Warning", "Please fill all the fields", QtWidgets.QMessageBox.Warning) def getDetails(self): a = self.ui.t1_le_fid.text() if a != "": con = sqlite3.connect("XYZ.db") result = con.execute("SELECT * FROM FOOD WHERE fid = ?", (a, )) data = result.fetchone() if data != None: self.ui.t1_le_fname.setText(str(data[1])) self.ui.t1_le_price.setText(str(data[2])) self.ui.t1_le_qty.setText("1") else: self.showMessageBox("Warning", "Incorrect Food ID", QtWidgets.QMessageBox.Warning) else: self.showMessageBox("Warning", "Please type the Food ID", QtWidgets.QMessageBox.Warning) def searchDetails(self): self.ui.t2_tw.setRowCount(0) a = self.ui.t2_le_fid.text() b = self.ui.t2_le_fname.text() con = sqlite3.connect("XYZ.db") print("connection established") print((a, b)) c = (a, b) result = con.execute( "SELECT * from FOOD WHERE fid LIKE ? OR fname LIKE ?", c) print("selction query executed") for count, row in enumerate(result.fetchall()): self.ui.t2_tw.insertRow(count) print(count) for i, item in enumerate(row): print(i) self.ui.t2_tw.setItem(count, i, QtWidgets.QTableWidgetItem(str(item))) con.close() def viewDetails(self): self.ui.t2_tw.setRowCount(0) con = sqlite3.connect("XYZ.db") result = con.execute("SELECT * FROM FOOD") for count, row in enumerate(result.fetchall()): self.ui.t2_tw.insertRow(count) for i, item in enumerate(row): self.ui.t2_tw.setItem(count, i, QtWidgets.QTableWidgetItem(str(item))) con.close() def t3reset(self): self.ui.t3_le_fid.setText("") self.ui.t3_le_fname.setText("") self.ui.t3_le_price.setText("") def t2reset(self): self.ui.t2_le_fid.setText("") self.ui.t2_le_fname.setText("") self.ui.t2_tw.setRowCount(0) def addDetails(self): fid = self.ui.t3_le_fid.text() fname = self.ui.t3_le_fname.text() fcost = self.ui.t3_le_price.text() status = 0 if fid != "" and fname != "" and fcost != "": try: fcost = int(fcost) except: self.showMessageBox("Warning", "Cost can't be string", QtWidgets.QMessageBox.Warning) status = 1 if status == 0: con = sqlite3.connect("XYZ.db") con.execute( "CREATE TABLE IF NOT EXISTS FOOD(fid TEXT PRIMARY KEY NOT NULL,fname TEXT,fcost INT)" ) result = con.execute("Select fid from FOOD") check = 0 for count, row in enumerate(result.fetchall()): for i, col in enumerate(row): if col == fid: check = 1 if check > 0: self.showMessageBox("Warning", "Food ID already exists", QtWidgets.QMessageBox.Warning) con.close() else: con.execute("INSERT INTO FOOD VALUES(?,?,?)", (fid, fname, fcost)) self.showMessageBox("Status", "Record added successfully", QtWidgets.QMessageBox.Information) con.commit() con.close() else: self.showMessageBox("Warning", "Please fill all the fields", QtWidgets.QMessageBox.Warning) def modDetails(self): f1 = self.ui.t3_le_fid.text() f2 = self.ui.t3_le_fname.text() f3 = self.ui.t3_le_price.text() status = 0 if f1 != "" and f2 != "" and f3 != "": try: f3 = int(f3) except: self.showMessageBox("Warning", "Cost can't be string", QtWidgets.QMessageBox.Warning) status = 1 if status == 0: con = sqlite3.connect("XYZ.db") result = con.execute("Select fid from FOOD") check = 0 for count, row in enumerate(result.fetchall()): for i, col in enumerate(row): if col == f1: check = 1 if check == 1: con.execute( """Update FOOD SET fname = ?,fcost = ? WHERE fid = ?""", (f2, f3, f1)) self.showMessageBox("Status", "Record updated successfully", QtWidgets.QMessageBox.Information) con.commit() con.close() else: self.showMessageBox("Warning", "Mentioned FID not exists", QtWidgets.QMessageBox.Warning) con.commit() con.close() else: self.showMessageBox("Warning", "Please fill all the fields", QtWidgets.QMessageBox.Warning) def delDetails(self): con = sqlite3.connect("XYZ.db") f = self.ui.t3_le_fid.text() result = con.execute("Select fid from FOOD") check = 0 for count, row in enumerate(result.fetchall()): for i, col in enumerate(row): if col == f: check = 1 if check == 1: con.execute("DELETE FROM FOOD WHERE fid = ?", (f, )) self.showMessageBox("Status", "Record deleted successfully", QtWidgets.QMessageBox.Information) con.commit() con.close() else: self.showMessageBox("Warning", "Mentioned FID not exists", QtWidgets.QMessageBox.Warning) con.commit() con.close() def showMessageBox(self, title, message, icon): msgbox = QtWidgets.QMessageBox() msgbox.setIcon(icon) msgbox.setWindowTitle(title) msgbox.setText(message) msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) msgbox.exec_()
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.ui = Ui_Dialog() self.ui.setupUi(self) QMessageBox.critical(self, '错误', '用户名或密码错误')
import sys from PyQt5.QtWidgets import QApplication, QDialog, QWidget from login import Ui_Dialog if __name__ == '__main__': app = QApplication(sys.argv) login_dialog = QDialog() ui = Ui_Dialog() ui.setupUi(login_dialog) login_dialog.show() sys.exit(app.exec_())