# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'QQchating.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from socket import *
import threading
import time


class Ui_MainWindow(object):

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(771, 588)
        MainWindow.setMinimumSize(QtCore.QSize(771, 585))
        MainWindow.setMaximumSize(QtCore.QSize(771, 588))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("imgs/icon.png"),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setStyleSheet("")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.frame_2 = QtWidgets.QFrame(self.centralwidget)
        self.frame_2.setGeometry(QtCore.QRect(240, 49, 531, 531))
        self.frame_2.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_2.setObjectName("frame_2")
        self.textBrowser = QtWidgets.QTextBrowser(self.frame_2)
        self.textBrowser.setGeometry(QtCore.QRect(10, 11, 511, 306))
        self.textBrowser.setObjectName("textBrowser")
        self.textEdit = QtWidgets.QTextEdit(self.frame_2)
        self.textEdit.setGeometry(QtCore.QRect(10, 345, 511, 126))
        self.textEdit.setObjectName("textEdit")
        self.pushButton = QtWidgets.QPushButton(self.frame_2)
        self.pushButton.setGeometry(QtCore.QRect(70, 480, 91, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setBold(True)
        font.setWeight(75)
        self.pushButton.setFont(font)
        self.pushButton.setStyleSheet("background-color: rgb(38, 99, 184);\n"
                                      "color: rgb(255, 255, 255);")
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.frame_2)
        self.pushButton_2.setGeometry(QtCore.QRect(360, 480, 101, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setBold(True)
        font.setWeight(75)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setStyleSheet("background-color: rgb(38, 99, 184);\n"
                                        "color: rgb(255, 255, 255);")
        self.pushButton_2.setObjectName("pushButton_2")
        self.label_6 = QtWidgets.QLabel(self.frame_2)
        self.label_6.setGeometry(QtCore.QRect(70, 320, 31, 20))
        self.label_6.setText("")
        self.label_6.setPixmap(QtGui.QPixmap("imgs/imagebutton.png"))
        self.label_6.setObjectName("label_6")
        self.label_5 = QtWidgets.QLabel(self.frame_2)
        self.label_5.setGeometry(QtCore.QRect(10, 320, 31, 21))
        self.label_5.setText("")
        self.label_5.setPixmap(QtGui.QPixmap("imgs/emojibutton.png"))
        self.label_5.setObjectName("label_5")
        self.label_7 = QtWidgets.QLabel(self.frame_2)
        self.label_7.setGeometry(QtCore.QRect(40, 320, 31, 21))
        self.label_7.setText("")
        self.label_7.setPixmap(QtGui.QPixmap("imgs/filebutton.png"))
        self.label_7.setScaledContents(False)
        self.label_7.setObjectName("label_7")
        self.frame_3 = QtWidgets.QFrame(self.centralwidget)
        self.frame_3.setGeometry(QtCore.QRect(240, 0, 531, 51))
        self.frame_3.setStyleSheet("background-color: rgb(38, 99, 184);")
        self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_3.setObjectName("frame_3")
        self.label_4 = QtWidgets.QLabel(self.frame_3)
        self.label_4.setGeometry(QtCore.QRect(220, 10, 121, 31))
        font = QtGui.QFont()
        font.setFamily("Arial Black")
        font.setPointSize(14)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(10)
        self.label_4.setFont(font)
        self.label_4.setStyleSheet("color: rgb(255, 255, 255);\n"
                                   "font: 87 14pt \"Arial Black\";")
        self.label_4.setAlignment(QtCore.Qt.AlignCenter)
        self.label_4.setObjectName("label_4")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(0, -1, 241, 41))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setBold(True)
        font.setWeight(75)
        self.label_3.setFont(font)
        self.label_3.setStyleSheet("background-color: rgb(234, 234, 234);")
        self.label_3.setLineWidth(1)
        self.label_3.setTextFormat(QtCore.Qt.AutoText)
        self.label_3.setAlignment(QtCore.Qt.AlignCenter)
        self.label_3.setObjectName("label_3")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(0, 39, 241, 41))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setStyleSheet("background-color: rgb(216, 216, 216);")
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.listWidget = QtWidgets.QListWidget(self.centralwidget)
        self.listWidget.setGeometry(QtCore.QRect(0, 80, 241, 491))
        self.listWidget.setStyleSheet("background-color: rgb(216, 216, 216);")
        self.listWidget.setIconSize(QtCore.QSize(45, 45))
        self.listWidget.setObjectName("listWidget")
        item = QtWidgets.QListWidgetItem()
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("imgs/avatar_icon.png"),
                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
        item.setIcon(icon1)
        self.listWidget.addItem(item)
        item = QtWidgets.QListWidgetItem()
        item.setIcon(icon1)
        self.listWidget.addItem(item)
        item = QtWidgets.QListWidgetItem()
        item.setIcon(icon1)
        self.listWidget.addItem(item)
        item = QtWidgets.QListWidgetItem()
        item.setIcon(icon1)
        self.listWidget.addItem(item)
        item = QtWidgets.QListWidgetItem()
        item.setIcon(icon1)
        self.listWidget.addItem(item)
        item = QtWidgets.QListWidgetItem()
        item.setIcon(icon1)
        self.listWidget.addItem(item)
        #MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        #MainWindow.setStatusBar(self.statusbar)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Group Chat"))
        self.pushButton.setText(_translate("MainWindow", "Shut Down"))
        self.pushButton_2.setText(_translate("MainWindow", "Send"))
        self.label_4.setText(_translate("MainWindow", "GROUP_1"))
        self.label_3.setText(_translate("MainWindow", "518030910001"))
        self.label.setText(_translate("MainWindow", "MEMBERS"))
        __sortingEnabled = self.listWidget.isSortingEnabled()
        self.listWidget.setSortingEnabled(False)
        item = self.listWidget.item(0)
        item.setText(_translate("MainWindow", "518030910001"))
        item = self.listWidget.item(1)
        item.setText(_translate("MainWindow", "518030910002"))
        item = self.listWidget.item(2)
        item.setText(_translate("MainWindow", "518030910003"))
        item = self.listWidget.item(3)
        item.setText(_translate("MainWindow", "518030910004"))
        item = self.listWidget.item(4)
        item.setText(_translate("MainWindow", "518030910005"))
        item = self.listWidget.item(5)
        item.setText(_translate("MainWindow", "518030910006"))
        self.listWidget.setSortingEnabled(__sortingEnabled)

    def recv_thead(self, s):
        buffsize = 1024

        def recv():
            while True:
                recvdata = s.recv(buffsize).decode('utf-8')
                self.textBrowser.append(time.ctime())
                self.textBrowser.append(recvdata + "\n" + "\n")
                print(recvdata)

        re = threading.Thread(target=recv)  # 创建线程
        re.start()

    def dj_send(self, s, wename, user):
        def send():
            we_text = ['wechat']
            we_text.append(wename)
            we_text.append(user)
            text = self.textEdit.toPlainText()
            if text != '':
                we_text.append(text)
                we_text = ' '.join(we_text)
                s.send(we_text.encode())
            else:
                QtWidgets.QMessageBox.information(self.MainWindow, 'Warning', 'Empty Message！',
                                                  QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Close,
                                                  QtWidgets.QMessageBox.Close)
            self.textEdit.clear()

        self.pushButton_2.clicked.connect(send)

    def dj_quit(self, ui2):
        def quit():
            ui2.close()

        self.pushButton.clicked.connect(quit)
