[白月黑羽]关于风机协议工具的解答

架构 python3.8+pyqt5
先来看下原题:
在这里插入图片描述
视频中软件的效果
在这里插入图片描述
先来看下程序的效果如何,看上去大概相似
在这里插入图片描述
对应代码已经上传到了gitcode
https://gitcode.com/m0_37662818/fan_protocol_tool/overview

实现中的难点是双悬浮可视化,同时要高亮悬浮对应内容,程序中用的的事件过滤器。也许白月黑羽用的是更好的方法。

代码如下
app.py 主文件

from PyQt5 import QtWidgets,QtCore,QtGui
from ui_main import Ui_MainWindow  # 导入主界面类
import sys
import socket
import traceback 
from typing import List, Tupleclass MySignal(QtCore.QObject):update_sheet = QtCore.pyqtSignal(str)hover_signal = QtCore.pyqtSignal(int)
my_signal = MySignal()class MainWindow(QtWidgets.QMainWindow):def __init__(self, parent=None):super().__init__()self.ui = Ui_MainWindow()self.ui.setupUi(self)  # 加载主界面self.socket_fan = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # 创建socket对象self.ui.btn_connect_server.clicked.connect(self.connect_fan)  # 绑定按钮事件self.ui.stackedWidget.setCurrentIndex(0)self.ui.msg_list.setFlow(QtWidgets.QListView.Flow.LeftToRight)self.ui.msg_list.setViewMode(QtWidgets.QListView.ViewMode.IconMode)self.ui.msg_list.setResizeMode(QtWidgets.QListView.ResizeMode.Adjust)self.ui.msg_list.setWrapping(True)self.ui.msg_list.setSpacing(3)self.ui.msg_head_list.setFlow(QtWidgets.QListView.Flow.LeftToRight)self.ui.msg_head_list.setWrapping(True)self.ui.msg_head_list.setViewMode(QtWidgets.QListView.ViewMode.IconMode)self.ui.msg_head_list.setResizeMode(QtWidgets.QListView.ResizeMode.Adjust)self.ui.msg_head_list.setFixedHeight(70)self.ui.msg_list.setDragEnabled(False)self.ui.msg_head_list.setDragEnabled(False)self.ui.msg_body_table.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Stretch)self.ui.msg_body_table.verticalHeader().hide()self.ui.msg_body_table.horizontalHeader().setStyleSheet("color:#00789d;")self.ui.msg_list.setAttribute(QtCore.Qt.WidgetAttribute.WA_Hover,True)self.ui.msg_body_table.setAttribute(QtCore.Qt.WidgetAttribute.WA_Hover,True)self.ui.msg_head_list.setAttribute(QtCore.Qt.WidgetAttribute.WA_Hover,True)self.ui.msg_list.installEventFilter(self)self.ui.msg_body_table.installEventFilter(self)self.ui.msg_head_list.installEventFilter(self)self.last_hover_index = -1self.msg_id = 0self.ui.listWidget.itemClicked.connect(self.list_widget_clicked)self.ui.btn_set.clicked.connect(self.btn_set_clicked)self.ui.btn_get_sn.clicked.connect(self.btn_get_sn_clicked)self.ui.btn_get_state.clicked.connect(self.btn_get_state_clicked)my_signal.update_sheet.connect(self.update_sheet_cb)my_signal.hover_signal.connect(self.draw_cb)def draw_cb(self,index):def draw_(index:int,color:str):self.ui.msg_list.item(index).setBackground(QtGui.QColor(color))if index < 3:self.ui.msg_head_list.item(index * 2 + 1).setBackground(QtGui.QColor(color))else:row = index//3 - 1col = index%3 + 1self.ui.msg_body_table.item(row,col).setBackground(QtGui.QColor(color))if(index == self.last_hover_index):returnif(self.last_hover_index != index):if(self.last_hover_index >= 0):draw_(self.last_hover_index,'white')if(index >= 0):draw_(index,'orangered')if(index < 0 and self.last_hover_index >= 0):draw_(self.last_hover_index,'white')self.last_hover_index = indexdef eventFilter(self, watched:QtWidgets.QWidget, event:QtCore.QEvent):if(watched == self.ui.msg_head_list):if(event.type() == QtCore.QEvent.Type.HoverMove):index = watched.indexAt(event.pos()).row()my_signal.hover_signal.emit(index//2)if(event.type() == QtCore.QEvent.Type.HoverLeave):my_signal.hover_signal.emit(-1)if(watched == self.ui.msg_list):if(event.type() == QtCore.QEvent.Type.HoverMove):index = watched.indexAt(event.pos()).row()my_signal.hover_signal.emit(index)if(event.type() == QtCore.QEvent.Type.HoverLeave):my_signal.hover_signal.emit(-1)if(watched == self.ui.msg_body_table):if(event.type() == QtCore.QEvent.Type.HoverMove):x = event.pos().x()y = event.pos().y()hight = watched.horizontalHeader().height()point = QtCore.QPoint(x,y - hight)Model_index = watched.indexAt(point)p = event.pos()if Model_index is None:my_signal.hover_signal.emit(-1)else:index = -1row = Model_index.row()col = Model_index.column()if(row >= 0 and col >= 1):row = Model_index.row()#print("row:" + str(row))col = Model_index.column()#print("col:" + str(col))index = (row) * 3 + col - 1 + 3my_signal.hover_signal.emit(index) if(event.type() == QtCore.QEvent.Type.HoverLeave):my_signal.hover_signal.emit(-1)return super().eventFilter( watched, event)       def update_sheet_cb(self,text:str):def fill_data(infos:List[Tuple[str,str]]):for index,info in enumerate(infos):self.ui.msg_list.addItem(info[0])if index < 3:if index == 0:self.ui.msg_head_list.addItem("消息长度:")if index == 1: self.ui.msg_head_list.addItem("类型:")if index == 2:self.ui.msg_head_list.addItem("消息ID:")self.ui.msg_head_list.addItem(str(info[1]))elif index % 3 == 0:self.ui.msg_body_table.insertRow(index // 3 - 1)table_item = QtWidgets.QTableWidgetItem(str(infos[index][1]))table_item.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)self.ui.msg_body_table.setItem(index // 3 - 1, 1, table_item)table_item = QtWidgets.QTableWidgetItem(str(infos[index + 1][1]))table_item.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)self.ui.msg_body_table.setItem(index // 3 - 1, 2, table_item)table_item = QtWidgets.QTableWidgetItem(str(infos[index + 2][1]))table_item.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)self.ui.msg_body_table.setItem(index // 3 - 1, 3, table_item)if infos[index][0] == "01":table_item = QtWidgets.QTableWidgetItem("设备编号")table_item.setForeground(QtGui.QColor(255,128,0))table_item.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)self.ui.msg_body_table.setItem(index // 3 - 1, 0, table_item)elif infos[index][0] == "02":table_item = QtWidgets.QTableWidgetItem("设备状态")table_item.setForeground(QtGui.QColor(255,128,0))table_item.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)self.ui.msg_body_table.setItem(index // 3 - 1, 0,table_item)elif infos[index][0] == "a0":table_item = QtWidgets.QTableWidgetItem("结果码")table_item.setForeground(QtGui.QColor(255,128,0))table_item.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)self.ui.msg_body_table.setItem(index // 3 - 1, 0,table_item)elif infos[index][0] == "a1":table_item = QtWidgets.QTableWidgetItem("结果描述")table_item.setForeground(QtGui.QColor(255,128,0))table_item.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)self.ui.msg_body_table.setItem(index // 3 - 1, 0, table_item)#上色for i in range(self.ui.msg_list.count()):if i < 3:self.ui.msg_list.item(i).setForeground(QtGui.QColor(0,128,0))elif i % 3 == 0:self.ui.msg_list.item(i).setForeground(QtGui.QColor(255,128,0))elif i % 3 == 1:self.ui.msg_list.item(i).setForeground(QtGui.QColor(0, 120, 157))passres = bytes.fromhex(text)infos = self.resolve_response(res)self.ui.msg_list.clear()self.ui.msg_head_list.clear()self.ui.msg_body_table.setRowCount(0)fill_data(infos)passdef connect_fan(self):ip = self.ui.input_server_ip.text()port = int(self.ui.input_server_port.text())print(ip, port)if not ip or not port:self.ui.msgWindow.append("请输入风机IP和端口!")returnif self.ui.btn_connect_server.text() == "连接":try:self.socket_fan.connect((ip, port))  # 连接风机self.ui.msgWindow.append("连接风机成功!")#self.ui.btn_connect_server.setText("断开")except Exception as error:self.ui.msgWindow.append("连接风机失败!")print(error)elif self.ui.btn_connect_server.text() == "断开":self.socket_fan.close()  # 断开连接self.ui.msgWindow.append("断开风机连接!")self.ui.btn_connect_server.setText("连接")def btn_set_clicked(self):text = self.ui.btn_set.text()if(text == '设置'):self.set_dev_stats_process()def btn_get_sn_clicked(self):self.get_dev_stats_process(state=1)def btn_get_state_clicked(self):self.get_dev_stats_process(state=2)def list_widget_clicked(self,item:QtWidgets.QListWidgetItem):text = item.text()if(text == "连接设备"):self.change_page_connect()elif(text == "设置风泵状态"):self.change_page_set()elif(text == "读取风泵状态"):self.change_page_get()def change_page_connect(self):self.ui.stackedWidget.setCurrentIndex(0)def change_page_set(self):self.ui.stackedWidget.setCurrentIndex(1)def change_page_get(self):self.ui.stackedWidget.setCurrentIndex(2)# 获取设备配置请求def get_dev_config_request(self,msg_id:int,state:int)-> bytes:body = b''body += b'\xC1'body += b'\x03'body += (state.to_bytes(1,byteorder='big'))msg_len = 8 + len(body)msg_type = 0x01F0msg_id = msg_idreturn msg_len.to_bytes(2,byteorder='big') + msg_type.to_bytes(2,byteorder='big') + msg_id.to_bytes(4,byteorder='big') + body# 获取设备配置通信过程def get_dev_stats_process(self,state=0):msg_id = self.msg_idtry:req = self.get_dev_config_request(msg_id, state)self.socket_fan.send(req)self.ui.msgWindow.append("发送消息:")self.ui.msgWindow.append("<font color=\"#006400\">"+ req.hex() + "</font> ")res =  self.socket_fan.recv(1024)self.ui.msgWindow.append("接收消息:")self.ui.msgWindow.append("<font color=\"#006400\">"+ res.hex() + "</font> ")infos = self.resolve_response(res)for index,info in enumerate(infos):if index == 3 or index == 6:if info[0] == "01":self.ui.output_devSn.setText(str(infos[index + 2][1]))elif info[0] == "02":self.ui.output_devState.setText(str(infos[index + 2][1]))my_signal.update_sheet.emit(res.hex())except Exception as e:traceback.print_exc()self.msg_id += 1pass# 组装设备配置请求def set_dev_config_request(self,msgid:int,dev:str, stats:int):body = b''if dev is not None:body += b'\x01'body += (len(dev) + 2).to_bytes(1,byteorder='big')body += dev.encode()if stats is not None:body += b'\x02'body += (3).to_bytes(1,byteorder='big')body += stats.to_bytes(1,byteorder='big')msg_len = 8 + len(body)msg_type = b'\x02\xF0'msgid = msgidreturn msg_len.to_bytes(2,byteorder='big') + msg_type + msgid.to_bytes(4,byteorder='big') + body# 设置设备状态通信过程def set_dev_stats_process(self):msg_id = self.msg_iddev_id_text =  self.ui.input_devSn.text() if len(self.ui.input_devSn.text()) > 0 else  Nonedev_stats_text = self.ui.input_devState.text()dev_stats = Noneif dev_stats_text is not None and len(dev_stats_text) != 0 :dev_stats = int(dev_stats_text)try:req = self.set_dev_config_request(msgid=msg_id,dev = dev_id_text,stats=dev_stats)self.socket_fan.send(req)self.ui.msgWindow.append("发送消息:")self.ui.msgWindow.append("<font color=\"#006400\">"+ req.hex() + "</font> ")res =  self.socket_fan.recv(1024)self.ui.msgWindow.append("接收消息:")self.ui.msgWindow.append("<font color=\"#006400\">"+ res.hex() + "</font> ")my_signal.update_sheet.emit(res.hex())except Exception as e:traceback.print_exc()self.msg_id += 1pass# 解析响应 bytes版'''def resolve_response(self, res:bytes)-> dict:if len(res) < 8:return {}infos = {}msg_type_bytes = res[2:4]msg_type = 'unknown massage 'if msg_type_bytes == b'\x01\xF1':msg_type = 'read state response'elif msg_type_bytes == b'\x02\xF1':msg_type = 'set state response'infos["msg_len"] = int.from_bytes(res[0:2],byteorder='big') infos["msg_id"] =  int.from_bytes(res[4:8],byteorder='big')infos["msg_type"] = msg_typepos = 8while pos < len(res):code = res[pos:pos + 1]if(msg_type_bytes == b'\x01\xF1'):if code == b'\x01':length = res[pos + 1]desc = res[pos+2:pos+length].decode()field = Field(b'\x01',length,desc)infos['sn'] = fieldpos += lengthelif code == b'\x02':length = res[pos + 1]desc = int.from_bytes(res[pos + 2:pos + length],byteorder='big')field = Field(b'\x02',length,desc)infos['state'] = fieldpos += lengthelse:breakif(msg_type_bytes == b'\x02\xF1'):if code == b'\xA0':length = res[pos + 1]desc = int.from_bytes[pos + 2: pos + length]field = Field(b'\xA0',length,desc)infos['code'] = fieldpos += lengthelif code == b'\xA1':length = res[pos + 1]desc = res[pos+2:pos + length].decode()field = Field(b'\xA1',length,desc)infos['desc'] = fieldpos += lengthelse:breakreturn infospass'''# 解析响应 str版def resolve_response(self, res:bytes)-> list:def resolve_response_head(res_head:bytes)->list:infos = []msg_type = 0msg_len_hex = (res_head[0:2]).hex()msg_type_hex = (res_head[2:4]).hex()msg_id_hex = (res_head[4:8]).hex()msg_type_desc = ""msg_len = int.from_bytes(res_head[0:2],byteorder='big')msg_id = int.from_bytes(res_head[4:8],byteorder='big')if(msg_type_hex.upper() == "01F1"):msg_type_desc = "get_state_response"elif(msg_type_hex.upper() == "02F1"):msg_type_desc = "set_state_response"infos.append((msg_len_hex,msg_len))infos.append((msg_type_hex,msg_type_desc))infos.append((msg_id_hex,msg_id))return infosdef resolve_response_body_get_state(res_body:bytes)->list:pos = 0infos = []while pos < len(res_body):code_hex = res_body[pos:pos + 1].hex()length_hex = res_body[pos + 1:pos + 2].hex()length = res_body[1]value_hex = res_body[pos + 2: pos + length].hex()value = ""if(code_hex == "01"):value = res_body[pos + 2:pos + length].decode(encoding="ANSI")elif(code_hex == "02"):value = int.from_bytes(res_body[pos + 2:pos + length],byteorder='big')infos.append((code_hex,code_hex))infos.append((length_hex,str(length)))infos.append((value_hex,str(value)))pos += lengthreturn infosdef resolve_response_body_set_state(res_body:bytes)->list:pos = 0infos = []while pos < len(res_body):code_hex = res_body[pos:pos + 1].hex()length_hex = res_body[pos + 1:pos + 2].hex()length = res_body[pos+1]value_hex = res_body[pos + 2:pos + length].hex()value = ""if(code_hex.upper() == "A0"):value = res_body[pos+2]elif(code_hex.upper() == "A1"):value = res_body[pos + 2:pos + length].decode(encoding="ANSI")infos.append((code_hex,code_hex))infos.append((length_hex,str(length)))  infos.append((value_hex,str(value)))pos += lengthreturn infosres_len = len(res)if res_len < 8:return []msg_len = int.from_bytes(res[0:2],byteorder='big')if msg_len > res_len:return []res_head = res[0:8]res_body = res[8:msg_len]infos = []infos = resolve_response_head(res_head)if(infos[1][0].upper() == "01F1"):infos = infos + resolve_response_body_get_state(res_body)elif(infos[1][0].upper() == "02F1"):infos = infos + resolve_response_body_set_state(res_body)return infosif __name__ == '__main__':app = QtWidgets.QApplication([])  # 创建QApplication对象window = MainWindow()  # 创建主界面对象window.show()  # 显示主界面sys.exit(app.exec_())  # 运行主界面

ui_main.py 文件

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'main.ui'
#
# Created by: PyQt5 UI code generator 5.15.11
#
# 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, QtWidgetsclass Ui_MainWindow(object):def setupUi(self, MainWindow):MainWindow.setObjectName("MainWindow")MainWindow.resize(593, 600)MainWindow.setStyleSheet("* { \n"
"    color: rgb(88, 88, 88);\n"
" font-size:14px;\n"
" font-family: consolas, \"微软雅黑\";\n"
"}")self.centralwidget = QtWidgets.QWidget(MainWindow)self.centralwidget.setObjectName("centralwidget")self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.centralwidget)self.verticalLayout_5.setObjectName("verticalLayout_5")self.horizontalLayout_3 = QtWidgets.QHBoxLayout()self.horizontalLayout_3.setObjectName("horizontalLayout_3")self.listWidget = QtWidgets.QListWidget(self.centralwidget)sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)sizePolicy.setHorizontalStretch(0)sizePolicy.setVerticalStretch(0)sizePolicy.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth())self.listWidget.setSizePolicy(sizePolicy)self.listWidget.setStyleSheet("\n"
"\n"
"QListWidget::item:selected\n"
"{\n"
"    background: #f5d6db;\n"
"    color: rgb(83, 83, 83);\n"
"}\n"
"")self.listWidget.setObjectName("listWidget")item = QtWidgets.QListWidgetItem()self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()self.listWidget.addItem(item)item = QtWidgets.QListWidgetItem()self.listWidget.addItem(item)self.horizontalLayout_3.addWidget(self.listWidget)self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)sizePolicy.setHorizontalStretch(0)sizePolicy.setVerticalStretch(0)sizePolicy.setHeightForWidth(self.stackedWidget.sizePolicy().hasHeightForWidth())self.stackedWidget.setSizePolicy(sizePolicy)self.stackedWidget.setLineWidth(0)self.stackedWidget.setObjectName("stackedWidget")self.page = QtWidgets.QWidget()self.page.setObjectName("page")self.verticalLayout = QtWidgets.QVBoxLayout(self.page)self.verticalLayout.setObjectName("verticalLayout")self.horizontalLayout = QtWidgets.QHBoxLayout()self.horizontalLayout.setObjectName("horizontalLayout")spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout.addItem(spacerItem)self.label = QtWidgets.QLabel(self.page)self.label.setObjectName("label")self.horizontalLayout.addWidget(self.label)self.input_server_ip = QtWidgets.QLineEdit(self.page)self.input_server_ip.setObjectName("input_server_ip")self.horizontalLayout.addWidget(self.input_server_ip)spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout.addItem(spacerItem1)self.verticalLayout.addLayout(self.horizontalLayout)self.horizontalLayout_2 = QtWidgets.QHBoxLayout()self.horizontalLayout_2.setObjectName("horizontalLayout_2")spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_2.addItem(spacerItem2)self.label_2 = QtWidgets.QLabel(self.page)self.label_2.setObjectName("label_2")self.horizontalLayout_2.addWidget(self.label_2)self.input_server_port = QtWidgets.QLineEdit(self.page)self.input_server_port.setObjectName("input_server_port")self.horizontalLayout_2.addWidget(self.input_server_port)spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_2.addItem(spacerItem3)self.verticalLayout.addLayout(self.horizontalLayout_2)self.horizontalLayout_7 = QtWidgets.QHBoxLayout()self.horizontalLayout_7.setObjectName("horizontalLayout_7")spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_7.addItem(spacerItem4)self.btn_connect_server = QtWidgets.QPushButton(self.page)self.btn_connect_server.setObjectName("btn_connect_server")self.horizontalLayout_7.addWidget(self.btn_connect_server)spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_7.addItem(spacerItem5)self.verticalLayout.addLayout(self.horizontalLayout_7)self.stackedWidget.addWidget(self.page)self.page_2 = QtWidgets.QWidget()self.page_2.setObjectName("page_2")self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.page_2)self.verticalLayout_3.setObjectName("verticalLayout_3")self.horizontalLayout_8 = QtWidgets.QHBoxLayout()self.horizontalLayout_8.setObjectName("horizontalLayout_8")spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_8.addItem(spacerItem6)self.label_3 = QtWidgets.QLabel(self.page_2)self.label_3.setObjectName("label_3")self.horizontalLayout_8.addWidget(self.label_3)self.input_devSn = QtWidgets.QLineEdit(self.page_2)self.input_devSn.setObjectName("input_devSn")self.horizontalLayout_8.addWidget(self.input_devSn)spacerItem7 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_8.addItem(spacerItem7)self.verticalLayout_3.addLayout(self.horizontalLayout_8)self.horizontalLayout_10 = QtWidgets.QHBoxLayout()self.horizontalLayout_10.setObjectName("horizontalLayout_10")spacerItem8 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_10.addItem(spacerItem8)self.label_4 = QtWidgets.QLabel(self.page_2)self.label_4.setObjectName("label_4")self.horizontalLayout_10.addWidget(self.label_4)self.input_devState = QtWidgets.QLineEdit(self.page_2)self.input_devState.setStyleSheet("")self.input_devState.setObjectName("input_devState")self.horizontalLayout_10.addWidget(self.input_devState)spacerItem9 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_10.addItem(spacerItem9)self.verticalLayout_3.addLayout(self.horizontalLayout_10)self.horizontalLayout_9 = QtWidgets.QHBoxLayout()self.horizontalLayout_9.setObjectName("horizontalLayout_9")spacerItem10 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_9.addItem(spacerItem10)self.btn_set = QtWidgets.QPushButton(self.page_2)self.btn_set.setObjectName("btn_set")self.horizontalLayout_9.addWidget(self.btn_set)spacerItem11 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_9.addItem(spacerItem11)self.verticalLayout_3.addLayout(self.horizontalLayout_9)self.stackedWidget.addWidget(self.page_2)self.page_3 = QtWidgets.QWidget()self.page_3.setObjectName("page_3")self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.page_3)self.verticalLayout_4.setObjectName("verticalLayout_4")self.horizontalLayout_12 = QtWidgets.QHBoxLayout()self.horizontalLayout_12.setObjectName("horizontalLayout_12")spacerItem12 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_12.addItem(spacerItem12)self.label_6 = QtWidgets.QLabel(self.page_3)self.label_6.setObjectName("label_6")self.horizontalLayout_12.addWidget(self.label_6)self.output_devSn = QtWidgets.QLineEdit(self.page_3)self.output_devSn.setObjectName("output_devSn")self.horizontalLayout_12.addWidget(self.output_devSn)spacerItem13 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_12.addItem(spacerItem13)self.verticalLayout_4.addLayout(self.horizontalLayout_12)self.horizontalLayout_11 = QtWidgets.QHBoxLayout()self.horizontalLayout_11.setObjectName("horizontalLayout_11")spacerItem14 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_11.addItem(spacerItem14)self.label_5 = QtWidgets.QLabel(self.page_3)self.label_5.setObjectName("label_5")self.horizontalLayout_11.addWidget(self.label_5)self.output_devState = QtWidgets.QLineEdit(self.page_3)self.output_devState.setStyleSheet("")self.output_devState.setObjectName("output_devState")self.horizontalLayout_11.addWidget(self.output_devState)spacerItem15 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_11.addItem(spacerItem15)self.verticalLayout_4.addLayout(self.horizontalLayout_11)self.horizontalLayout_13 = QtWidgets.QHBoxLayout()self.horizontalLayout_13.setObjectName("horizontalLayout_13")spacerItem16 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_13.addItem(spacerItem16)self.btn_get_sn = QtWidgets.QPushButton(self.page_3)self.btn_get_sn.setObjectName("btn_get_sn")self.horizontalLayout_13.addWidget(self.btn_get_sn)spacerItem17 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_13.addItem(spacerItem17)self.btn_get_state = QtWidgets.QPushButton(self.page_3)self.btn_get_state.setObjectName("btn_get_state")self.horizontalLayout_13.addWidget(self.btn_get_state)spacerItem18 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)self.horizontalLayout_13.addItem(spacerItem18)self.verticalLayout_4.addLayout(self.horizontalLayout_13)self.stackedWidget.addWidget(self.page_3)self.horizontalLayout_3.addWidget(self.stackedWidget)self.verticalLayout_5.addLayout(self.horizontalLayout_3)self.horizontalLayout_4 = QtWidgets.QHBoxLayout()self.horizontalLayout_4.setObjectName("horizontalLayout_4")self.msgWindow = QtWidgets.QTextBrowser(self.centralwidget)sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)sizePolicy.setHorizontalStretch(0)sizePolicy.setVerticalStretch(0)sizePolicy.setHeightForWidth(self.msgWindow.sizePolicy().hasHeightForWidth())self.msgWindow.setSizePolicy(sizePolicy)self.msgWindow.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored)self.msgWindow.setObjectName("msgWindow")self.horizontalLayout_4.addWidget(self.msgWindow)self.verticalLayout_2 = QtWidgets.QVBoxLayout()self.verticalLayout_2.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)self.verticalLayout_2.setSpacing(0)self.verticalLayout_2.setObjectName("verticalLayout_2")self.msg_list = QtWidgets.QListWidget(self.centralwidget)sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)sizePolicy.setHorizontalStretch(0)sizePolicy.setVerticalStretch(0)sizePolicy.setHeightForWidth(self.msg_list.sizePolicy().hasHeightForWidth())self.msg_list.setSizePolicy(sizePolicy)self.msg_list.setStyleSheet("")self.msg_list.setLineWidth(0)self.msg_list.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContentsOnFirstShow)self.msg_list.setObjectName("msg_list")self.verticalLayout_2.addWidget(self.msg_list)self.msg_head_list = QtWidgets.QListWidget(self.centralwidget)sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)sizePolicy.setHorizontalStretch(0)sizePolicy.setVerticalStretch(0)sizePolicy.setHeightForWidth(self.msg_head_list.sizePolicy().hasHeightForWidth())self.msg_head_list.setSizePolicy(sizePolicy)self.msg_head_list.setBaseSize(QtCore.QSize(0, 30))self.msg_head_list.setStyleSheet("QListWidget::item {\n"
"    height: 30px;\n"
"}\n"
"\n"
"QListWidget{\n"
"        color:green;\n"
"}\n"
"")self.msg_head_list.setLineWidth(0)self.msg_head_list.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)self.msg_head_list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)self.msg_head_list.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)self.msg_head_list.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop)self.msg_head_list.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)self.msg_head_list.setMovement(QtWidgets.QListView.Free)self.msg_head_list.setResizeMode(QtWidgets.QListView.Adjust)self.msg_head_list.setViewMode(QtWidgets.QListView.IconMode)self.msg_head_list.setWordWrap(False)self.msg_head_list.setItemAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignCenter|QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)self.msg_head_list.setObjectName("msg_head_list")self.verticalLayout_2.addWidget(self.msg_head_list)self.msg_body_table = QtWidgets.QTableWidget(self.centralwidget)sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)sizePolicy.setHorizontalStretch(0)sizePolicy.setVerticalStretch(0)sizePolicy.setHeightForWidth(self.msg_body_table.sizePolicy().hasHeightForWidth())self.msg_body_table.setSizePolicy(sizePolicy)self.msg_body_table.setStyleSheet("QTableWidget::item{\n"
"    text-align:center;\n"
"}\n"
"QTableWidget::item:hover{\n"
"    background:#FFFFFF;\n"
"}")self.msg_body_table.setLineWidth(0)self.msg_body_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored)self.msg_body_table.setObjectName("msg_body_table")self.msg_body_table.setColumnCount(4)self.msg_body_table.setRowCount(0)item = QtWidgets.QTableWidgetItem()brush = QtGui.QBrush(QtGui.QColor(35, 206, 250))brush.setStyle(QtCore.Qt.NoBrush)item.setForeground(brush)self.msg_body_table.setHorizontalHeaderItem(0, item)item = QtWidgets.QTableWidgetItem()brush = QtGui.QBrush(QtGui.QColor(35, 206, 250))brush.setStyle(QtCore.Qt.NoBrush)item.setForeground(brush)self.msg_body_table.setHorizontalHeaderItem(1, item)item = QtWidgets.QTableWidgetItem()item.setBackground(QtGui.QColor(35, 206, 250))self.msg_body_table.setHorizontalHeaderItem(2, item)item = QtWidgets.QTableWidgetItem()item.setBackground(QtGui.QColor(35, 206, 250))self.msg_body_table.setHorizontalHeaderItem(3, item)self.verticalLayout_2.addWidget(self.msg_body_table)self.horizontalLayout_4.addLayout(self.verticalLayout_2)self.verticalLayout_5.addLayout(self.horizontalLayout_4)MainWindow.setCentralWidget(self.centralwidget)self.menubar = QtWidgets.QMenuBar(MainWindow)self.menubar.setGeometry(QtCore.QRect(0, 0, 593, 25))self.menubar.setObjectName("menubar")MainWindow.setMenuBar(self.menubar)self.statusbar = QtWidgets.QStatusBar(MainWindow)self.statusbar.setObjectName("statusbar")MainWindow.setStatusBar(self.statusbar)self.retranslateUi(MainWindow)self.stackedWidget.setCurrentIndex(2)QtCore.QMetaObject.connectSlotsByName(MainWindow)def retranslateUi(self, MainWindow):_translate = QtCore.QCoreApplication.translateMainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))__sortingEnabled = self.listWidget.isSortingEnabled()self.listWidget.setSortingEnabled(False)item = self.listWidget.item(0)item.setText(_translate("MainWindow", "连接设备"))item = self.listWidget.item(1)item.setText(_translate("MainWindow", "设置风泵状态"))item = self.listWidget.item(2)item.setText(_translate("MainWindow", "读取风泵状态"))self.listWidget.setSortingEnabled(__sortingEnabled)self.label.setText(_translate("MainWindow", "地址"))self.input_server_ip.setText(_translate("MainWindow", "127.0.0.1"))self.label_2.setText(_translate("MainWindow", "端口"))self.input_server_port.setText(_translate("MainWindow", "30088"))self.btn_connect_server.setText(_translate("MainWindow", "连接"))self.label_3.setText(_translate("MainWindow", "设备编号"))self.label_4.setText(_translate("MainWindow", "设备状态"))self.btn_set.setText(_translate("MainWindow", "设置"))self.label_6.setText(_translate("MainWindow", "设备编号"))self.label_5.setText(_translate("MainWindow", "设备状态"))self.btn_get_sn.setText(_translate("MainWindow", "读取编号"))self.btn_get_state.setText(_translate("MainWindow", "读取状态"))item = self.msg_body_table.horizontalHeaderItem(0)item.setText(_translate("MainWindow", "字段名"))item = self.msg_body_table.horizontalHeaderItem(1)item.setText(_translate("MainWindow", "字段码"))item = self.msg_body_table.horizontalHeaderItem(2)item.setText(_translate("MainWindow", "字段长"))item = self.msg_body_table.horizontalHeaderItem(3)item.setText(_translate("MainWindow", "字段值"))

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/491862.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HCIA-Access V2.5_4_1_1路由协议基础_IP路由表

大型网络的拓扑结构一般会比较复杂&#xff0c;不同的部门&#xff0c;或者总部和分支可能处在不同的网络中&#xff0c;此时就需要使用路由器来连接不同的网络&#xff0c;实现网络之间的数据转发。 本章将介绍路由协议的基础知识、路由表的分类、静态路由基础与配置、VLAN间…

ISCTF复现-misc

File_Format 下载附件后用010打开查看文件头会发现是个exe文件 格式&#xff1a;文件描述&#xff08;后缀名&#xff09;&#xff0c;文件头(hex)&#xff1a;文件头标识&#xff08;十六进制&#xff09;PNG (png)&#xff0c;文件头(hex)&#xff1a;89504E47 PNGImageFile…

Windows设置所有软件默认以管理员身份运行

方法一、修改注册表 winr打开运行&#xff0c;输入“regedit”打开注册表&#xff1b; 打开此路径“计算机HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem”&#xff1b; 在右侧找到“EnableLUA”&#xff0c;将其值改为0&#xff0c;重启电脑。 …

【题解】—— LeetCode一周小结50

&#x1f31f;欢迎来到 我的博客 —— 探索技术的无限可能&#xff01; &#x1f31f;博客的简介&#xff08;文章目录&#xff09; 【题解】—— 每日一道题目栏 上接&#xff1a;【题解】—— LeetCode一周小结49 9.判断国际象棋棋盘中一个格子的颜色 题目链接&#xff1a;…

Docker安全性与最佳实践

一、引言&#xff1a;Docker安全性的重要性 Docker作为一种容器化技术&#xff0c;已成为现代应用程序部署和开发的核心工具。然而&#xff0c;随着容器化应用的普及&#xff0c;Docker的安全性问题也日益突出。容器本身的隔离性、网络配置、权限管理等方面的安全隐患&#xf…

利用notepad++删除特定关键字所在的行

1、按组合键Ctrl H&#xff0c;查找模式选择 ‘正则表达式’&#xff0c;不选 ‘.匹配新行’ 2、查找目标输入 &#xff1a; ^.*关键字.*\r\n (不保留空行) ^.*关键字.*$ (保留空行)3、替换为&#xff1a;&#xff08;空&#xff09; 配置界面参考下图&#xff1a; ​​…

上传图片的预览

解决:在上传图片时,1显示已有的图片 2显示准备替换的图片 前 后 在这个案例中可以预览到 【已有与准备替换】 2张图片 具体流程 1创建一个共享组件 与manage.py同级别路径的文件 manage.py custom_widgets.py# custom_widgets.py from django import forms from dja…

MySQL学习之DDL操作

目录 数据库的操作 创建 查看 选择 删除 修改 数据类型 表的创建 表的修改 表的约束 主键 PRIMARY KEY 唯一性约束 UNIQUE 非空约束 NOT NULL 外键约束 约束小结 索引 索引分类 常规索引 主键索引 唯一索引 外键索引 优点 缺点 视图 创建 删除 修改…

国际网络专线是什么?有什么优势?

国际网络专线作为一种独立的网络连接方式&#xff0c;通过卫星或海底光缆等物理链路&#xff0c;将全球不同国家和地区的网络直接互联&#xff0c;为企业提供了可靠的通信渠道。本文将详细探讨国际网络专线的优势以及其广泛的应用场景。 国际网络专线的优势解析 1. 专属连接&am…

密码编码学与网络安全(第五版)答案

通过如下代码分别统计一个字符的频率和三个字符的频率&#xff0c;"8"——"e"&#xff0c;“&#xff1b;48”——“the”&#xff0c;英文字母的相对使用频率&#xff0c;猜测频率比较高的依此为&#xff09;&#xff0c;t,*,5&#xff0c;分别对应s,o,n,…

【功能安全】随机硬件失效导致违背安全目标的评估(FMEDA)

目录 01 随机硬件失效介绍 02 FMEDA介绍 03 FMEDA模板 01 随机硬件失效介绍 GBT 34590 part5

mybatis 的动态sql 和缓存

动态SQL 可以根据具体的参数条件&#xff0c;来对SQL语句进行动态拼接。 比如在以前的开发中&#xff0c;由于不确定查询参数是否存在&#xff0c;许多人会使用类似于where 1 1 来作为前缀&#xff0c;然后后面用AND 拼接要查询的参数&#xff0c;这样&#xff0c;就算要查询…

Web APIs - 第5章笔记

目标&#xff1a; 依托 BOM 对象实现对历史、地址、浏览器信息的操作或获取 具备利用本地存储实现学生就业表案例的能力 BOM操作 综合案例 JavaScript的组成 ECMAScript: 规定了js基础语法核心知识。 比如&#xff1a;变量、分支语句、循环语句、对象等等 Web APIs : DO…

AI视频配音技术创新应用与商业机遇

随着人工智能技术的飞速发展&#xff0c;AI视频配音技术已经成为内容创作者和营销人员的新宠。这项技术不仅能够提升视频内容的吸引力&#xff0c;还能为特定行业带来创新的解决方案。本文将探讨AI视频配音技术的应用场景&#xff0c;并讨论如何合法合规地利用这一技术。 AI视频…

vlan和vlanif

文章目录 1、为什么会有vlan的存在2、vlan(虚拟局域网)1、vlan原理1. 为什么这样划分了2、如何实现不同交换机相同的vlan实现互访呢3、最优化的解决方法&#xff0c;vlan不同交换机4、vlan标签和vlan数据帧 5、vlan实现2、基于vlan的划分方式1、基于接口的vlan划分方式2、基于m…

Java每日一题(1)

给定n个数a1,a2,...an,求它们两两相乘再相加的和。 即&#xff1a;Sa1*a2a1*a3...a1*ana2*a3...an-2*an-1an-2*anan-1*an 第一行输入的包含一个整数n。 第二行输入包含n个整数a1,a2,...an。 样例输入 4 1 3 6 9 样例输出 117 答案 import java.util.Scanner; // 1:无…

Redis应用—6.热key探测设计与实践

大纲 1.热key引发的巨大风险 2.以往热key问题怎么解决 3.热key进内存后的优势 4.热key探测关键指标 5.热key探测框架JdHotkey的简介 6.热key探测框架JdHotkey的组成 7.热key探测框架JdHotkey的工作流程 8.热key探测框架JdHotkey的性能表现 9.关于热key探测框架JdHotke…

Elasticsearch:使用 Open Crawler 和 semantic text 进行语义搜索

作者&#xff1a;来自 Elastic Jeff Vestal 了解如何使用开放爬虫与 semantic text 字段结合来轻松抓取网站并使其可进行语义搜索。 Elastic Open Crawler 演练 我们在这里要做什么&#xff1f; Elastic Open Crawler 是 Elastic 托管爬虫的后继者。 Semantic text 是 Elasti…

python爬虫入门教程

安装python 中文网 Python中文网 官网 安装好后打开命令行执行&#xff08;如果没有勾选添加到Path则注意配置环境变量&#xff09; python 出现如上界面则安装成功 设置环境变量 右键我的电脑->属性 设置下载依赖源 默认的是官网比较慢&#xff0c;可以设置为清华大…

数据结十大排序之(冒泡,快排,并归)

接上期&#xff1a; 数据结十大排序之&#xff08;选排&#xff0c;希尔&#xff0c;插排&#xff0c;堆排&#xff09;-CSDN博客 前言&#xff1a; 在计算机科学中&#xff0c;排序算法是最基础且最重要的算法之一。无论是大规模数据处理还是日常的小型程序开发&#xff0c;…