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.
166 lines
6.4 KiB
Python
166 lines
6.4 KiB
Python
2 years ago
|
|
||
2 years ago
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout, QLabel, QPushButton, QLayout, \
|
||
|
QHBoxLayout, QComboBox, QLineEdit, QSpacerItem, QSizePolicy, QGridLayout, QMessageBox, QSplitter, QFrame
|
||
|
import re
|
||
|
class forceButton(QPushButton):
|
||
2 years ago
|
def __init__(self, number = None, valueLabel = None, valueEdit = None):
|
||
2 years ago
|
super().__init__()
|
||
|
self.valueEdit = valueEdit
|
||
2 years ago
|
self.valueLabel = valueLabel
|
||
|
self.number = number
|
||
2 years ago
|
self.setObjectName('forceBtn')
|
||
|
self.setText('强制')
|
||
|
|
||
2 years ago
|
class RightAreaWidgets(QWidget):
|
||
2 years ago
|
def __init__(self, areaWidget, order, byteLineEdit, dataType, deviceName):
|
||
|
super().__init__()
|
||
2 years ago
|
self.areaLineEditValue = []
|
||
|
self.areaLabel = {}
|
||
2 years ago
|
self.areaWidget = areaWidget
|
||
2 years ago
|
self.devicesManange = self.areaWidget.devicesManange
|
||
2 years ago
|
self.order = order
|
||
|
self.byteLineEdit = byteLineEdit
|
||
|
self.dataType = dataType
|
||
|
self.deviceName = deviceName
|
||
|
self.addLayout()
|
||
2 years ago
|
|
||
|
# self.setStyleSheet("background-color: black")
|
||
2 years ago
|
|
||
|
|
||
|
|
||
|
def addLayout(self):
|
||
|
self.setLayout(self.areaLayout())
|
||
|
|
||
|
|
||
|
def areaLayout(self):
|
||
|
areaLayout = QVBoxLayout()
|
||
|
if self.dataType in ['AI','AO']:
|
||
|
hLayout = QHBoxLayout()
|
||
2 years ago
|
hLayout.addWidget(QSplitter())
|
||
2 years ago
|
hLayout.addLayout(self.dateLayout(1))
|
||
|
hLayout.addWidget(QSplitter())
|
||
2 years ago
|
areaLayout.addWidget(QSplitter())
|
||
2 years ago
|
areaLayout.addLayout(hLayout)
|
||
|
areaLayout.addWidget(QSplitter())
|
||
|
else:
|
||
|
byteLineEdit = int(self.byteLineEdit) * 4
|
||
2 years ago
|
areaLayout.addWidget(QSplitter())
|
||
2 years ago
|
for i in range(int(byteLineEdit)):
|
||
|
hLayout = QHBoxLayout()
|
||
2 years ago
|
hLayout.addWidget(QSplitter(), 1)
|
||
|
hLayout.addLayout(self.dateLayout(number = (i + 1)), 3)
|
||
|
hLayout.addWidget(QSplitter(), 1)
|
||
|
hLayout.addLayout(self.dateLayout(number = (i + 1) + 8), 3)
|
||
|
hLayout.addWidget(QSplitter(), 1)
|
||
2 years ago
|
areaLayout.addLayout(hLayout)
|
||
|
areaLayout.addWidget(QSplitter())
|
||
2 years ago
|
|
||
2 years ago
|
return areaLayout
|
||
|
|
||
|
def dateLayout(self, number, force = True):
|
||
|
number = number
|
||
|
|
||
|
forceLayout = QHBoxLayout()
|
||
2 years ago
|
areaMessLabel = QLabel(str(self.dataType) + "{:<{}}".format(str(number), 2) + ": " + '字节长度: ' + str(self.byteLineEdit) + ' 当前值:' )
|
||
2 years ago
|
areaMessLabel.setObjectName('areaMessLabel')
|
||
|
areaValueLabel = QLabel('0')
|
||
|
areaValueLabel.setObjectName('areaValueLabel')
|
||
|
forceLayout.addWidget(areaMessLabel)
|
||
|
forceLayout.addWidget(areaValueLabel)
|
||
|
|
||
|
|
||
|
if '主站' in self.deviceName and self.dataType == 'AI' or ('从站' in self.deviceName and self.dataType == 'AO'):
|
||
|
force = False
|
||
2 years ago
|
self.areaLabel[number - 1] = areaValueLabel
|
||
2 years ago
|
elif '主站' in self.deviceName and self.dataType == 'DI' or ('从站' in self.deviceName and self.dataType == 'DO'):
|
||
|
force = False
|
||
2 years ago
|
self.areaLabel[number - 1] = areaValueLabel
|
||
|
|
||
2 years ago
|
|
||
|
if force:
|
||
|
areaLineEdit = QLineEdit('0')
|
||
|
areaLineEdit.setObjectName('areaLineEdit')
|
||
2 years ago
|
areaLineEdit.setFixedSize(80, 33)
|
||
2 years ago
|
forceBtn = forceButton(number = number, valueLabel=areaValueLabel, valueEdit=areaLineEdit)
|
||
2 years ago
|
forceBtn.clicked.connect(self.forceValues)
|
||
2 years ago
|
# forceBtn.setFixedSize(50, 27)
|
||
2 years ago
|
forceLayout.addWidget(areaLineEdit)
|
||
|
forceLayout.addWidget(forceBtn)
|
||
2 years ago
|
self.areaLineEditValue.append(0)
|
||
|
|
||
|
if self.deviceName[-2:] + self.dataType in ['从站DI','主站DO']:
|
||
|
areaMessLabel.setObjectName('wirteDIDOareaMessLabel')
|
||
|
areaValueLabel.setObjectName('wirteDIDOareaValueLabel')
|
||
|
areaLineEdit.setObjectName('wirteDIDOareaLineEdit')
|
||
|
areaLineEdit.setFixedSize(30, 27)
|
||
|
forceBtn.setObjectName('wirteDIDOforceBtn')
|
||
|
|
||
|
if self.deviceName[-2:] + self.dataType in ['主站DI','从站DO']:
|
||
|
areaMessLabel.setObjectName('readDIDOareaMessLabel')
|
||
|
areaValueLabel.setObjectName('readDIDOareaValueLabel')
|
||
|
|
||
|
|
||
2 years ago
|
|
||
2 years ago
|
|
||
|
|
||
|
# forceLayout.setSpacing(10)
|
||
2 years ago
|
return forceLayout
|
||
|
|
||
2 years ago
|
def wirteAreaLineEditValue(self,dataTypeAndModel, valueLabel, number, value):
|
||
|
|
||
2 years ago
|
if dataTypeAndModel in ['主站AO','从站AI']:
|
||
2 years ago
|
pattern = re.compile(r'^\d+(\.\d+)?$')
|
||
|
match = pattern.match(value)
|
||
|
if not match:
|
||
|
QMessageBox.warning(self, '提示', '请输入数字。')
|
||
|
return
|
||
|
else:
|
||
|
valueLabel.setText(value)
|
||
2 years ago
|
self.areaLineEditValue[number -1] = float(value)
|
||
2 years ago
|
|
||
2 years ago
|
#判断输入值是否为0和1
|
||
|
elif dataTypeAndModel in ['主站DO','从站DI']:
|
||
|
|
||
2 years ago
|
pattern = re.compile(r'^[01]$')
|
||
|
match = pattern.match(value)
|
||
|
if not match:
|
||
|
QMessageBox.warning(self, '提示', '请输入0或1。')
|
||
|
return
|
||
|
else:
|
||
|
valueLabel.setText(value)
|
||
|
self.areaLineEditValue[number -1] = value
|
||
|
|
||
|
return self.areaLineEditValue
|
||
2 years ago
|
|
||
2 years ago
|
|
||
2 years ago
|
def readValues(self, curIndex):
|
||
|
print(curIndex)
|
||
|
if self.areaLabel is None or self.areaLabel == dict():
|
||
2 years ago
|
return
|
||
2 years ago
|
# elif curIndex == -1:
|
||
|
# return
|
||
2 years ago
|
else:
|
||
2 years ago
|
print(self.deviceName, curIndex)
|
||
|
device = self.devicesManange.getDevice(self.deviceName)
|
||
2 years ago
|
values = device.getAreaValues(curIndex)
|
||
|
for index, value in enumerate(values):
|
||
2 years ago
|
self.areaLabel[index].setText(str(value))
|
||
|
# print(self.areaLabel[index],values)
|
||
2 years ago
|
|
||
2 years ago
|
|
||
|
|
||
|
def forceValues(self):
|
||
2 years ago
|
sender = self.sender()
|
||
|
number = sender.number
|
||
|
valueLabel = sender.valueLabel
|
||
|
value = sender.valueEdit.text()
|
||
2 years ago
|
dataTypeAndModel = self.deviceName[-2:] + self.dataType
|
||
|
curIndex = self.areaWidget.areaTabWidget.currentIndex()
|
||
2 years ago
|
valueList = self.wirteAreaLineEditValue(dataTypeAndModel=dataTypeAndModel, valueLabel=valueLabel,number=number, value=value)
|
||
2 years ago
|
print(valueList, curIndex)
|
||
2 years ago
|
if valueList is None:
|
||
|
return
|
||
2 years ago
|
else:
|
||
2 years ago
|
self.devicesManange.writeAreas(deviceName = self.deviceName, areaIndex = curIndex, values = valueList)
|
||
2 years ago
|
|
||
|
|