Ejemplo n.º 1
0
class ItemWidget(ScrollArea):
    def __init__(self, parent=None, blog=None):
        super(ItemWidget, self).__init__()
        self.parent = parent
        self.blog = blog
        self.init()
        self.setLayouts()
        self.setData()

        with open('qss/common.qss', 'r', encoding="utf-8") as f:
            self.setStyleSheet(f.read())

    def init(self):
        self.headerText = InputLine(self.frame, 600, 32, self.blog.header)
        self.headerText.setAlignment(Qt.AlignCenter)
        self.contentText = QTextEdit(self.frame)
        self.contentText.setMaximumWidth(600)
        self.contentText.setMaximumHeight(100)
        self.contentText.setMinimumHeight(100)
        self.contentText.setText(self.blog.content)
        self.imageFrame = QFrame()
        self.imageLayout = QGridLayout()
        self.imageFrame.setLayout(self.imageLayout)

    def setLayouts(self):
        self.mainLayout = VBoxLayout()
        self.frameLayout = HBoxLayout()
        self.contentLayout = VBoxLayout()
        self.contentLayout.addSpacing(30)
        self.contentLayout.addWidget(self.headerText)
        self.contentLayout.addSpacing(20)
        self.contentLayout.addWidget(self.contentText)
        self.contentLayout.addSpacing(20)
        self.contentLayout.addWidget(self.imageFrame)
        self.frameLayout.addSpacing(10)
        self.frameLayout.addLayout(self.contentLayout)
        self.frameLayout.addSpacing(10)
        self.mainLayout.addLayout(self.frameLayout)
        self.mainLayout.addStretch()
        self.setLayout(self.mainLayout)

    def setData(self):
        if self.blog.image is None or self.blog.image == "":
            return
        images = self.blog.image.split(":")
        count = 0
        for image in images:
            row = int(count / 3)
            col = int(count % 3)
            pic_label = PicLabel(src=IMAGE_BASE + image, width=180, height=120)
            self.imageFrame.setFixedHeight(120 * (row + 1) + 10)
            self.imageLayout.addWidget(pic_label, row, col)
            count = count + 1

    def sizeHint(self):
        # 每个item控件的大小
        return QSize(self.width(), self.height())
Ejemplo n.º 2
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.º 3
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.º 4
0
class BlogAdd(ScrollArea):
    def __init__(self, parent=None):
        super(BlogAdd, self).__init__(self)
        self.parent = parent
        self.user = self.parent.user
        self.blogService = self.parent.parent.blogService
        self.imageService = self.parent.parent.imageService
        self.title = None
        self.contents = None
        self.images = []
        self.image_pic = []
        self.draw()
        self.setLayouts()
        with open('qss/common.qss', 'r', encoding="utf-8") as f:
            self.setStyleSheet(f.read())

    def draw(self):
        self.headerText = InputLine(self.frame, 600, 32, "» 标题 «")
        self.headerText.setAlignment(Qt.AlignCenter)
        self.contentText = QTextEdit(self.frame)
        self.contentText.setMaximumWidth(600)
        self.contentText.setMaximumHeight(100)
        self.contentText.setMinimumHeight(100)
        self.imageFrame = QFrame()
        self.imageFrame.setToolTip("添加图片")
        self.imageFrame.setFixedHeight(20)
        self.addImageButton = QPushButton('☞ ❒')
        self.addImageButton.clicked.connect(self.addImage)
        self.addButton = QPushButton("发布")
        self.addButton.clicked.connect(self.publish)

    def setLayouts(self):
        self.mainLayout = VBoxLayout()
        self.frameLayout = HBoxLayout()
        self.contentLayout = VBoxLayout()
        self.imageLayout = QGridLayout()
        self.imageFrame.setLayout(self.imageLayout)
        self.contentLayout.addSpacing(30)
        self.contentLayout.addWidget(self.headerText)
        self.contentLayout.addSpacing(20)
        self.contentLayout.addWidget(self.contentText)
        self.contentLayout.addSpacing(20)
        self.contentLayout.addWidget(self.addImageButton)
        self.contentLayout.addSpacing(20)
        self.contentLayout.addWidget(self.imageFrame)
        self.contentLayout.addSpacing(20)
        self.contentLayout.addWidget(self.addButton)
        self.frameLayout.addSpacing(10)
        self.frameLayout.addLayout(self.contentLayout)
        self.frameLayout.addSpacing(10)
        self.mainLayout.addLayout(self.frameLayout)
        self.mainLayout.addStretch()
        self.setLayout(self.mainLayout)

    def addImage(self):
        paths, _ = QFileDialog.getOpenFileNames(self, "选择图片", '.',
                                                '图像文件(*.jpg *.png)')
        print(paths)
        for path in paths:
            image = self.imageService.saveImage(path)
            if image is not None:
                count = len(self.images)
                row = count / 3
                col = count % 3
                pic_label = PicLabel(src=IMAGE_BASE + image,
                                     width=180,
                                     height=120)
                self.imageFrame.setFixedHeight(120 * (row + 1) + 10)
                self.imageLayout.addWidget(pic_label, row, col)
                self.images.append(image)
                self.image_pic.append(pic_label)

    def publish(self):
        header = self.headerText.text()
        if self.isEmpty(header):
            QMessageBox.information(self, "提示", "标题不能为空!", QMessageBox.Yes)
            return
        blog = BlogPro(user_id=self.user.id)
        blog.header = header
        blog.content = self.contentText.toPlainText()
        if len(self.images) > 0:
            blog.image = ":".join(self.images)
        result = self.blogService.save(blog)
        if result is None:
            QMessageBox.information(self, "提示", "添加成功!", QMessageBox.Yes)
        else:
            QMessageBox.information(self, "提示", "添加成功!", QMessageBox.Yes)
            self.headerText.setText("")
            self.contentText.setText("")
            for pic in self.image_pic:
                self.imageLayout.removeWidget(pic)
                sip.delete(pic)
            self.images = []
            self.image_pic = []
            self.imageFrame.setFixedHeight(20)

    @staticmethod
    def isEmpty(text):
        return text is None or text.strip() == ""