import sys

from PyQt5.QtWidgets import QDialog, QPushButton, QLineEdit, QLabel, qApp
sys.path.append('../../')


class UserNameDialog(QDialog):
    """
    User login and password dialogue class.
    """
    def __init__(self):
        super().__init__()
        self.ok_pressed = False
        self.setWindowTitle('Starting...')
        self.setFixedSize(175, 135)
        self.label = QLabel('Input your username:', self)
        self.label.move(10, 10)
        self.label.setFixedSize(150, 10)
        self.client_name = QLineEdit(self)
        self.client_name.setFixedSize(154, 20)
        self.client_name.move(10, 30)
        self.btn_ok = QPushButton('Start', self)
        self.btn_ok.move(10, 105)
        self.btn_ok.clicked.connect(self.click)
        self.btn_cancel = QPushButton('Exit', self)
        self.btn_cancel.move(90, 105)
        self.btn_cancel.clicked.connect(qApp.exit)
        self.label_passwd = QLabel('Enter password:', self)
        self.label_passwd.move(10, 55)
        self.label_passwd.setFixedSize(150, 15)
        self.client_passwd = QLineEdit(self)
        self.client_passwd.setFixedSize(154, 20)
        self.client_passwd.move(10, 75)
        self.client_passwd.setEchoMode(QLineEdit.Password)
        self.show()

    def click(self):
        """
        OK click handler method.
        :return:
        """
        if self.client_name.text() and self.client_passwd.text():
            self.ok_pressed = True
            qApp.exit()
