示例#1
0
class Logon(QWidget):
    ok = Signal()

    # 생성자 (self 는 걍 써줌 기본으로)

    def __init__(self, ids, pws, parent=None):
        # 보통 Qwidget 을 만들때, parent 를 넣어주는데, 없으면 default = None 임
        QWidget.__init__(self, parent)

        self.listIds = ids  # 클래스 생성자에다가 변수 걍 선언해도됨
        self.listPWs = pws

        self.labelId = QLabel('&Id :')
        self.labelId.setAlignment(Qt.AlignRight | Qt.AlignVCenter)

        self.labelPW = QLabel('&Password :'******'&Ok')
        self.buttonOk.setIcon(QIcon(':/images/ok.png'))

        layout1 = QGridLayout()
        layout1.addWidget(self.labelId, 0, 0)
        layout1.addWidget(self.lineEditId, 0, 1)
        layout1.addWidget(self.labelPW, 1, 0)
        layout1.addWidget(self.lineEditPW, 1, 1)

        layout2 = QHBoxLayout()
        layout2.addStretch()
        layout2.addWidget(self.buttonOk)

        mainLayout = QVBoxLayout()
        mainLayout.addLayout(layout1)
        mainLayout.addLayout(layout2)

        self.setLayout(mainLayout)  # 되는 이유는 Qwidget 클래스를 상속했기 때문임
        self.setWindowTitle('Log on')
        self.setWindowIcon(QIcon(":/images/ok.png"))

        self.buttonOk.clicked.connect(self.onOk)  # 밑에 함수 연결

    def onOk(self):
        if (self.lineEditId.text() not in self.listIds):
            QMessageBox.critical(self, 'Logon Error', 'You are not my member.')
            self.lineEditId.setFocus()
        else:
            idx = self.listIds.index(self.lineEditId.text())

            if (self.lineEditPW.text() != self.listPWs[idx]):
                QMessageBox.critical(self, 'Logon Error', 'Wrong Number')
                self.lineEditPW.setFocus()
            else:
                self.ok.emit()  # ok 시그널 보냄
示例#2
0
文件: ui.py 项目: rickmer/keyswarm
class PasswordDialog(QDialog):
    """
    An add password Dialog
    """
    def __init__(self, optional_fields=[]):
        QDialog.__init__(self)
        self.setMinimumHeight(120)
        self.setMinimumWidth(380)
        self.setWindowTitle('Enter a Password')
        self.grid_layout = QGridLayout()
        self.setLayout(self.grid_layout)
        name_label = QLabel('Name:')
        pass_label = QLabel('Password:'******'Gen')
        generate_password_button.clicked.connect(self.generate_password)
        self.layout().addWidget(generate_password_button, 1, 2)
        self.grid_layout.addWidget(pass_label, 1, 0)
        self.grid_layout.addWidget(self.password_input, 1, 1)
        self.optional_fields = list()
        for field in optional_fields:
            self.__add_optional_field__(field)
        comment_label = QLabel('comments')
        self.comment_field = QTextEdit()
        self.layout().addWidget(comment_label, self.layout().rowCount() + 1, 0)
        self.layout().addWidget(self.comment_field,
                                self.layout().rowCount(), 1)
        self.confirm_button = QPushButton()
        self.confirm_button.setShortcut('Return')
        self.confirm_button.setText('OK')
        self.grid_layout.addWidget(self.confirm_button,
                                   self.grid_layout.rowCount() + 1, 1)
        self.confirm_button.clicked.connect(self.confirm)

    def generate_password(self):
        self.password_input.setText(random_password())

    def confirm(self):
        """
        confirms the add password dialog
        :return: None
        """
        self.accept()

    def __add_optional_field__(self, name):
        """
        adds an optional field to the Dialog
        :param name:
        :return:
        """
        next_row = self.grid_layout.rowCount() + 1
        label = QLabel('{name}:'.format(name=name))
        input_field = QLineEdit()
        self.grid_layout.addWidget(label, next_row, 0)
        self.grid_layout.addWidget(input_field, next_row, 1)
        self.optional_fields.append((label, input_field))
示例#3
0
class LoginWindow(QDialog):

    api = API()
    db = Database()


    def __init__(self):
        super().__init__()
        self.title = 'Timey'
        self.left = 10
        self.top = 10
        self.width = 440
        self.height = 680
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setWindowIcon(QIcon(Config.icon))
        #self.setGeometry(self.left, self.top, self.width, self.height)
 
        logo = QLabel()
        logo.setPixmap(QPixmap('icon.png'))
        logo.setAlignment(Qt.AlignCenter)

        label_version = QLabel("version: "+__version__)
        label_version.setAlignment(Qt.AlignCenter)
        
        self.username = QLineEdit(self)
        self.password = QLineEdit(self)
        self.password.setEchoMode(QLineEdit.Password)
        fa5_icon = qta.icon('fa5.flag')
        self.button_login = QPushButton(fa5_icon, 'Login')
        self.button_login.clicked.connect(self.handleLogin)
        
        layout = QVBoxLayout(self)
        layout.addWidget(logo)
        layout.addWidget(label_version)
        layout.addWidget(self.username)
        layout.addWidget(self.password)
        layout.addWidget(self.button_login)
        print("hasdad")
        self.show()

    def handleLogin(self):
        data = self.api.auth(self.username.text(), self.password.text())
        print(data)
        try:
            if data.get('username'):
                logging.info("username and password accepted")
                self.db.saveUser(data["username"], data["api_token"], data['api_expire'])
                self.accept()
            elif data.get('error'):
                logging.info("username and password is incorrect")
                QMessageBox.warning(
                    self, 'Error', data['error'])
        except (TypeError, AttributeError):
            logging.error("Unknown error not cover in API() class")
            QMessageBox.warning(self, 'Error', "Unknown error not cover in API() class")