You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
4.4 KiB
Python
116 lines
4.4 KiB
Python
7 months ago
|
from PyQt5.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
|
||
|
QMetaObject, QObject, QPoint, QRect,
|
||
|
QSize, QTime, QUrl, Qt, QTimer)
|
||
|
from PyQt5.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
||
|
QFont, QFontDatabase, QGradient, QIcon,
|
||
|
QImage, QKeySequence, QLinearGradient, QPainter,
|
||
|
QPalette, QPixmap, QRadialGradient, QTransform)
|
||
|
from PyQt5.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, QLabel,
|
||
|
QPushButton, QSizePolicy, QSpacerItem, QTextEdit,
|
||
|
QWidget)
|
||
|
|
||
|
from protocol.Celery.MBTCPMaster import app
|
||
|
from Static import static
|
||
|
class MessageWidget(QWidget):
|
||
|
def __init__(self, parent=None):
|
||
|
super(MessageWidget, self).__init__(parent)
|
||
|
|
||
|
self.setObjectName(u"self")
|
||
|
self.resize(1037, 648)
|
||
|
|
||
|
self.decima = 16
|
||
|
|
||
|
self.recvLabel = QLabel(self)
|
||
|
self.recvLabel.setObjectName("mesLabel")
|
||
|
self.recvLabel.setAlignment(Qt.AlignCenter)
|
||
|
|
||
|
self.sendLabel = QLabel(self)
|
||
|
self.sendLabel.setObjectName("mesLabel")
|
||
|
self.sendLabel.setAlignment(Qt.AlignCenter)
|
||
|
|
||
|
self.clearButton = QPushButton(self)
|
||
|
self.clearButton.setObjectName("mesButton")
|
||
|
|
||
|
self.reButton = QPushButton(self)
|
||
|
self.reButton.setObjectName("mesButton")
|
||
|
|
||
|
self.decimaButton = QPushButton(self)
|
||
|
self.decimaButton.setObjectName("mesButton")
|
||
|
|
||
|
self.recvEdit = QTextEdit(self)
|
||
|
self.recvEdit.setObjectName("mesEdit")
|
||
|
|
||
|
self.sendEdit = QTextEdit(self)
|
||
|
self.sendEdit.setObjectName("mesEdit")
|
||
|
|
||
|
self.horizontalLayout = QHBoxLayout()
|
||
|
self.horizontalLayout.setObjectName("horizontalLayout")
|
||
|
self.horizontalLayout.addWidget(self.clearButton)
|
||
|
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
||
|
self.horizontalLayout.addItem(self.horizontalSpacer)
|
||
|
self.horizontalLayout.addWidget(self.reButton)
|
||
|
self.horizontalLayout.addWidget(self.decimaButton)
|
||
|
|
||
|
self.gridLayout = QGridLayout(self)
|
||
|
self.gridLayout.setObjectName("gridLayout")
|
||
|
self.gridLayout.addWidget(self.recvLabel, 1, 0, 1, 1)
|
||
|
self.gridLayout.addWidget(self.sendLabel, 1, 1, 1, 1)
|
||
|
self.gridLayout.addWidget(self.recvEdit, 2, 0, 1, 1)
|
||
|
self.gridLayout.addWidget(self.sendEdit, 2, 1, 1, 1)
|
||
|
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 2)
|
||
|
|
||
|
self.setWindowTitle('报文查看')
|
||
|
self.setWindowIcon(QIcon('./:/static/file.png'))
|
||
|
self.recvLabel.setText(QCoreApplication.translate("Form", u"\u63a5\u6536\u5230\u62a5\u6587", None))
|
||
|
self.sendLabel.setText(QCoreApplication.translate("Form", u"\u53d1\u9001\u7684\u62a5\u6587", None))
|
||
|
self.clearButton.setText("清空报文")
|
||
|
self.reButton.setText('停止刷新')
|
||
|
self.decimaButton.setText('切换进制')
|
||
|
|
||
|
self.timer = QTimer(self)
|
||
|
# 将定时器超时信号与槽函数showTime()连接
|
||
|
self.timer.timeout.connect(self.addText)
|
||
|
self.timer.start(1000) # 启动timer
|
||
|
|
||
|
self.reButton.clicked.connect(self.stopRe)
|
||
|
self.decimaButton.clicked.connect(self.changeDecima)
|
||
|
self.clearButton.clicked.connect(self.clearText)
|
||
|
|
||
|
def clearText(self):
|
||
|
self.recvEdit.clear()
|
||
|
self.sendEdit.clear()
|
||
|
|
||
|
def changeDecima(self):
|
||
|
if self.decima == 16:
|
||
|
self.decima = 10
|
||
|
elif self.decima == 10:
|
||
|
self.decima = 16
|
||
|
|
||
|
def stopRe(self):
|
||
|
if self.timer.isActive():
|
||
|
self.timer.stop()
|
||
|
self.reButton.setText('开始刷新')
|
||
|
else:
|
||
|
self.timer.start()
|
||
|
self.reButton.setText('停止刷新')
|
||
|
|
||
|
def addText(self):
|
||
|
try:
|
||
|
self.recvEdit.clear()
|
||
|
self.sendEdit.clear()
|
||
|
if self.decima == 16:
|
||
|
for x in app.backend.client.lrange("16R" , 0 , -1):
|
||
|
text = str(x)[2:-1]
|
||
|
self.recvEdit.append(text)
|
||
|
for x in app.backend.client.lrange("16S" , 0 , -1):
|
||
|
text = str(x)[2:-1]
|
||
|
self.sendEdit.append(text)
|
||
|
elif self.decima == 10:
|
||
|
for x in app.backend.client.lrange("10R" , 0 , -1):
|
||
|
text = str(x)[2:-1]
|
||
|
self.recvEdit.append(text)
|
||
|
for x in app.backend.client.lrange("10S" , 0 , -1):
|
||
|
text = str(x)[2:-1]
|
||
|
self.sendEdit.append(text)
|
||
|
except:
|
||
|
pass
|