|
|
|
@ -5,7 +5,7 @@ import qtawesome
|
|
|
|
|
from PyQt5 import QtGui,QtCore,QtWidgets
|
|
|
|
|
from PyQt5.QtCore import QAbstractTableModel, QModelIndex, Qt, QVariant, QSize
|
|
|
|
|
|
|
|
|
|
from PyQt5.QtWidgets import QItemDelegate, QHBoxLayout, QWidget, QTableView, QMessageBox, QComboBox
|
|
|
|
|
from PyQt5.QtWidgets import QItemDelegate, QHBoxLayout, QWidget, QTableView, QMessageBox, QComboBox, QStyleOptionViewItem
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from protocol.Celery.MBTCPMaster import app as MBTCPMApp
|
|
|
|
@ -76,6 +76,7 @@ class VarTableModel(QAbstractTableModel):
|
|
|
|
|
self.checkList = ['Unchecked'] * len(self.datas)
|
|
|
|
|
# self.layoutChanged.emit()
|
|
|
|
|
self.table.proxy.invalidate()
|
|
|
|
|
self.refreshComboBox()
|
|
|
|
|
|
|
|
|
|
def append_data(self, x):
|
|
|
|
|
|
|
|
|
@ -194,6 +195,24 @@ class VarTableModel(QAbstractTableModel):
|
|
|
|
|
self.datas[sourceRow], self.datas[destinationChild] = self.datas[destinationChild], self.datas[sourceRow]
|
|
|
|
|
self.table.proxy.invalidate()
|
|
|
|
|
|
|
|
|
|
def refreshComboBox(self):
|
|
|
|
|
# print(self.table.rowCount())
|
|
|
|
|
for i in range(len(self.datas)):
|
|
|
|
|
cbRow = str('cb' + str(i) + '5')
|
|
|
|
|
index = self.index(i, 5)
|
|
|
|
|
delegate = self.table.itemDelegate(index)
|
|
|
|
|
delegate.paint(self.table, QStyleOptionViewItem(), index)
|
|
|
|
|
try:
|
|
|
|
|
comboBox = getattr(delegate, cbRow)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
continue
|
|
|
|
|
if self.datas[i][5] in [0, 1]:
|
|
|
|
|
comboBox.setCurrentIndex(self.datas[i][5])
|
|
|
|
|
elif self.datas[i][5] in [3, 4]:
|
|
|
|
|
comboBox.setCurrentIndex(self.datas[i][5] - 1)
|
|
|
|
|
else:
|
|
|
|
|
comboBox.setCurrentIndex(-1)
|
|
|
|
|
|
|
|
|
|
class ModBusTCPSlaveModel(VarTableModel):
|
|
|
|
|
def __init__(self, header, data: list, table = None):
|
|
|
|
|
'''
|
|
|
|
@ -253,6 +272,7 @@ class VarButtonDelegate(QItemDelegate):
|
|
|
|
|
comboBox.addItem('BADC', 3)
|
|
|
|
|
comboBox.addItem('DCBA', 4)
|
|
|
|
|
comboBox.setCurrentText(self.parent().model.datas[index.row()][index.column()])
|
|
|
|
|
comboBox.setMinimumWidth(30)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
comboBox.currentIndexChanged.connect(self.indexChange)
|
|
|
|
@ -376,23 +396,26 @@ class VarButtonDelegate(QItemDelegate):
|
|
|
|
|
else:
|
|
|
|
|
varMes = model.datas[sender.index[0]]
|
|
|
|
|
name, des, varType, slaveID, address, min, max, order = str(varMes[3]), str(varMes[4]), str(varMes[5]), str(varMes[6]), str(varMes[7]), str(varMes[8]), str(varMes[9]), str(varMes[-1])
|
|
|
|
|
print(name, des, varType, slaveID, address, min, max, order)
|
|
|
|
|
# print(name, des, varType, slaveID, address, min, max, order)
|
|
|
|
|
if not name or not varType:
|
|
|
|
|
reply = QMessageBox.question(self.parent(),
|
|
|
|
|
'警告',
|
|
|
|
|
"有字段为空",
|
|
|
|
|
QMessageBox.Yes)
|
|
|
|
|
return
|
|
|
|
|
sender.isEdit = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkbox.setEnabled(False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.editableList.remove(sender.index[0])
|
|
|
|
|
if sender.oldName:
|
|
|
|
|
ModbusVarManage.editVar(name = sender.oldName, Nname = name, des = des, varType = varType, slaveID = slaveID, address = address, min = min, max = max, order = order)
|
|
|
|
|
if sender.oldName and ModBusVar.getByName(sender.oldName):
|
|
|
|
|
if sender.oldName == name or [varMes[3] for varMes in model.datas].count(name) < 2:
|
|
|
|
|
ModbusVarManage.editVar(name = sender.oldName, Nname = name, des = des, varType = varType, slaveID = slaveID, address = address, min = min, max = max, order = order)
|
|
|
|
|
else:
|
|
|
|
|
QMessageBox.information(self.parent(), '提示', '已有同名变量')
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
ModbusVarManage.createVar(varName = name, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = order)
|
|
|
|
|
res = ModbusVarManage.createVar(varName = name, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = order)
|
|
|
|
|
if res:
|
|
|
|
|
QMessageBox.information(self.parent(), '提示', '已有同名变量')
|
|
|
|
|
return
|
|
|
|
|
sender.setIcon(qtawesome.icon('fa.pencil', color='#4c8cf2'))
|
|
|
|
|
rowIndex = sender.index[0]
|
|
|
|
|
varMes = ModbusVarManage.getByName(name)
|
|
|
|
@ -401,6 +424,10 @@ class VarButtonDelegate(QItemDelegate):
|
|
|
|
|
varMes.insert(2, '')
|
|
|
|
|
model.insert_data(varMes, rowIndex)
|
|
|
|
|
model.remove_row(rowIndex + 1)
|
|
|
|
|
|
|
|
|
|
sender.isEdit = True
|
|
|
|
|
checkbox.setEnabled(False)
|
|
|
|
|
model.editableList.remove(sender.index[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_action(self):
|
|
|
|
@ -418,18 +445,15 @@ class VarButtonDelegate(QItemDelegate):
|
|
|
|
|
trend = ActualTrend(varName = name)
|
|
|
|
|
trend.show()
|
|
|
|
|
|
|
|
|
|
class ModbusTypeBox(VarButtonDelegate):
|
|
|
|
|
class ModbusTypeBox(QItemDelegate):
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
super(ModbusTypeBox, self).__init__(parent)
|
|
|
|
|
|
|
|
|
|
def paint(self, painter, option, index):
|
|
|
|
|
if not self.parent().indexWidget(index):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if index.column() == 5:
|
|
|
|
|
data = self.parent().model.datas[index.row()]
|
|
|
|
|
comBox = str('cb' + str(index.row()) + str(index.column()))
|
|
|
|
|
setattr(self, comBox, QComboBox(self.parent()))
|
|
|
|
|
setattr(self, comBox, QComboBox())
|
|
|
|
|
comboBox = getattr(self, comBox)
|
|
|
|
|
|
|
|
|
|
item = ['Coil Status', 'Input Status', 'Input Register', 'Holding Register']
|
|
|
|
@ -451,6 +475,7 @@ class ModbusTypeBox(VarButtonDelegate):
|
|
|
|
|
comboBox.setObjectName('ModbusTypeBox')
|
|
|
|
|
comboBox.setEditable(True)
|
|
|
|
|
comboBox.lineEdit().setAlignment(Qt.AlignCenter)
|
|
|
|
|
comboBox.setMinimumWidth(200)
|
|
|
|
|
# comboBox.setEnabled(False)
|
|
|
|
|
h_box_layout = QHBoxLayout()
|
|
|
|
|
h_box_layout.addWidget(comboBox)
|
|
|
|
@ -474,6 +499,7 @@ class ModbusTypeBox(VarButtonDelegate):
|
|
|
|
|
index,
|
|
|
|
|
widget
|
|
|
|
|
)
|
|
|
|
|
self.parent().openPersistentEditor(index)
|
|
|
|
|
|
|
|
|
|
def indexChange(self):
|
|
|
|
|
sender = self.sender()
|
|
|
|
|