Ejemplo n.º 1
0
class UserInfo(ScrollArea):
    def __init__(self, parent=None):
        super(UserInfo, self).__init__(self)
        self.setLabel()
        self.setLayouts()

    def setLabel(self):
        self.avatarLabel = QLabel()
        self.avatarLabel.setText("头像")
        self.avatarImage = PicLabel(width=100, height=100)
        self.avatarImage.setObjectName("avatarImage")
        self.avatarImage.doubleClick.connect(self.avatarClick)

        self.userNameLabel = QLabel()
        self.userNameLabel.setText("用户名")
        self.userNameText = InputLine(self, 300, 32)

        self.passwordLabel = QLabel()
        self.passwordLabel.setText("密码")
        self.passwordText = InputLine(self, 300, 32)

        self.nickNameLabel = QLabel()
        self.nickNameLabel.setText("昵称")
        self.nickNameText = InputLine(self, 300, 32)

        self.genderLabel = QLabel()
        self.genderLabel.setText("性别")
        self.boyRadio = QRadioButton('男')
        self.girlRadio = QRadioButton('女')

        self.emailLabel = QLabel()
        self.emailLabel.setText("邮箱")
        self.emailText = InputLine(self, 300, 32)

        self.phoneLabel = QLabel()
        self.phoneLabel.setText("手机")
        self.phoneText = InputLine(self, 300, 32)

        self.signLabel = QLabel()
        self.signLabel.setText("签名")
        self.signText = InputLine(self, 300, 32)

    def avatarClick(self):
        print('ccc')

    def setLayouts(self):
        middle = 20
        height = 20
        self.mainLayout = VBoxLayout()
        self.mainLayout.addSpacing(20)
        self.infoLayout = HBoxLayout()
        self.infoLayout.addStretch()
        self.labelLayout = VBoxLayout()
        self.labelLayout.addSpacing(42)
        self.labelLayout.addWidget(self.avatarLabel)
        self.labelLayout.addSpacing(52)
        self.labelLayout.addWidget(self.userNameLabel)
        self.labelLayout.addSpacing(height)
        self.labelLayout.addWidget(self.passwordLabel)
        self.labelLayout.addSpacing(height)
        self.labelLayout.addWidget(self.nickNameLabel)
        self.labelLayout.addSpacing(height)
        self.labelLayout.addWidget(self.genderLabel)
        self.labelLayout.addSpacing(height)
        self.labelLayout.addWidget(self.emailLabel)
        self.labelLayout.addSpacing(height)
        self.labelLayout.addWidget(self.phoneLabel)
        self.labelLayout.addSpacing(height)
        self.labelLayout.addWidget(self.signLabel)
        self.labelLayout.addSpacing(height)
        self.textLayout = VBoxLayout()
        self.imageLayout = HBoxLayout()
        self.imageLayout.addStretch()
        self.imageLayout.addWidget(self.avatarImage)
        self.imageLayout.addStretch()
        self.textLayout.addLayout(self.imageLayout)
        self.textLayout.addSpacing(height)
        self.textLayout.addWidget(self.userNameText)
        self.textLayout.addSpacing(height)
        self.textLayout.addWidget(self.passwordText)
        self.textLayout.addSpacing(height)
        self.textLayout.addWidget(self.nickNameText)
        self.textLayout.addSpacing(height)
        self.genderLayout = HBoxLayout()
        self.genderLayout.addWidget(self.boyRadio)
        self.genderLayout.addWidget(self.girlRadio)
        self.textLayout.addLayout(self.genderLayout)
        self.textLayout.addSpacing(height)
        self.textLayout.addWidget(self.emailText)
        self.textLayout.addSpacing(height)
        self.textLayout.addWidget(self.phoneText)
        self.textLayout.addSpacing(height)
        self.textLayout.addWidget(self.signText)
        self.textLayout.addSpacing(height)
        self.infoLayout.addLayout(self.labelLayout)
        self.infoLayout.addSpacing(middle)
        self.infoLayout.addLayout(self.textLayout)
        self.infoLayout.addStretch()
        self.mainLayout.addLayout(self.infoLayout)
Ejemplo n.º 2
0
class LoginWindow(ScrollArea):
    def __init__(self, parent=None):
        super(LoginWindow, self).__init__()
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.parent = parent
        self.userService = self.parent.userService
        self.resize(600, 360)
        self.setObjectName("LoginWindow")
        self.mainLayout = VBoxLayout(self)
        self.header = Header("登录", self)
        self.header.setMinimumHeight(30)
        self.user_label = QLabel("用户名")
        self.user_label.setObjectName("UserName")

        self.user_label.setMaximumHeight(27)
        self.txt_user = InputLine(self, 220, 32, "请输入用户名")
        self.txt_user.setObjectName("txt_user")
        self.txt_user.setText("生命练习生")
        self.pwd_label = QLabel("密码")
        self.pwd_label.setObjectName("Password")
        self.pwd_label.setMaximumHeight(27)
        self.txt_pwd = InputLine(self, 220, 32, "请输入密码")
        self.txt_pwd.resize(280, 40)
        self.txt_pwd.setObjectName("txt_pwd")
        self.txt_pwd.setEchoMode(QLineEdit.Password)
        self.txt_pwd.setText("123")
        self.btn_login = QPushButton()
        self.btn_login.setObjectName("btn_login")
        self.btn_login.setText("登录")
        self.btn_login.clicked.connect(self.login)
        self.btn_register = QPushButton()
        self.btn_register.setObjectName("btn_register")
        self.btn_register.setText("注册账号")
        self.setLayouts()
        with open('qss/Login_style.qss', 'r', encoding='utf-8') as f:
            self.setStyleSheet(f.read())

    def setLayouts(self):
        self.mainLayout = VBoxLayout()
        self.mainLayout.addWidget(self.header)
        self.mainLayout.addStretch()

        self.infoLayout = HBoxLayout()
        self.infoLayout.addStretch()
        self.labelLayout = VBoxLayout()
        self.labelLayout.addWidget(self.user_label)
        self.labelLayout.addSpacing(10)
        self.labelLayout.addWidget(self.pwd_label)
        self.infoLayout.addLayout(self.labelLayout)
        self.infoLayout.addSpacing(40)
        self.msgLayout = VBoxLayout()
        self.msgLayout.addWidget(self.txt_user)
        self.msgLayout.addSpacing(10)
        self.msgLayout.addWidget(self.txt_pwd)
        self.infoLayout.addLayout(self.msgLayout)
        self.infoLayout.addStretch()
        self.mainLayout.addLayout(self.infoLayout)
        self.mainLayout.addSpacing(15)

        self.mainLayout.addSpacing(40)

        self.loginLayout = HBoxLayout()
        self.loginLayout.addSpacing(150)
        self.loginLayout.addWidget(self.btn_login)
        self.loginLayout.addSpacing(150)

        self.registerLayout = HBoxLayout()
        self.registerLayout.addSpacing(150)
        self.registerLayout.addWidget(self.btn_register)
        self.registerLayout.addSpacing(150)
        self.mainLayout.addLayout(self.loginLayout)
        self.mainLayout.addSpacing(10)
        self.mainLayout.addLayout(self.registerLayout)
        self.mainLayout.addStretch()
        self.frame.setLayout(self.mainLayout)

    def login(self):
        username = self.txt_user.text()
        password = self.txt_pwd.text()
        print(username, password)
        user = self.userService.login(username, password)
        if user is not None:
            self.parent.user = user
            self.parent.loginSuccess()
        else:
            QMessageBox.information(self, "提示", "用户名或密码错误!", QMessageBox.Yes)
Ejemplo n.º 3
0
class UserAdd(UserInfo):
    def __init__(self, parent=None):
        super(UserAdd, self).__init__(self)
        self.parent = parent
        self.userService = self.parent.parent.userService
        self.imageService = self.parent.parent.imageService
        self.avatar = None
        self.addRegisterBtn()
        with open('qss/common.qss', 'r', encoding="utf-8") as f:
            self.setStyleSheet(f.read())

    def addRegisterBtn(self):
        style = """QPushButton{
                height: 30px;
                width: 130px;
                color: #FFFFFF;
                font: 100 12pt "黑体";
                background-color:#A9A9A9;
         }"""
        self.btn_add = QPushButton()
        self.btn_add.setObjectName("but_add")
        self.btn_add.setText("注册账号")
        self.btn_add.setStyleSheet(style)
        self.btn_add.clicked.connect(self.registerUser)
        self.btnLayout = HBoxLayout()
        self.btnLayout.addStretch()
        self.btnLayout.addWidget(self.btn_add)
        self.btnLayout.addStretch()
        self.mainLayout.addLayout(self.btnLayout)
        self.mainLayout.addStretch()
        self.setLayout(self.mainLayout)

    def registerUser(self):
        username = self.userNameText.text()
        password = self.passwordText.text()
        if self.isEmpty(username) or self.isEmpty(password):
            QMessageBox.information(self, "提示", "用户名或密码不能为空!", QMessageBox.Yes)
            return
        userPro = UserPro(user_name=username, password=password)
        email = self.emailText.text()
        if not self.isEmpty(email):
            userPro.email = email
        sign = self.signText.text()
        if not self.isEmpty(sign):
            userPro.sign = sign
        phone = self.phoneText.text()
        if not self.isEmpty(phone):
            userPro.phone = phone
        nick_name = self.nickNameText.text()
        if not self.isEmpty(nick_name):
            userPro.nick_name = nick_name
        if self.boyRadio.isChecked():
            userPro.gender = 0
        elif self.girlRadio.isChecked():
            userPro.gender = 1
        if not self.isEmpty(self.avatar):
            userPro.avatar = self.avatar
        result = self.userService.register(userPro)

        if result is None:
            QMessageBox.information(self, "提示", "添加用户失败!", QMessageBox.Yes)
        else:
            QMessageBox.information(self, "提示", "添加用户成功!", QMessageBox.Yes)

    def avatarClick(self):
        path, _ = QFileDialog.getOpenFileName(self, "选择图片", '.', '图像文件(*.jpg *.png)')
        result = self.imageService.saveImage(path)
        if result is not None:
            self.avatarImage.setSrc(IMAGE_BASE + result)
            self.avatar = result
        print(result)

    @staticmethod
    def isEmpty(text):
        return text is None or text.strip() == ""
Ejemplo n.º 4
0
class Header(QFrame):
    myStyle = """
    QFrame {background: #C0C0C0;}

    QLabel {
        margin-left: 8px; 
        color: white; 
        font-weight: bold;
        font-size: 15px;
    }

    QPushButton {
        border: none;
        font: bold;
        font-size: 13px;
        color: #7C7C7C;
        margin-right: 8px;
    }

    QPushButton:hover{
        color: #DCDDE4;
    }
    """

    def __init__(self, title: str, parent=None):
        super(Header, self).__init__()
        self.parent = parent

        self.setStyleSheet(self.myStyle)

        self.mainLayout = HBoxLayout(self)

        self.title = QLabel(title)
        self.mainLayout.addWidget(self.title)

        self.mainLayout.addStretch(1)

        self.closeButton = QPushButton('×')
        self.closeButton.clicked.connect(self.parent.close)
        self.mainLayout.addWidget(self.closeButton)

    # 事件。
    """重写鼠标事件,实现窗口拖动。"""

    def mousePressEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.parent.m_drag = True
            self.parent.m_DragPosition = event.globalPos() - self.parent.pos()
            event.accept()

    def mouseMoveEvent(self, event):
        try:
            if event.buttons() and Qt.LeftButton:
                self.parent.move(event.globalPos() - self.parent.m_DragPosition)
                event.accept()
        except AttributeError:
            pass

    def mouseReleaseEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.m_drag = False