Beispiel #1
0
 def close_device(self):
     """
     教师端关闭学生端计算机
     :return:
     """
     send_msg = {'turn_off': True}
     self.control_client(send_msg)
     current_time = NowTime().now_time()
     self.textBrowser.append("<font color='blue'>" + current_time + "\n" + "关闭设备</font>")
Beispiel #2
0
 def reboot_device(self):
     """
     教师端重启客户端
     :return:
     """
     send_msg = {'reboot': True}
     self.control_client(send_msg)
     current_time = NowTime().now_time()
     self.textBrowser.append("<font color='blue'>" + current_time + "\n" + "重启设备</font>")
Beispiel #3
0
 def choose_client(self, i):
     self.current_client = self.comboBox.currentText()
     now_client = str(self.current_client)
     if now_client:
         current_time = NowTime().now_time()
         self.textBrowser.append("<font color='black'>" + current_time + "\n连接" + now_client + "</font>")
     self.pushButton_5.setEnabled(True)
     self.pushButton.setEnabled(True)
     self.pushButton_2.setEnabled(True)
     self.pushButton_3.setEnabled(True)
Beispiel #4
0
 def broadcast(self):
     broadcast_content = self.plainTextEdit.toPlainText()
     if broadcast_content and conn_list:
         current_time = NowTime().now_time()
         self.textBrowser.append("<font color='red'>" + current_time + " 广播\n"
                                 + broadcast_content + "</font>")
         send_msg = {'broadcast': broadcast_content}
         for client in conn_list:
             try:
                 conn_dt[client].sendall((str(send_msg)).encode("utf-8"))
             except Exception as err:
                 print(err)
                 continue
     else:
         pass
Beispiel #5
0
    def __init__(self):
        QMainWindow.__init__(self)
        loadUi("ui_source_server/server_panel.ui", self)  # 加载面板文件,使用qt designer开发
        self.setWindowTitle("多媒体管理软件 -樱桃智库")  # 设置窗口标题
        icon_info = qta.icon('fa5s.chalkboard-teacher', color='#3a8ee6')
        self.setWindowIcon(icon_info)  # 设置窗口的图标
        self.setFixedSize(1160, 865)  # 设置窗口固定尺寸

        self.clients_list = []
        self.comboBox.addItems(self.clients_list)  # 为客户端选择框填充项目
        self.window_initial()  # 窗口初始化

        self.check_thread = Server([])  # 多线程去获取
        self.check_thread.signal.connect(self.server_callback)
        self.check_thread.start()  # 启动线程

        current_time = NowTime().now_time()
        self.textBrowser.append("" + current_time + "\n"
                                + "学生端输入本机ip:" + host + " 本机端口:" + str(port))

        icon_info = qta.icon('fa5s.info-circle', color='white')
        icon_reboot = qta.icon('fa5s.redo', color='white')
        icon_power_off = qta.icon('fa5s.power-off', color='white')
        icon_lock = qta.icon('fa5s.lock', color='white')
        icon_broadcast = qta.icon('fa5s.bullhorn', color='white')
        self.pushButton_5.setIcon(icon_info)
        self.pushButton.setIcon(icon_reboot)
        self.pushButton_2.setIcon(icon_power_off)
        self.pushButton_3.setIcon(icon_lock)
        self.pushButton_4.setIcon(icon_broadcast)

        for i in range(9):
            client_button = 'self.pushButtonClient_' + str(i + 1)
            eval(client_button).clicked.connect(self.child_window)

        self.statusbar.showMessage("软件版本 v0.0.1", 5000)
Beispiel #6
0
 def lock_screen(self):
     send_msg = {'lock_screen': True}
     self.control_client(send_msg)
     current_time = NowTime().now_time()
     self.textBrowser.append("<font color='blue'>" + current_time + "\n" + "锁定计算机</font>")
Beispiel #7
0
    def tcp_callback(self, value):
        """
        tcp传输的回调函数,子线程的回复内容在这里出现。
        :param value: list
        :return: None
        """
        if value:
            client_addr = value[0].get('client_addr')
            receive_msg = value[0].get('receive_msg')
            offline = value[0].get('offline')
            stu_file = value[0].get('stu_file')

            if offline:
                client_name = client_addr[0] + ':' + str(client_addr[1])
                current_time = NowTime().now_time()
                self.textBrowser.append("<font color='red'>" + current_time + "\n"
                                        + client_name + "已经掉线!</font>")
                print("已经掉线")
                self.timer.stop()  # 停掉计时器
                # 掉线以后应该及时将students清掉!
                # 先停掉timer然后清掉,然后再开启!
                for i, student in enumerate(students):
                    if client_addr in student.values():
                        students.pop(i)
                        break
                self.setup_ui()  # 开启记时
                self.update_clients()  # 更新
            elif receive_msg:
                receive_msg = eval(receive_msg)
                stu_name = receive_msg.get('stu_name')
                stu_addr = receive_msg.get('stu_addr')
                mem_percent = receive_msg.get('mem_percent')
                if stu_name and stu_addr:
                    # 如果返回学生端计算名和计算地址
                    student = receive_msg
                    student['client_addr'] = client_addr  #
                    students.append(student)  # 添加到用户列表中
                    self.setup_ui()  # 开启记时
                elif mem_percent:
                    mem_percent = receive_msg['mem_percent']
                    current_time = NowTime().now_time()
                    self.textBrowser.append(
                        "<font color='Orange'>" + current_time + "\n" + "设备状态:CPU核心数"
                        + receive_msg['cpu_count'] + ",CPU占用:" + receive_msg['cpu_percent']
                        + ",内存占用:" + receive_msg['mem_percent'] + ".</font>")
                else:
                    client_name = client_addr[0] + ':' + str(client_addr[1])
                    current_time = NowTime().now_time()
                    # TODO 这里应该设置多线程后台连接,设置超时10次
                    self.textBrowser.append("<font color='red'>" + current_time + "\n"
                                            + client_name + " 举手一次</font>")
            elif stu_file:
                receive_data = value[0]
                stu_address = receive_data['client_addr']
                filename = stu_address[0] + '_' + str(stu_address[1]) + '_' + receive_data['stu_filename']  # 重建名字
                content = receive_data['stu_file']  # 获取数据
                with open("./received_files/" + filename, 'wb') as f:
                    f.write(content)
                current_time = NowTime().now_time()
                self.textBrowser.append(
                    "<font color='Orange'>" + current_time + "\n" + "收到文件" + filename + ",并保存成功!</font>")
Beispiel #8
0
 def device_info(self):
     """查看设备信息"""
     send_msg = {'device_info': True}
     self.control_client(send_msg)
     current_time = NowTime().now_time()
     self.textBrowser.append("<font color='blue'>" + current_time + "\n" + "查看设备信息</font>")