def __init__ (self, parent = None): super(Settings, self).__init__(parent) self.registerDialog = Register() self.loginDialog = LogIn(self) self.keyAccess = AccessKey() self.showSettings = self.keyAccess.keyCheck() self.settingsLayout = QtGui.QVBoxLayout() settingsRow = QtGui.QHBoxLayout() label = QtGui.QLabel('Notifications enabled') checkbox = QtGui.QCheckBox() button = QtGui.QPushButton('Save') settingsRow.addWidget(label, 0) settingsRow.addWidget(checkbox, 1) self.settingsLayout.addLayout(settingsRow, 0) self.settingsLayout.addWidget(button, 1) self.loginLayout = QtGui.QVBoxLayout() loginButton = QtGui.QPushButton('Login') registerButton = QtGui.QPushButton('Register') registerButton.clicked.connect(self.registerDialog.show) loginButton.clicked.connect(self.loginDialog.show) self.loginLayout.addWidget(loginButton, 0) self.loginLayout.addWidget(registerButton, 1) if self.showSettings == True: self.setLayout(self.settingsLayout) else: self.setLayout(self.loginLayout)
def __init__(self, parent = None): super(LogIn, self).__init__(parent) self.parent = parent self.network = Network() self.keyAccess = AccessKey() mainLayout = QtGui.QVBoxLayout() nameLayout = QtGui.QHBoxLayout() passwordLayout = QtGui.QHBoxLayout() self.nameLabel = QtGui.QLabel('Username') self.nameEdit = QtGui.QLineEdit() nameLayout.addWidget(self.nameLabel, 0) nameLayout.addWidget(self.nameEdit, 1) self.passwordLabel = QtGui.QLabel('Password') self.passwordEdit = QtGui.QLineEdit() self.passwordEdit.setEchoMode(QtGui.QLineEdit.Password) passwordLayout.addWidget(self.passwordLabel, 0) passwordLayout.addWidget(self.passwordEdit, 1) palette = QtGui.QPalette() palette.setColor(QtGui.QPalette.Foreground, QtCore.Qt.red) self.generalError = QtGui.QLabel('Login error') self.emptyError = QtGui.QLabel('Empty field') self.generalError.setPalette(palette) self.generalError.hide() self.emptyError.setPalette(palette) self.emptyError.hide() self.loginButton = QtGui.QPushButton('Log in') self.loginButton.clicked.connect(self.loginButtonHandler) mainLayout.addLayout(nameLayout, 0) mainLayout.addLayout(passwordLayout, 1) mainLayout.addWidget(self.generalError, 2) mainLayout.addWidget(self.emptyError, 3) mainLayout.addWidget(self.loginButton, 4) self.setLayout(mainLayout)
class LogIn(QtGui.QDialog): def __init__(self, parent = None): super(LogIn, self).__init__(parent) self.parent = parent self.network = Network() self.keyAccess = AccessKey() mainLayout = QtGui.QVBoxLayout() nameLayout = QtGui.QHBoxLayout() passwordLayout = QtGui.QHBoxLayout() self.nameLabel = QtGui.QLabel('Username') self.nameEdit = QtGui.QLineEdit() nameLayout.addWidget(self.nameLabel, 0) nameLayout.addWidget(self.nameEdit, 1) self.passwordLabel = QtGui.QLabel('Password') self.passwordEdit = QtGui.QLineEdit() self.passwordEdit.setEchoMode(QtGui.QLineEdit.Password) passwordLayout.addWidget(self.passwordLabel, 0) passwordLayout.addWidget(self.passwordEdit, 1) palette = QtGui.QPalette() palette.setColor(QtGui.QPalette.Foreground, QtCore.Qt.red) self.generalError = QtGui.QLabel('Login error') self.emptyError = QtGui.QLabel('Empty field') self.generalError.setPalette(palette) self.generalError.hide() self.emptyError.setPalette(palette) self.emptyError.hide() self.loginButton = QtGui.QPushButton('Log in') self.loginButton.clicked.connect(self.loginButtonHandler) mainLayout.addLayout(nameLayout, 0) mainLayout.addLayout(passwordLayout, 1) mainLayout.addWidget(self.generalError, 2) mainLayout.addWidget(self.emptyError, 3) mainLayout.addWidget(self.loginButton, 4) self.setLayout(mainLayout) def loginButtonHandler(self): if self.nameEdit.text() == '' or self.passwordEdit.text() == '': self.emptyError.show() else: self.emptyError.hide() self.response = self.network.login({'username': self.nameEdit.text(), 'password': self.passwordEdit.text()}) self.response.finished.connect(self.requestFinished) def requestFinished(self): replyByteArray = self.response.readAll() QtCore.QObject.deleteLater(self.response) replyString = str(replyByteArray.data()) exp = re.compile(r'\\n|b\'|\'') clear = re.sub(exp, '', replyString) if clear == 'User not found': self.generalError.show() return replyDict = json.loads(clear) key = replyDict['key'] self.keyAccess.saveKey(key) print(self.keyAccess.getKey()) self.parent.refresh() self.hide()