示例#1
0
文件: main.py 项目: xiyiyia/vv-yc-zn
    def thread_start(self):
        self.thread = Thread()
        self.thread.hostname = 'localhost'
        self.thread.start()
        self.sign_send.connect(self.thread.sign_thread_send)
        self.thread.sign_thread_recv.connect(self.slot_recv)

        self.thread.sign_thread_start.connect(self.update_name)
示例#2
0
文件: test.py 项目: xiyiyia/vv-yc-zn
class Login(QWidget):
    sign_send = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.thread_start()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 400, 247)
        # 登录窗口无边界
        # self.setWindowFlags(Qt.FramelessWindowHint)
        # 登录窗口透明
        self.setAttribute(Qt.WA_TranslucentBackground, True)
        # 定义多个空label
        self.label_null1 = QLabel()
        self.label_null2 = QLabel()
        self.label_null3 = QLabel()
        self.label_null4 = QLabel()
        self.label_new = QLabel()
        # 定义创建新账户标签并设置信号槽绑定事件
        self.label_new.setText("<a href='#'>注册新用户</a>")
        self.label_new.setStyleSheet('''color: rgb(253,129,53);''')
        self.label_new.linkActivated.connect(self.idnew)
        # 设置隐藏密码RadioButton
        self.btn_check = QRadioButton("显示密码")
        self.btn_check.setStyleSheet('''color: rgb(253,129,53);;''')
        self.btn_check.clicked.connect(self.yanma)
        # 登录与退出按钮,设置按钮颜色及事件绑定
        self.btn_denglu = QPushButton("登录")
        self.btn_quxiao = QPushButton("退出")
        self.btn_denglu.setStyleSheet('''color: white;
                                background-color: rgb(218,181,150);''')
        self.btn_quxiao.setStyleSheet('''color: white;
                                background-color: rgb(218,181,150);''')
        self.btn_denglu.clicked.connect(self.check)
        self.btn_quxiao.clicked.connect(self.quxiao)
        # 账号和密码
        self.lineedit_id = QLineEdit()
        self.lineedit_id.setPlaceholderText("账号")
        self.account = self.lineedit_id.text()
        self.lineedit_password = QLineEdit()
        self.lineedit_password.setEchoMode(QLineEdit.Password)
        self.lineedit_password.setPlaceholderText("密码")
        self.passwd = self.lineedit_password.text()
        # 布局设置
        layout = QHBoxLayout(self)
        wid_denglu_right = QWidget()
        wid_denglu_left = QLabel()
        g = QGridLayout()
        g.addWidget(self.lineedit_id, 1, 1, 1, 2)
        g.addWidget(self.lineedit_password, 2, 1, 1, 2)
        g.addWidget(self.btn_check, 3, 1)
        g.addWidget(self.btn_denglu, 4, 1)
        g.addWidget(self.btn_quxiao, 4, 2)
        g.addWidget(self.label_null1, 5, 1)
        g.addWidget(self.label_null2, 6, 1)
        g.addWidget(self.label_null3, 7, 1)
        g.addWidget(self.label_null4, 8, 1)
        g.addWidget(self.label_new, 9, 2)
        wid_denglu_right.setLayout(g)
        layout.addWidget(wid_denglu_left)
        layout.addWidget(wid_denglu_right)
        self.setLayout(layout)
        # 密码隐藏

    def thread_start(self):
        self.thread = Thread()
        self.thread.hostname = 'localhost'
        self.thread.start()
        self.sign_send.connect(self.thread.sign_thread_send)
        self.thread.sign_thread_recv.connect(self.slot_recv)
        # self.thread.sign_thread_start.connect(self.update_name)

    def yanma(self):
        if self.btn_check.isChecked():
            self.lineedit_password.setEchoMode(QLineEdit.Normal)
        else:
            self.lineedit_password.setEchoMode(QLineEdit.Password)
        # 登录时核查账号及密码是否正确

    # 发送登陆信息
    def check(self):
        self.passwd = self.lineedit_password.text()
        self.account = self.lineedit_id.text()
        send_message_data_1 = IntegrationMessage.gm_signup(
            self.account, self.passwd)
        send_message_1 = IntegrationMessage.general_messages(
            '000001', '00000', '0', send_message_data_1, get_host_ip(),
            '127.0.0.1')
        self.sign_send.emit("00" + send_message_1)
        # '127.0.0.1'是服务器IP,后期运行更改

    # 服务器登陆信息处理
    def SignUp(self, str_1):
        json_operation = JO.JsonServer('0')
        print("check" + self.result)
        check_msg = PTB.GeneralMessages()
        check_msg = str_1
        if op.eq(check_msg.SC, "66666"):
            reply = QMessageBox.warning(self, "!", "登录成功", QMessageBox.Yes)
            json_operation.UpdateJson(self.account, check_msg.DATA)
            self.close()  # 登录成功
            self.idnewclose()  # 跳转到聊天界面
        if op.eq(check_msg.SC, "00001"):
            reply = QMessageBox.warning(self, "!", "账号或密码输入错误",
                                        QMessageBox.Yes)
            quit()  # 登录失败
        if op.eq(check_msg.SC, "00100"):
            reply = QMessageBox.warning(self, "!", "账号不存在", QMessageBox.Yes)
            quit()  # 登录失败

    def SignIn(self, str_1):
        json_operation = JO.JsonServer('0')
        print("check" + self.result)
        check_msg = PTB.GeneralMessages()
        check_msg = str_1
        if op.eq(check_msg.SC, "66666"):
            reply = QMessageBox.warning(self, "!", "注册成功", QMessageBox.Yes)
            json_operation.CreateJson(self.account, check_msg.DATA)
            quit()  # 注册成功
        if op.eq(check_msg.SC, "00100"):
            reply = QMessageBox.warning(self, "!", "账号不存在", QMessageBox.Yes)
            quit()  # 注册失败

    ##########################################################################################
    #接受消息,处理消息
    def slot_recv(self, mes_1):
        print("recv now")
        # print(Event_msg)
        self.result = mes_1
        check_msg = PTB.GeneralMessages()
        check_msg.ParseFromString(str.encode(mes_1[2:]))
        if op.eq(check_msg.RC, "010001") or op.eq(check_msg.RC, "011001"):
            if op.eq(mes_1[0:2], "00"):
                if op.eq(check_msg.RC, "010001"):
                    self.SignUp(check_msg)
                if op.eq(check_msg.RC, "011001"):
                    self.SignIn(check_msg)
        else:
            reply = QMessageBox.warning(self, "!", "Isn't the right message",
                                        QMessageBox.Yes)

    ##########################################################################################

    # 创建新的账号
    def idnew(self):
        self.hide()
        self.label_idnew_id = QLabel("账号")
        self.label_idnew_password = QLabel("密码")
        self.lineedit_idnew_id = QLineEdit()

        self.lineedit_idnew_password = QLineEdit()

        self.btn_idnew_quren = QPushButton("注册")
        self.btn_idnew_quren.clicked.connect(self.idnewqueren)
        self.btn_idnew_quxiao = QPushButton("取消")
        self.btn_idnew_quxiao.clicked.connect(self.idnewclose)
        self.idnew = QWidget()
        layout_idnew = QGridLayout()
        layout_idnew.addWidget(self.label_idnew_id, 1, 0)
        layout_idnew.addWidget(self.label_idnew_password, 2, 0)
        layout_idnew.addWidget(self.lineedit_idnew_id, 1, 1, 1, 2)
        layout_idnew.addWidget(self.lineedit_idnew_password, 2, 1, 1, 2)
        layout_idnew.addWidget(self.btn_idnew_quren, 3, 1)
        layout_idnew.addWidget(self.btn_idnew_quxiao, 3, 2)
        self.idnew.setLayout(layout_idnew)
        self.idnew.move(self.pos())
        self.idnew.resize(200, 133)
        self.idnew.setWindowFlags(Qt.FramelessWindowHint)
        self.paintEvent(self)
        self.idnew.setStyleSheet("background-color :rgb(253,216,174)")
        self.idnew.show()
        # 新账号注册的确认

    # 发送注册信息
    def idnewqueren(self):
        self.passwd = self.lineedit_password.text()
        self.account = self.lineedit_id.text()
        send_message_data_1 = IntegrationMessage.gm_signup(
            self.account, self.passwd)
        send_message_1 = IntegrationMessage.general_messages(
            '001001', '00000', '0', send_message_data_1, get_host_ip(),
            '127.0.0.1')
        self.sign_send.emit("00" + send_message_1)
        # '127.0.0.1'是服务器IP,后期运行更改

    # 添加背景图片
    def paintEvent(self, event):
        painter = QPainter(self)
        pixmap = QPixmap("药水哥.jpg")
        painter.drawPixmap(self.rect(), pixmap)

    # 关闭创新账号窗口
    def idnewclose(self):
        self.idnew.close()

    # 取消创建新账号,并退出创建窗口
    def quxiao(self):
        sys.exit()

    def handle_click(self):
        if not self.isVisible():
            self.show()
示例#3
0
文件: test.py 项目: xiyiyia/vv-yc-zn
class Ui_Form(QObject):
    sign_send = pyqtSignal(str)

    def __init__(self):
        super(Ui_Form, self).__init__()
        self.thread_start()

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(495, 405)

        self.listWidget = QListWidget(Form)
        self.listWidget.setGeometry(QRect(220, 50, 261, 311))
        self.listWidget.setObjectName("listWidget")
        self.listWidget.itemClicked.connect(self.click_item)

        self.listWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        #self.listWidget.customContextMenuRequested[QPoint].connect(self.rightMenu)

        self.label = QLabel(Form)
        self.label.setGeometry(QRect(320, 20, 81, 21))
        self.label.setObjectName("label")
        self.dateTimeEdit = QDateTimeEdit(Form)

        self.dateTimeEdit.setGeometry(QRect(10, 20, 194, 26))
        self.dateTimeEdit.setObjectName("dateTimeEdit")
        self.dateTimeEdit.setFrame(False)
        self.dateTimeEdit.setDate(QDate.currentDate())
        self.dateTimeEdit.setTime(QTime.currentTime())

        self.getname_line = QLineEdit(Form)
        self.getname_line.setGeometry(QRect(40, 60, 141, 31))
        self.getname_line.setObjectName("get_name")
        self.getname_line.setPlaceholderText("请输入账号名")
        self.id_label = QLabel(Form)
        self.id_label.setGeometry(QRect(70, 100, 67, 17))

        self.id_label.setObjectName("id_label")
        self.lineEdit = QLineEdit(Form)
        self.lineEdit.setPlaceholderText("添加好友")
        self.lineEdit.setGeometry(QRect(10, 150, 113, 25))
        self.lineEdit.setObjectName("lineEdit")
        self.pushButton = QPushButton(Form)
        self.pushButton.setGeometry(QRect(140, 150, 61, 21))
        self.pushButton.setObjectName("pushButton")
        self.pushButton.clicked.connect(self.add_friend)

        # self.load_friend()

        self.retranslateUi(Form)

        QMetaObject.connectSlotsByName(Form)

    """
    def rightMenu(self):
        rightMenu = QMenu(self.listWidget)
        removeAction = QAction(u"删除好友", triggered=self.delete_friend)
        rightMenu.addAction(removeAction)

        addAction = QAction(u"发起聊天",  triggered=self.start2chat)  # 也可以指定自定义对象事件
        rightMenu.addAction(addAction)
        rightMenu.exec_(QCursor.pos())
    """

    def thread_start(self):
        self.thread = Thread()
        self.thread.hostname = 'localhost'
        self.thread.start()
        self.sign_send.connect(self.thread.sign_thread_send)
        self.thread.sign_thread_recv.connect(self.slot_recv)
        # self.thread.sign_thread_start.connect(self.update_name)
    def click_item(self, item):
        QMessageBox.information(self.listWidget, "ListWidget",
                                "你选择了: " + item.text())

    def retranslateUi(self, Form):
        _translate = QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "好友列表"))
        #self.welcome_label.setText(_translate("Form", "welcome to gayhub"))
        self.pushButton.setText(_translate("Form", "确定"))

    # 把json文件中的好友信息全部读到列表中
    def load_friend(self):
        self.myname = self.getname_line.text()
        jo_1 = JO.JsonServer(self.myname)
        if self.myname != None:
            r = jo_1.friend_list(self.myname)
        else:
            print("f**k yc")
        #self.listWidget.addItem(account + IP + SIP)   用空格分开 f**k yc
        key_user = r.keys()
        for i in key_user:
            if (r[i]['STD'] == 1):
                self.listWidget.addItem(i + r[i]['IP'] + "在线")
            if (r[i]['STD'] == 0):
                self.listWidget.addItem(i + r[i]['IP'] + "不在线")

    def delete_friend(self, item):
        #row = self.listWidget.currentRow()
        print(self.listWidget.currentItem().text())

        self.str = self.listWidget.currentItem().text()
        self.del_name = self.str.split(" ")[0]

        send_message_data_1 = IntegrationMessage.gm_friend(
            self.del_name, self.myname)
        print(self.del_name)
        send_message = IntegrationMessage.general_messages(
            '000011', '00000', '0', send_message_data_1, get_host_ip(),
            '127.0.0.1')
        self.sign_send.emit("00" + send_message)

        #send friend's account to server
        #load client.json
        #self.listWidget.addItem("account ip sip")

    def start2chat(self):
        self.str = self.listWidget.currentItem().text()
        self.chat_friend = self.str.split(" ")[0]
        self.friend_IP = self.str.split(" ")[2]

    def add_friend(self):
        self.addfriend_name = self.lineEdit.text()
        send_message_data_1 = IntegrationMessage.gm_friend(
            self.addfriend_name, self.myname)
        send_message_1 = IntegrationMessage.general_messages(
            '000010', '00000', '0', send_message_data_1, get_host_ip(),
            '127.0.0.1')
        self.sign_send.emit("00" + send_message_1)
        #   self.listWidget.addItem("account ip sip")
        pass

    ######################################################################################
    #只要成功就load json
    def slot_recv(self, mes_1):
        print("recv now")
        # print(Event_msg)
        self.result = mes_1
        check_msg = PTB.GeneralMessages()
        check_msg.ParseFromString(str.encode(mes_1[2:]))
        if op.eq(check_msg.RC, "010010") or op.eq(check_msg.RC, "010011"):
            if op.eq(mes_1[0:2], "00"):
                if op.eq(check_msg.RC, '010010'):
                    if op.eq(check_msg.SC, "00000"):
                        self.AddFDRecv(check_msg)
                    else:
                        self.AddFDSend(check_msg)
                if op.eq(check_msg.RC, '010011'):
                    self.DelFD(check_msg)

    ######################################################################################

    def AddFDRecv(self, mes_1):
        self.FDInven(mes_1)

    # 好友邀请
    def FDInven(self, mes_1):
        self.label = QLabel("好友请求")
        self.friend_ID = QLabel('From ')
        self.friend_name = QLabel()
        #self.friend_name.setText(从recv得到申请者的名字)

        self.OK = QPushButton("同意")
        self.OK.clicked.connect(self.agree(mes_1))
        self.NO = QPushButton("不同意")
        self.NO.clicked.connect(self.disagree(mes_1))
        self.addFD = QWidget()
        layout_addFD = QGridLayout()
        layout_addFD.addWidget(self.label, 1, 0)
        layout_addFD.addWidget(self.friend_ID, 2, 0)
        layout_addFD.addWidget(self.friend_name, 2, 1, 1, 2)
        layout_addFD.addWidget(self.OK, 3, 1)
        layout_addFD.addWidget(self.NO, 3, 2)
        self.addFD.setLayout(layout_addFD)
        # self.addFD.move(self.pos())
        self.addFD.resize(200, 133)
        self.addFD.setWindowFlags(Qt.FramelessWindowHint)
        # self.paintEvent(self)
        self.addFD.setStyleSheet("background-color :rgb(253,216,174)")
        self.addFD.show()

    def agree(self, mes_1):
        self.addFD.hide()
        json_operation = JO.JsonServer('0')
        print("check" + self.result)
        # check_msg = PTB.GeneralMessages()
        check_msg_data = PTB.GeneralMessages()
        check_msg = mes_1
        check_msg_data.ParseFromString(str.encode(check_msg.DATA))
        json_operation.add_friend_json(self.myname, check_msg_data.SIP,
                                       check_msg_data.DIP)
        send_message_1 = IntegrationMessage.general_messages(
            '000010', '66666', '0', check_msg.DATA, get_host_ip(), '127.0.0.1')
        self.sign_send.emit("00" + send_message_1)

    def disagree(self, mes_1):
        self.addFD.hide()
        send_message_1 = IntegrationMessage.general_messages(
            '000010', '00010', '0', mes_1.DATA, get_host_ip(), '127.0.0.1')
        self.sign_send.emit("00" + send_message_1)

    def AddFDSend(self, mes_1):
        self.addfriend_name = self.lineEdit.text()
        json_operation = JO.JsonServer('0')
        print("check" + self.result)
        check_msg = PTB.GeneralMessages()
        check_msg = mes_1
        if op.eq(check_msg.SC, "66666"):
            reply = QMessageBox.warning(self.listWidget, "!", "添加成功",
                                        QMessageBox.Yes)
            json_operation.UpdateJson(self.addfriend_name, check_msg.DATA)
            self.load_friend()
            quit()  # 注册成功
        if op.eq(check_msg.SC, "00010"):
            reply = QMessageBox.warning(self.listWidget, "!", "拒绝申请",
                                        QMessageBox.Yes)
            quit()  # 注册失败

    def DelFD(self, mes_1):
        self.addfriend_name = self.lineEdit.text()
        json_operation = JO.JsonServer('0')
        print("check" + self.result)
        check_msg = PTB.gm_friend()
        check_msg.ParseFromString(str.encode(mes_1.DATA))
        if op.eq(mes_1.SC, "66666"):
            reply = QMessageBox.warning(self.listWidget, "!", "删除成功",
                                        QMessageBox.Yes)
            json_operation.del_friend_json(check_msg.DIP, check_msg.SIP)
            self.load_friend()
            quit()  # 注册成功
        if op.eq(mes_1.SC, "00100"):
            reply = QMessageBox.warning(self.listWidget, "!", "拒绝删除请求",
                                        QMessageBox.Yes)
            quit()  # 注册失败
示例#4
0
class f**k(QObject):
    sign_send = pyqtSignal(str)

    def __init__(self):
        super(f**k, self).__init__()
        self.thread_start()

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(446, 382)
        self.yourmessage = QtWidgets.QTextEdit(Form)
        self.yourmessage.setGeometry(QtCore.QRect(30, 250, 371, 91))
        self.yourmessage.setObjectName("yourmessage")
        self.friendIP = QtWidgets.QLineEdit(Form)
        self.friendIP.setGeometry(QtCore.QRect(280, 34, 151, 21))
        self.friendIP.setObjectName("friendIP")
        self.miwen = QtWidgets.QLineEdit(Form)
        self.miwen.setGeometry(QtCore.QRect(280, 84, 151, 21))
        self.miwen.setObjectName("miwen")
        self.key = QtWidgets.QLineEdit(Form)
        self.key.setGeometry(QtCore.QRect(280, 134, 151, 21))
        self.key.setObjectName("key")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(30, 10, 67, 17))
        self.label.setObjectName("label")
        self.send_btn = QtWidgets.QPushButton(Form)
        self.send_btn.setGeometry(QtCore.QRect(300, 350, 89, 25))
        self.send_btn.setObjectName("send_btn")
        self.send_btn.clicked.connect(self.send_click)
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(310, 10, 67, 17))
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(Form)
        self.label_3.setGeometry(QtCore.QRect(320, 60, 67, 17))
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(Form)
        self.label_4.setGeometry(QtCore.QRect(320, 110, 67, 17))
        self.label_4.setObjectName("label_4")
        self.history_message = QtWidgets.QTextBrowser(Form)
        self.history_message.setGeometry(QtCore.QRect(25, 40, 251, 191))
        self.history_message.setObjectName("history_message")
        self.getyourname = QtWidgets.QLineEdit(Form)
        self.getyourname.setGeometry(QtCore.QRect(10, 14, 71, 21))
        self.getyourname.setObjectName("lineEdit")
        self.getyourname.setPlaceholderText("您的名字")
        self.getfriendname = QtWidgets.QLineEdit(Form)
        self.getfriendname.setGeometry(QtCore.QRect(100, 14, 81, 21))
        self.getfriendname.setObjectName("lineEdit_2")
        self.getfriendname.setPlaceholderText("好友的名字")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "聊天界面"))
        self.send_btn.setText(_translate("Form", "发送"))
        self.label_2.setText(_translate("Form", "好友IP"))
        self.label_3.setText(_translate("Form", "密文"))
        self.label_4.setText(_translate("Form", "秘钥"))

    def thread_start(self):
        self.thread = Thread()
        self.thread.hostname = 'localhost'
        self.thread.start()
        self.sign_send.connect(self.thread.sign_thread_send)
        self.thread.sign_thread_recv.connect(self.slot_recv)
        # self.thread.sign_thread_start.connect(self.update_name)

    def send_click(self):

        self.message = "your message " + time.asctime(
            time.localtime(
                time.time())) + '\n' + self.yourmessage.toPlainText()
        self.history_message.append(self.message)
        send_message_data = IntegrationMessage.gm_friend(
            self.myname, self.message)
        send_message = IntegrationMessage.general_messages(
            '000000', '00000', '0', send_message_data, get_host_ip(),
            '127.0.0.1')
        self.sign_send.emit(send_message)
        self.show_miwen(self.yourmessage.toPlainText())
        self.show_friendIP()
        self.show_key()
        self.yourmessage.clear()
        #sendmessage to friend !!!!!!!!!!!!!!!!!!!!!! 补充在这里

    def show_friendIP(self):
        jo = JO.JsonServer('0')
        self.myname = self.getyourname.text()
        self.friendname = self.getfriendname.text()
        self.friendIP = jo.friend_ip(self.friendname)
        self.friendIP.setText(self.friendname)
        #   open myname.json     比如2016.json
        #   通过用户名得到相应的IP
        #   myIP 和 friend_IP
        #   self.friendIP.setText(friendname_IP)
        #   return self.friend_IP
        pass

    def show_miwen(self, msg):
        #self.miwen.setText("加密msg")
        pass

    def show_key(self):
        #self.key.setText("key")
        pass

    def slot_recv(self, msg):  #接受从服务区发来的消息
        check_msg = PTB.GeneralMessages()
        check_msg.ParseFromString(str.encode(msg[2:]))
        if op.eq(check_msg.RC, "010000"):
            if op.eq(msg[0:2], "00"):
                check_msg_data = PTB.gm_signup()
                check_msg_data.ParseFromString(check_msg.DATA)
                if op.eq(check_msg_data.SIP, self.friendname):
                    self.history_message.append(
                        'From' + self.friendname +
                        time.asctime(time.localtime(time.time())) + '\n' +
                        check_msg_data.DIP)
                else:
                    self.history_message.append(
                        "friend's message " + 'From' + self.friendname +
                        time.asctime(time.localtime(time.time())) + '\n' +
                        check_msg_data.DIP)
        """
示例#5
0
文件: main.py 项目: xiyiyia/vv-yc-zn
class login(QWidget):

    sign_recv = pyqtSignal(str, str)
    sign_send = pyqtSignal(str, str)
    sign_cmd = pyqtSignal(str)
    sign_getjson = pyqtSignal(str)

    def __init__(self):
        super(login, self).__init__()
        self.setGeometry(300, 300, 400, 247)
        # 登录窗口无边界
        # self.setWindowFlags(Qt.FramelessWindowHint)
        # 登录窗口透明
        self.setAttribute(Qt.WA_TranslucentBackground, True)
        # 定义多个空label
        self.label_null1 = QLabel()
        self.label_null2 = QLabel()
        self.label_null3 = QLabel()
        self.label_null4 = QLabel()
        self.label_new = QLabel()
        self.result = ""
        # 定义创建新账户标签并设置信号槽绑定事件
        self.label_new.setText("<a href='#'>注册新用户</a>")
        self.label_new.setStyleSheet('''color: rgb(253,129,53);''')
        self.label_new.linkActivated.connect(self.idnew)
        # 设置隐藏密码RadioButton
        self.btn_check = QRadioButton("显示密码")
        self.btn_check.setStyleSheet('''color: rgb(253,129,53);;''')
        self.btn_check.clicked.connect(self.yanma)
        # 登录与退出按钮,设置按钮颜色及事件绑定
        self.btn_denglu = QPushButton("登录")
        self.btn_quxiao = QPushButton("退出")
        self.btn_denglu.setStyleSheet('''color: white;
                        background-color: rgb(218,181,150);''')
        self.btn_quxiao.setStyleSheet('''color: white;
                        background-color: rgb(218,181,150);''')
        self.btn_denglu.clicked.connect(self.check)
        self.btn_quxiao.clicked.connect(self.quxiao)
        self.thread_start()
        self.sign_cmd.connect(self.check_usr)
        self.sign_getjson.connect(self.getjson)
        # 账号和密码
        self.lineedit_id = QLineEdit()
        self.lineedit_id.setPlaceholderText("账号")
        #        self.account = self.lineedit_id.text()
        self.lineedit_password = QLineEdit()
        self.lineedit_password.setEchoMode(QLineEdit.Password)
        self.lineedit_password.setPlaceholderText("密码")
        #        self.passwd = self.lineedit_password.text()
        # 布局设置
        layout = QHBoxLayout(self)
        wid_denglu_right = QWidget()
        wid_denglu_left = QLabel()
        g = QGridLayout()
        g.addWidget(self.lineedit_id, 1, 1, 1, 2)
        g.addWidget(self.lineedit_password, 2, 1, 1, 2)
        g.addWidget(self.btn_check, 3, 1)
        g.addWidget(self.btn_denglu, 4, 1)
        g.addWidget(self.btn_quxiao, 4, 2)
        g.addWidget(self.label_null1, 5, 1)
        g.addWidget(self.label_null2, 6, 1)
        g.addWidget(self.label_null3, 7, 1)
        g.addWidget(self.label_null4, 8, 1)
        g.addWidget(self.label_new, 9, 2)
        wid_denglu_right.setLayout(g)
        layout.addWidget(wid_denglu_left)
        layout.addWidget(wid_denglu_right)
        self.setLayout(layout)

    def thread_start(self):
        self.thread = Thread()
        self.thread.hostname = 'localhost'
        self.thread.start()
        self.sign_send.connect(self.thread.sign_thread_send)
        self.thread.sign_thread_recv.connect(self.slot_recv)

        self.thread.sign_thread_start.connect(self.update_name)

    def getjson(self, event_msg):
        Filename = "./" + self.account + ".json"
        with open(Filename, 'w+') as f:
            json.dump(event_msg, f, indent=4, ensure_ascii=False)
        f.close()

    # 密码隐藏
    def yanma(self):
        if self.btn_check.isChecked():
            self.lineedit_password.setEchoMode(QLineEdit.Normal)
        else:
            self.lineedit_password.setEchoMode(QLineEdit.Password)

    # 登录时核查账号及密码是否正确

    def check_usr(self, str):
        print("check" + self.result)
        if (str == "666666"):
            reply = QMessageBox.warning(self, "!", "登录成功", QMessageBox.Yes)
            # 登录成功
            # 跳转到聊天界面
        else:
            reply = QMessageBox.warning(self, "!", "账号或密码输入错误",
                                        QMessageBox.Yes)

    def SignUp(self, str_1):
        json_operation = JO.JsonServer()
        print("check" + self.result)
        check_msg = PTB.GeneralMessages()
        if op.eq(str_1[0:2], "00"):
            check_msg.ParseFromString(str.encode(str_1[2:]))
            if op.eq(check_msg.SC, "66666"):
                reply = QMessageBox.warning(self, "!", "登录成功", QMessageBox.Yes)
                json_operation.UpdateJson(self.account, check_msg.DATA)
                # 登录成功
                # 跳转到聊天界面
            if op.eq(check_msg.SC, "00001"):
                reply = QMessageBox.warning(self, "!", "账号或密码输入错误",
                                            QMessageBox.Yes)
                # 登录失败
            if op.eq(check_msg.SC, "00100"):
                reply = QMessageBox.warning(self, "!", "账号不存在",
                                            QMessageBox.Yes)
                # 登录失败
        else:
            reply = QMessageBox.warning(self, "!", "Isn't the right message",
                                        QMessageBox.Yes)

    def update_name(self, addr):
        event_msg = ["0", addr]
        # self.sign_send.emit("0000", event_msg)
        print("finish")

    def slot_recv(self, Event_id, Event_msg):
        print("recv now")
        print(Event_msg)
        self.result = Event_msg
        print(self.result)
        if Event_id == '0001':  #登录
            self.sign_cmd.emit(self.result)
        # if(Event_id == '0002'):  #传输json
        #     self.sign_getjson.emit(Event_msg)

    def client_login(self):  # def client_login(self)
        self.account = self.lineedit_id.text()
        self.passwd = self.lineedit_password.text()
        #生成报文
        event_msg = self.account + self.passwd
        #/生成报文
        self.sign_send.emit("0001", event_msg)
        print("send msg")

    def check(self):
        self.client_login()
        print("11" + self.result)

    # 创建新的账号
    def idnew(self):
        self.label_idnew_id = QLabel("账号")
        self.label_idnew_password = QLabel("密码")
        self.lineedit_idnew_id = QLineEdit()

        self.new_account = self.lineedit_idnew_id.text()

        self.lineedit_idnew_password = QLineEdit()

        self.new_passwd = self.lineedit_idnew_password.text()

        self.btn_idnew_quren = QPushButton("注册")
        self.btn_idnew_quren.clicked.connect(self.idnewqueren)
        self.btn_idnew_quxiao = QPushButton("取消")
        self.btn_idnew_quxiao.clicked.connect(self.idnewclose)
        self.idnew = QWidget()
        layout_idnew = QGridLayout()
        layout_idnew.addWidget(self.label_idnew_id, 1, 0)
        layout_idnew.addWidget(self.label_idnew_password, 2, 0)
        layout_idnew.addWidget(self.lineedit_idnew_id, 1, 1, 1, 2)
        layout_idnew.addWidget(self.lineedit_idnew_password, 2, 1, 1, 2)
        layout_idnew.addWidget(self.btn_idnew_quren, 3, 1)
        layout_idnew.addWidget(self.btn_idnew_quxiao, 3, 2)
        self.idnew.setLayout(layout_idnew)
        self.idnew.move(self.pos())
        self.idnew.resize(200, 133)
        self.idnew.setWindowFlags(Qt.FramelessWindowHint)
        self.paintEvent(self)
        self.idnew.setStyleSheet("background-color :rgb(253,216,174)")
        self.idnew.show()
        # 新账号注册的确认

    def idnewqueren(self):
        var = self.client_enroll(self.new_account, self.new_passwd)

        if (var == "0100"):
            replay = QMessageBox.warning(self, "!", "账号存在", QMessageBox.Yes)
        elif var == "0101":
            replay = QMessageBox.warning(self, "!", "密码不符合要求", QMessageBox.Yes)

        elif var == "0102":
            replay = QMessageBox.warning(self, "!", "注册成功", QMessageBox.Yes)
            self.idnew.close()
        replay = QMessageBox.warning(self, "!", "未知错误", QMessageBox.Yes)

    def client_enroll(self, new_account, new_passwd):
        return "f**k off"

    # 添加背景图片
    def paintEvent(self, event):
        painter = QPainter(self)
        pixmap = QPixmap("药水哥.jpg")
        painter.drawPixmap(self.rect(), pixmap)

    # 关闭创新账号窗口
    def idnewclose(self):
        self.idnew.close()

    # 取消创建新账号,并退出创建窗口
    def quxiao(self):
        sys.exit()