Ejemplo n.º 1
0
    def setLayouts(self):
        self.mainLayout = VBoxLayout()

        self.mainLayout.addSpacing(10)
        self.contentLayout = HBoxLayout()

        self.mainLayout.addWidget(self.spaceLine)
        self.mainLayout.addSpacing(10)
        self.contentLayout.addSpacing(30)
        self.contentLayout.addWidget(self.userTable)
        self.contentLayout.addSpacing(30)
        self.mainLayout.addLayout(self.contentLayout)
        self.mainLayout.addSpacing(30)
        self.setLayout(self.mainLayout)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
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.º 6
0
 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.º 7
0
    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)
Ejemplo n.º 8
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.º 9
0
class UserList(ScrollArea):
    def __init__(self, parent=None):
        super().__init__()
        self.parent = parent
        self.setObjectName('userList')
        self.userService = self.parent.parent.userService
        self.drawPanel()
        self.setLayouts()
        with open('qss/userList.qss', 'r', encoding="utf-8") as f:
            self.setStyleSheet(f.read())
        self.echoUserList()

    def drawPanel(self):
        self.spaceLine = QFrame(self)
        self.spaceLine.setObjectName("spaceLine")
        self.spaceLine.setFrameShape(QFrame.HLine)
        self.spaceLine.setFrameShadow(QFrame.Plain)
        self.spaceLine.setLineWidth(2)

        self.userTable = QTableWidget()
        self.userTable.setObjectName('userTable')
        self.userTable.setMinimumWidth(self.width())
        self.userTable.setColumnCount(6)
        self.userTable.setHorizontalHeaderLabels(
            ['用户名', '昵称', '邮箱', '联系方式', '签名', '添加好友'])

        self.userTable.setColumnWidth(0, self.width() / 6 * 0.9)
        self.userTable.setColumnWidth(1, self.width() / 6 * 0.9)
        self.userTable.setColumnWidth(2, self.width() / 6 * 1.1)
        self.userTable.setColumnWidth(3, self.width() / 6 * 1.1)
        self.userTable.setColumnWidth(4, self.width() / 6 * 1.5)
        self.userTable.setColumnWidth(5, self.width() / 6 * 0.5)
        self.userTable.horizontalHeader().setStretchLastSection(True)
        self.userTable.verticalHeader().setVisible(False)
        self.userTable.setShowGrid(False)
        self.userTable.setAlternatingRowColors(True)
        self.userTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.userTable.setSelectionBehavior(QAbstractItemView.SelectRows)

    def setLayouts(self):
        self.mainLayout = VBoxLayout()

        self.mainLayout.addSpacing(10)
        self.contentLayout = HBoxLayout()

        self.mainLayout.addWidget(self.spaceLine)
        self.mainLayout.addSpacing(10)
        self.contentLayout.addSpacing(30)
        self.contentLayout.addWidget(self.userTable)
        self.contentLayout.addSpacing(30)
        self.mainLayout.addLayout(self.contentLayout)
        self.mainLayout.addSpacing(30)
        self.setLayout(self.mainLayout)

    def echoUserList(self):
        allUser = self.userService.selectAll()
        for user in allUser:
            rowCount = self.userTable.rowCount()
            self.userTable.setRowCount(rowCount + 1)
            userInfo = [
                user.user_name, user.nick_name, user.email, user.phone,
                user.sign
            ]
            for i in range(5):
                self.userTable.setItem(rowCount, i,
                                       QTableWidgetItem(userInfo[i]))
Ejemplo n.º 10
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.º 11
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.º 12
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
Ejemplo n.º 13
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() == ""