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.
213 lines
7.5 KiB
Python
213 lines
7.5 KiB
Python
from PyQt5.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
|
|
QMetaObject, QObject, QPoint, QRect,
|
|
QSize, QTime, QUrl, Qt)
|
|
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, QComboBox, QGridLayout, QLabel,
|
|
QLineEdit, QPushButton, QSizePolicy, QSpacerItem, QListView,
|
|
QWidget, QMessageBox, QListView)
|
|
|
|
from utils.DBModels.ProtocolModel import RTUSetting
|
|
|
|
|
|
class CustomBox(QComboBox):
|
|
def __init__(self):
|
|
super(CustomBox, self).__init__()
|
|
self.setCursor(Qt.PointingHandCursor)
|
|
self.setView(QListView())
|
|
|
|
|
|
def showPopup(self):
|
|
QComboBox.showPopup(self)
|
|
pop = self.children()[1]
|
|
pop.move(pop.x(), pop.y() + 51)
|
|
|
|
|
|
class RTUSettingWidget(QWidget):
|
|
def __init__(self):
|
|
super(RTUSettingWidget, self).__init__()
|
|
|
|
self.gridLayout_2 = QGridLayout(self)
|
|
self.gridLayout_2.setObjectName("gridLayout_2")
|
|
self.gridLayout = QGridLayout()
|
|
self.gridLayout.setObjectName("gridLayout")
|
|
self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.gridLayout.addItem(self.horizontalSpacer_3, 5, 0, 1, 2)
|
|
|
|
self.byteSizeBox = CustomBox()
|
|
self.byteSizeBox.addItem("8")
|
|
self.byteSizeBox.addItem("7")
|
|
self.byteSizeBox.setObjectName("setBox")
|
|
|
|
self.gridLayout.addWidget(self.byteSizeBox, 4, 1, 1, 1)
|
|
|
|
self.label = QLabel(self)
|
|
self.label.setObjectName("setlabel")
|
|
|
|
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
|
|
|
|
self.label_4 = QLabel(self)
|
|
self.label_4.setObjectName("setlabel")
|
|
|
|
self.gridLayout.addWidget(self.label_4, 8, 0, 1, 1)
|
|
|
|
self.baudrateEdit = QLineEdit(self)
|
|
self.baudrateEdit.setObjectName("setEdit")
|
|
|
|
self.gridLayout.addWidget(self.baudrateEdit, 2, 1, 1, 1)
|
|
|
|
self.stopbitsBox = CustomBox()
|
|
self.stopbitsBox.addItem("1")
|
|
self.stopbitsBox.addItem("2")
|
|
self.stopbitsBox.setObjectName("setBox")
|
|
|
|
self.gridLayout.addWidget(self.stopbitsBox, 8, 1, 1, 1)
|
|
|
|
self.freEdit = QLineEdit(self)
|
|
self.freEdit.setObjectName("setEdit")
|
|
|
|
self.gridLayout.addWidget(self.freEdit, 10, 1, 1, 1)
|
|
|
|
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.gridLayout.addItem(self.horizontalSpacer, 1, 0, 1, 2)
|
|
|
|
self.label_6 = QLabel(self)
|
|
self.label_6.setObjectName("setlabel")
|
|
|
|
self.gridLayout.addWidget(self.label_6, 10, 0, 1, 1)
|
|
|
|
self.label_3 = QLabel(self)
|
|
self.label_3.setObjectName("setlabel")
|
|
|
|
self.gridLayout.addWidget(self.label_3, 6, 0, 1, 1)
|
|
|
|
self.label_5 = QLabel(self)
|
|
self.label_5.setObjectName("setlabel")
|
|
|
|
self.gridLayout.addWidget(self.label_5, 2, 0, 1, 1)
|
|
|
|
self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.gridLayout.addItem(self.horizontalSpacer_4, 7, 0, 1, 2)
|
|
|
|
self.portEdit = QLineEdit(self)
|
|
self.portEdit.setObjectName("setEdit")
|
|
|
|
self.gridLayout.addWidget(self.portEdit, 0, 1, 1, 1)
|
|
|
|
self.label_2 = QLabel(self)
|
|
self.label_2.setObjectName("setlabel")
|
|
|
|
self.gridLayout.addWidget(self.label_2, 4, 0, 1, 1)
|
|
|
|
self.parityBox = CustomBox()
|
|
self.parityBox.addItem("N 无")
|
|
self.parityBox.addItem("O 奇")
|
|
self.parityBox.addItem("E 偶")
|
|
self.parityBox.setObjectName("setBox")
|
|
|
|
self.gridLayout.addWidget(self.parityBox, 6, 1, 1, 1)
|
|
|
|
self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.gridLayout.addItem(self.horizontalSpacer_2, 3, 0, 1, 2)
|
|
|
|
self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.gridLayout.addItem(self.horizontalSpacer_5, 9, 0, 1, 2)
|
|
|
|
self.offsetBox = CustomBox()
|
|
self.offsetBox.addItem("1")
|
|
self.offsetBox.addItem("0")
|
|
self.offsetBox.setObjectName("setBox")
|
|
|
|
self.gridLayout.addItem(QSpacerItem(40, 20), 11, 0, 1, 2)
|
|
|
|
self.label_7 = QLabel('起始值')
|
|
self.label_7.setObjectName('setlabel')
|
|
self.gridLayout.addWidget(self.label_7, 12, 0, 1, 1)
|
|
|
|
self.gridLayout.addWidget(self.offsetBox, 12, 1, 1, 1)
|
|
|
|
self.gridLayout.addItem(QSpacerItem(40, 20), 13, 0, 1, 2)
|
|
|
|
|
|
self.gridLayout_2.addLayout(self.gridLayout, 3, 5, 2, 2)
|
|
|
|
self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
|
|
|
self.gridLayout_2.addItem(self.verticalSpacer, 0, 1, 3, 12)
|
|
|
|
self.saveButton = QPushButton(self)
|
|
self.saveButton.setObjectName("setButton")
|
|
|
|
self.gridLayout.addWidget(self.saveButton, 15, 1, 1, 1)
|
|
|
|
self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.gridLayout_2.addItem(self.horizontalSpacer_6, 7, 0, 3, 5)
|
|
|
|
self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.gridLayout_2.addItem(self.horizontalSpacer_7, 7, 2, 3, 5)
|
|
|
|
self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
|
|
|
self.gridLayout_2.addItem(self.verticalSpacer_2, 7, 0, 3, 5)
|
|
|
|
|
|
self.label.setText(QCoreApplication.translate("self", u"\u7aef\u53e3\u53f7", None))
|
|
self.label_4.setText(QCoreApplication.translate("self", u"\u505c\u6b62\u4f4d", None))
|
|
|
|
self.label_6.setText(QCoreApplication.translate("self", u"\u901a\u4fe1\u9891\u7387", None))
|
|
self.label_3.setText(QCoreApplication.translate("self", u"\u5947\u5076\u6821\u9a8c", None))
|
|
self.label_5.setText(QCoreApplication.translate("self", u"\u6ce2\u7279\u7387", None))
|
|
self.label_2.setText(QCoreApplication.translate("self", u"\u5b57\u8282\u957f\u5ea6", None))
|
|
|
|
self.saveButton.setText(QCoreApplication.translate("self", u"\u4fdd\u5b58", None))
|
|
|
|
self.saveButton.clicked.connect(self.saveSetting)
|
|
|
|
|
|
# self.setupUi()
|
|
|
|
# retranslateUi
|
|
|
|
def setupUI(self):
|
|
# port = CharField()
|
|
# byteSize = IntegerField()
|
|
# baudrate = IntegerField()
|
|
# stopbits = IntegerField()
|
|
# parity = CharField()
|
|
# frequency = CharField()
|
|
query = RTUSetting.get_by_id(1)
|
|
port = str(query.port)
|
|
byteSize = str(query.byteSize)
|
|
baudrate = str(query.baudrate)
|
|
stopbits = str(query.stopbits)
|
|
parity = str(query.parity)
|
|
frequency = str(query.frequency)
|
|
offset = str(query.offset)
|
|
|
|
self.portEdit.setText(port)
|
|
self.byteSizeBox.setCurrentText(byteSize)
|
|
self.baudrateEdit.setText(baudrate)
|
|
self.stopbitsBox.setCurrentText(stopbits)
|
|
self.freEdit.setText(frequency)
|
|
self.offsetBox.setCurrentText(offset)
|
|
self.parityBox.setCurrentText(parity)
|
|
|
|
def saveSetting(self):
|
|
port = self.portEdit.text()
|
|
byteSize = self.byteSizeBox.currentText()
|
|
baudrate = self.baudrateEdit.text()
|
|
stopbits = self.stopbitsBox.currentText()
|
|
parity = self.parityBox.currentText()
|
|
frequency = self.freEdit.text()
|
|
offset = self.offsetBox.currentText()
|
|
RTUSetting.update(port = port, byteSize = byteSize, baudrate = baudrate, stopbits = stopbits, parity = parity, frequency = frequency, offset = offset).where(RTUSetting.id == 1).execute()
|
|
QMessageBox.information(self, 'Sucess', '保存成功') |