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.
714 lines
31 KiB
Python
714 lines
31 KiB
Python
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
from PyQt5.QtCore import QSize, Qt, QTimer
|
|
from PyQt5.QtGui import QPixmap, QIcon
|
|
from PyQt5.QtWidgets import QSplitter, QPushButton, QFileDialog, QMessageBox
|
|
|
|
from UI.VarManages.VarTable import VarTableView, HartTableView, TcRtdTableView, AnalogTableView, FFSimulateTableView, \
|
|
HartSimulateTableView
|
|
from UI.VarManages.ModbusModel import VarTableModel
|
|
from UI.VarManages.MessageWidget import MessageWidget
|
|
|
|
from model.ProjectModel.ProjectManage import ProjectManage
|
|
from model.ProjectModel.VarManage import ModbusVarManage
|
|
from utils import Globals
|
|
|
|
from protocol.Celery.MBTCPMaster import app as MBTCPMApp
|
|
from protocol.Celery.MBRTUMaster import app as MBRTUMApp
|
|
from protocol.Celery.MBRTUSlave import app as MBRTUSApp
|
|
from protocol.Celery.MBTCPSlave import app as MBTCPSApp
|
|
from protocol.TCP.TemToMv import temToMv
|
|
from protocol.TCP.Analog import getRealAO
|
|
import re
|
|
from Static import static
|
|
class VarWidgets(QtWidgets.QWidget):
|
|
_isPopenOpen = False
|
|
def __init__(self, parent=None):
|
|
super(VarWidgets, self).__init__(parent)
|
|
self.setupUI()
|
|
|
|
def setupUI(self):
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
|
|
self.createBtn.setObjectName('createBtn')
|
|
self.createBtn.setIconSize(QSize(22, 22))
|
|
self.createBtn.clicked.connect(self.createVar)
|
|
|
|
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
|
|
self.forceBtn.setObjectName('forceBtn')
|
|
self.forceBtn.setIconSize(QSize(22, 22))
|
|
self.forceBtn.clicked.connect(self.forceVar)
|
|
|
|
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
|
|
self.clearBtn.setObjectName('clearBtn')
|
|
self.clearBtn.setIconSize(QSize(22, 22))
|
|
self.clearBtn.clicked.connect(self.clearColour)
|
|
|
|
self.importBtn = QPushButton(QIcon(':/static/import.png'), '导入变量')
|
|
self.importBtn.setObjectName('importBtn')
|
|
self.importBtn.setIconSize(QSize(22, 22))
|
|
self.importBtn.clicked.connect(self.importVar)
|
|
|
|
self.exportBtn = QPushButton(QIcon(':/static/export.png'), '导出变量')
|
|
self.exportBtn.setObjectName('exportBtn')
|
|
self.exportBtn.setIconSize(QSize(22, 22))
|
|
self.exportBtn.clicked.connect(self.exportVar)
|
|
|
|
self.messageBtn = QPushButton(QIcon(':/static/message.png'), '查看报文')
|
|
self.messageBtn.setObjectName('messageBtn')
|
|
self.messageBtn.setIconSize(QSize(22, 22))
|
|
self.messageBtn.clicked.connect(self.showMessage)
|
|
|
|
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
|
|
self.startProtocolBtn.setObjectName('startProtocolBtn')
|
|
self.startProtocolBtn.setIconSize(QSize(22, 22))
|
|
self.startProtocolBtn.clicked.connect(self.startProtocol)
|
|
|
|
self.varView = VarTableView(self)
|
|
self.varView.setObjectName('varView')
|
|
self.proxy = QtCore.QSortFilterProxyModel(self)
|
|
self.proxy.setSourceModel(self.varView.model)
|
|
|
|
self.varView.setModel(self.proxy)
|
|
self.varView.proxy = self.proxy
|
|
|
|
self.timer = QTimer(self)
|
|
# 将定时器超时信号与槽函数showTime()连接
|
|
self.timer.timeout.connect(self.proxy.invalidate)
|
|
self.timer.start(50) # 启动timer
|
|
|
|
Globals.setValue('varTable', self.varView)
|
|
# self.varView.model.initTable()
|
|
# [self.varView.model.append_data([1,1,1,1,1,1,1,1,1,1]) for x in range(100)]
|
|
|
|
# self.model = VarTableModel(self.dic['header'], self.dic['data'])
|
|
# self.varView.setModel(self.model)
|
|
|
|
self.gridLayout = QtWidgets.QGridLayout(self)
|
|
self.gridLayout.addWidget(self.createBtn,0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.forceBtn, 0, 1, 1, 1)
|
|
self.gridLayout.addWidget(self.messageBtn, 0, 2, 1, 1)
|
|
self.gridLayout.addWidget(self.startProtocolBtn, 0, 3, 1, 1)
|
|
self.gridLayout.addWidget(QSplitter(), 0, 4, 1, 20)
|
|
self.gridLayout.addWidget(self.clearBtn, 0, 4, 1, 1)
|
|
|
|
self.gridLayout.addWidget(self.importBtn, 0, 24, 1, 1)
|
|
self.gridLayout.addWidget(self.exportBtn, 0, 25, 1, 1)
|
|
self.gridLayout.addWidget(self.varView, 1, 0, 10, 26)
|
|
self.gridLayout.setSpacing(20)
|
|
self.gridLayout.setContentsMargins(20, 30, 20, 20)
|
|
|
|
|
|
# self.comboBox.currentIndexChanged.connect(self.on_comboBox_currentIndexChanged)
|
|
|
|
self.horizontalHeader = self.varView.horizontalHeader()
|
|
self.horizontalHeader.sectionClicked.connect(self.on_view_horizontalHeader_sectionClicked)
|
|
|
|
def clearColour(self):
|
|
Globals.clearValue('forceVars')
|
|
|
|
@QtCore.pyqtSlot(int)
|
|
def on_view_horizontalHeader_sectionClicked(self, logicalIndex):
|
|
self.logicalIndex = logicalIndex
|
|
self.on_comboBox_currentIndexChanged(self.logicalIndex)
|
|
menuName = '_' + str(logicalIndex) + 'Menu'
|
|
if not hasattr(self, menuName):
|
|
setattr(self, menuName, QtWidgets.QMenu(self))
|
|
self.menuValues = getattr(self, menuName)
|
|
menuEdit = QtWidgets.QLineEdit()
|
|
inputAction = QtWidgets.QWidgetAction(self.menuValues)
|
|
inputAction.setDefaultWidget(menuEdit)
|
|
self.menuValues.addAction(inputAction)
|
|
menuEdit.textChanged.connect(self.on_lineEdit_textChanged)
|
|
|
|
self.menuValues = getattr(self, menuName)
|
|
self.romoveAction(self.menuValues)
|
|
|
|
self.signalMapper = QtCore.QSignalMapper(self)
|
|
self.menuValues.mouseReleaseEvent = self._menu_mouseReleaseEvent
|
|
|
|
actionAll = QtWidgets.QAction("All", self)
|
|
actionAll.triggered.connect(self.on_actionAll_triggered)
|
|
actionAll.setProperty('canHide', True)
|
|
actionAll.setCheckable(True)
|
|
self.menuValues.addAction(actionAll)
|
|
self.menuValues.addSeparator()
|
|
|
|
valuesUnique = [self.proxy.data(self.proxy.index(row, self.logicalIndex))
|
|
for row in range(self.proxy.rowCount())
|
|
]
|
|
for actionNumber, actionName in enumerate((list(set(valuesUnique)))):
|
|
action = QtWidgets.QAction(str(actionName), self)
|
|
self.signalMapper.setMapping(action, actionNumber)
|
|
action.triggered.connect(self.signalMapper.map)
|
|
action.setCheckable(True)
|
|
self.menuValues.addAction(action)
|
|
|
|
self.signalMapper.mapped.connect(self.on_signalMapper_mapped)
|
|
|
|
headerPos =self.varView.mapToGlobal(self.horizontalHeader.pos())
|
|
|
|
posY = headerPos.y() + self.horizontalHeader.height()
|
|
posX = headerPos.x() + self.horizontalHeader.sectionPosition(self.logicalIndex)
|
|
getattr(self, menuName).exec_(QtCore.QPoint(posX, posY))
|
|
|
|
@QtCore.pyqtSlot()
|
|
def on_actionAll_triggered(self):
|
|
# 显示全部
|
|
filterColumn = self.logicalIndex
|
|
filterString = QtCore.QRegExp( "",
|
|
QtCore.Qt.CaseInsensitive,
|
|
QtCore.QRegExp.RegExp
|
|
)
|
|
|
|
self.proxy.setFilterRegExp(filterString)
|
|
self.proxy.setFilterKeyColumn(filterColumn)
|
|
|
|
@QtCore.pyqtSlot(int)
|
|
def on_signalMapper_mapped(self, i):
|
|
# stringAction = self.signalMapper.mapping(i).text()
|
|
stringActions = '|'.join([x.text() for x in getattr(self, '_' + str(self.logicalIndex) + 'Menu').actions() if x.isChecked()])
|
|
filterColumn = self.logicalIndex
|
|
filterString = QtCore.QRegExp( stringActions,
|
|
QtCore.Qt.CaseSensitive,
|
|
# QtCore.QRegExp.FixedString
|
|
)
|
|
self.proxy.setFilterRegExp(filterString)
|
|
self.proxy.setFilterKeyColumn(filterColumn)
|
|
|
|
@QtCore.pyqtSlot(str)
|
|
def on_lineEdit_textChanged(self, text):
|
|
# 搜索框文字变化函数
|
|
search = QtCore.QRegExp( text,
|
|
QtCore.Qt.CaseInsensitive,
|
|
QtCore.QRegExp.RegExp
|
|
)
|
|
|
|
self.proxy.setFilterRegExp(search)
|
|
|
|
@QtCore.pyqtSlot(int)
|
|
def on_comboBox_currentIndexChanged(self, index):
|
|
self.proxy.setFilterKeyColumn(index)
|
|
|
|
def _menu_mouseReleaseEvent(self, event):
|
|
action = self.menuValues.actionAt(event.pos())
|
|
if not action:
|
|
# 没有找到action就交给QMenu自己处理
|
|
return QtWidgets.QMenu.mouseReleaseEvent(self.menuValues, event)
|
|
if action.property('canHide'): # 如果有该属性则给菜单自己处理
|
|
return QtWidgets.QMenu.mouseReleaseEvent(self.menuValues, event)
|
|
# 找到了QAction则只触发Action
|
|
action.activate(action.Trigger)
|
|
|
|
def romoveAction(self, menu):
|
|
# 删除输入框之外的按钮1
|
|
for action in menu.actions():
|
|
if type(action) != QtWidgets.QWidgetAction:
|
|
menu.removeAction(action)
|
|
|
|
def _checkAction(self):
|
|
# 三个action都响应该函数
|
|
self.labelInfo.setText('\n'.join(['{}\t选中:{}'.format(
|
|
action.text(), action.isChecked()) for action in self.menuValues.actions()]))
|
|
|
|
def createVar(self):
|
|
self.varView.model.append_data(['', '', '', '', '', '', '', '', '', '', 'int'])
|
|
|
|
def forceVar(self):
|
|
check = [i for i,x in enumerate(self.varView.model.checkList) if x == 'Checked']
|
|
# check.sort(reverse=True)
|
|
for i in check:
|
|
varMes = self.varView.model.datas[i]
|
|
value, name, des, varType, slaveID, address, min, max, order = str(varMes[1]), str(varMes[3]), str(varMes[4]), str(varMes[5]), str(varMes[6]), str(varMes[7]), str(varMes[8]), str(varMes[9]), str(varMes[10])
|
|
model = self.varView.model
|
|
pattern = re.compile(r'[^0-9\.-]+')
|
|
if not value or re.findall(pattern, str(value)):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"请输入强制值或数字",
|
|
QMessageBox.Yes)
|
|
return
|
|
if min and max:
|
|
if float(value) < float(min) or float(value) > float(max):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
elif min and not max:
|
|
if float(value) < float(min):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
elif max and not min:
|
|
if float(value) > float(max):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
proType = Globals.getValue('currentProType')
|
|
forceVars = Globals.getValue('forceVars')
|
|
forceVars.add(name)
|
|
Globals.setValue('forceVars', forceVars)
|
|
if proType == '0':
|
|
MBTCPMApp.send_task('protocol.Celery.MBTCPMaster.MBTCPMTask.setValue',args=[name, varType, slaveID, address, value, order])
|
|
if proType == '1':
|
|
MBTCPSApp.send_task('protocol.Celery.MBTCPSlave.MBTCPSTask.setValue',args=[name, varType, slaveID, address, value])
|
|
elif proType == '2':
|
|
MBRTUMApp.send_task('protocol.Celery.MBRTUMaster.MBRTUMTask.setValue',args=[name, varType, slaveID, address, value, order])
|
|
elif proType == '3':
|
|
MBRTUSApp.send_task('protocol.Celery.MBRTUSlave.MBRTUSTask.setValue',args=[name, varType, slaveID, address, value])
|
|
|
|
|
|
def importVar(self):
|
|
if Globals.getValue('currentPro'):
|
|
path = QFileDialog.getOpenFileName(self, "Choose File", "./","VarExcel (*.xlsx);;All Files (*)")[0]
|
|
if not path:
|
|
return
|
|
result = ModbusVarManage.importModbusVar(path)
|
|
QMessageBox.question(self.parent(), '提示', result, QMessageBox.Yes)
|
|
self.varView.model.initTable()
|
|
|
|
def exportVar(self):
|
|
path = QFileDialog.getSaveFileName(self, "Choose File", "./","VarExcel (*.xlsx);;All Files (*)")[0]
|
|
if not path:
|
|
return
|
|
ModbusVarManage.exportModbusVar(path)
|
|
|
|
def showMessage(self):
|
|
self.messageWidget = MessageWidget()
|
|
self.messageWidget.show()
|
|
|
|
def startProtocol(self):
|
|
if not self._isPopenOpen:
|
|
ProjectManage.startProtocol()
|
|
self._isPopenOpen = True
|
|
self.startProtocolBtn.setText('停止通讯')
|
|
self.startProtocolBtn.setIcon(QIcon(':/static/pause.png'))
|
|
else:
|
|
ProjectManage.closePopen()
|
|
self._isPopenOpen = False
|
|
self.startProtocolBtn.setText('开始通讯')
|
|
self.startProtocolBtn.setIcon(QIcon(':/static/startProtocol.png'))
|
|
|
|
def initIcon(self):
|
|
self._isPopenOpen = False
|
|
self.startProtocolBtn.setText('开始通讯')
|
|
self.startProtocolBtn.setIcon(QIcon(':/static/startProtocol.png'))
|
|
|
|
|
|
class HartWidgets(VarWidgets):
|
|
def __init__(self, parent=None):
|
|
super(HartWidgets, self).__init__(parent)
|
|
|
|
def setupUI(self):
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
|
|
self.startProtocolBtn.setObjectName('startProtocolBtn')
|
|
self.startProtocolBtn.setIconSize(QSize(22, 22))
|
|
self.startProtocolBtn.clicked.connect(self.startProtocol)
|
|
|
|
self.varView = HartTableView()
|
|
self.varView.setObjectName('HartTable')
|
|
self.proxy = QtCore.QSortFilterProxyModel(self)
|
|
self.proxy.setSourceModel(self.varView.model)
|
|
|
|
self.varView.setModel(self.proxy)
|
|
self.varView.proxy = self.proxy
|
|
|
|
self.timer = QTimer(self)
|
|
# 将定时器超时信号与槽函数showTime()连接
|
|
self.timer.timeout.connect(self.proxy.invalidate)
|
|
self.timer.start(50) # 启动timer
|
|
|
|
Globals.setValue('HartTable', self.varView)
|
|
|
|
|
|
self.gridLayout = QtWidgets.QGridLayout(self)
|
|
# self.gridLayout.addWidget(self.createBtn, 0, 0, 1, 1)
|
|
# self.gridLayout.addWidget(self.forceBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.startProtocolBtn, 0, 0, 1, 1)
|
|
# self.gridLayout.addWidget(self.clearBtn, 0, 2, 1, 1)
|
|
|
|
self.gridLayout.addWidget(self.varView, 1, 0, 10, 26)
|
|
self.gridLayout.setSpacing(20)
|
|
self.gridLayout.setContentsMargins(20, 30, 20, 20)
|
|
|
|
|
|
# self.comboBox.currentIndexChanged.connect(self.on_comboBox_currentIndexChanged)
|
|
|
|
self.horizontalHeader = self.varView.horizontalHeader()
|
|
self.horizontalHeader.sectionClicked.connect(self.on_view_horizontalHeader_sectionClicked)
|
|
|
|
|
|
class TcRtdWidgets(VarWidgets):
|
|
def __init__(self, parent=None):
|
|
super(TcRtdWidgets, self).__init__(parent)
|
|
|
|
def setupUI(self):
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
# self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
|
|
# self.createBtn.setObjectName('createBtn')
|
|
# self.createBtn.setIconSize(QSize(22, 22))
|
|
# self.createBtn.clicked.connect(self.createVar)
|
|
|
|
|
|
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
|
|
self.forceBtn.setObjectName('forceBtn')
|
|
self.forceBtn.setIconSize(QSize(22, 22))
|
|
self.forceBtn.clicked.connect(self.forceVar)
|
|
|
|
|
|
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
|
|
self.startProtocolBtn.setObjectName('startProtocolBtn')
|
|
self.startProtocolBtn.setIconSize(QSize(22, 22))
|
|
self.startProtocolBtn.clicked.connect(self.startProtocol)
|
|
|
|
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
|
|
self.clearBtn.setObjectName('clearBtn')
|
|
self.clearBtn.setIconSize(QSize(22, 22))
|
|
self.clearBtn.clicked.connect(self.clearColour)
|
|
|
|
self.varView = TcRtdTableView()
|
|
self.varView.setObjectName('TcRtdTable')
|
|
self.proxy = QtCore.QSortFilterProxyModel(self)
|
|
self.proxy.setSourceModel(self.varView.model)
|
|
|
|
self.varView.setModel(self.proxy)
|
|
self.varView.proxy = self.proxy
|
|
|
|
self.timer = QTimer(self)
|
|
# 将定时器超时信号与槽函数showTime()连接
|
|
self.timer.timeout.connect(self.proxy.invalidate)
|
|
self.timer.start(50) # 启动timer
|
|
|
|
Globals.setValue('TcRtdTable', self.varView)
|
|
|
|
self.gridLayout = QtWidgets.QGridLayout(self)
|
|
# self.gridLayout.addWidget(self.createBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.forceBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.startProtocolBtn, 0, 1, 1, 1)
|
|
self.gridLayout.addWidget(self.clearBtn, 0, 2, 1, 1)
|
|
|
|
self.gridLayout.addWidget(self.varView, 1, 0, 10, 26)
|
|
self.gridLayout.setSpacing(20)
|
|
self.gridLayout.setContentsMargins(20, 30, 20, 20)
|
|
|
|
|
|
|
|
|
|
self.horizontalHeader = self.varView.horizontalHeader()
|
|
self.horizontalHeader.sectionClicked.connect(self.on_view_horizontalHeader_sectionClicked)
|
|
|
|
def createVar(self):
|
|
self.varView.model.append_data(['', '', '', '', '', '', '', '', ''])
|
|
|
|
def forceVar(self):
|
|
# print(self.varView.model.datas)
|
|
check = [i for i,x in enumerate(self.varView.model.checkList) if x == 'Checked']
|
|
for i in check:
|
|
value = self.varView.model.datas[i][1]
|
|
varType = self.varView.model.datas[i][5]
|
|
min = self.varView.model.datas[i][6]
|
|
max = self.varView.model.datas[i][7]
|
|
pattern = re.compile(r'[^0-9\.-]+')
|
|
if not value or re.findall(pattern, str(value)):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"请输入强制值或数字",
|
|
QMessageBox.Yes)
|
|
return
|
|
if min and max:
|
|
if float(value) < float(min) or float(value) > float(max):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
elif min and not max:
|
|
if float(value) < float(min):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
elif max and not min:
|
|
if float(value) > float(max):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
mv = temToMv(varType, float(value))
|
|
if not mv and mv != 0:
|
|
continue
|
|
self.varView.mvList[i] = mv
|
|
self.varView.valueList[i] = float(value)
|
|
forceVars = Globals.getValue('forceVars')
|
|
# forceVars.add(model.datas[sender.index[0]][3])
|
|
forceVars.add(self.varView.model.datas[i][3])
|
|
Globals.setValue('forceVars', forceVars)
|
|
# self.varView.valueList = [float(x[1]) for x in self.varView.model.datas]
|
|
|
|
|
|
|
|
class AnalogWidgets(VarWidgets):
|
|
def __init__(self, parent=None):
|
|
super(AnalogWidgets, self).__init__(parent)
|
|
|
|
def setupUI(self):
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
# self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
|
|
# self.createBtn.setObjectName('createBtn')
|
|
# self.createBtn.setIconSize(QSize(22, 22))
|
|
# self.createBtn.clicked.connect(self.createVar)
|
|
|
|
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
|
|
self.forceBtn.setObjectName('forceBtn')
|
|
self.forceBtn.setIconSize(QSize(22, 22))
|
|
self.forceBtn.clicked.connect(self.forceVar)
|
|
|
|
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
|
|
self.startProtocolBtn.setObjectName('startProtocolBtn')
|
|
self.startProtocolBtn.setIconSize(QSize(22, 22))
|
|
self.startProtocolBtn.clicked.connect(self.startProtocol)
|
|
|
|
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
|
|
self.clearBtn.setObjectName('clearBtn')
|
|
self.clearBtn.setIconSize(QSize(22, 22))
|
|
self.clearBtn.clicked.connect(self.clearColour)
|
|
|
|
self.varView = AnalogTableView()
|
|
self.varView.setObjectName('AnalogTable')
|
|
self.proxy = QtCore.QSortFilterProxyModel(self)
|
|
self.proxy.setSourceModel(self.varView.model)
|
|
|
|
self.varView.setModel(self.proxy)
|
|
self.varView.proxy = self.proxy
|
|
|
|
self.timer = QTimer(self)
|
|
# 将定时器超时信号与槽函数showTime()连接
|
|
self.timer.timeout.connect(self.proxy.invalidate)
|
|
self.timer.start(50) # 启动timer
|
|
|
|
Globals.setValue('AnalogTable', self.varView)
|
|
|
|
self.gridLayout = QtWidgets.QGridLayout(self)
|
|
# self.gridLayout.addWidget(self.createBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.forceBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.startProtocolBtn, 0, 1, 1, 1)
|
|
self.gridLayout.addWidget(self.clearBtn, 0, 2, 1, 1)
|
|
|
|
self.gridLayout.addWidget(self.varView, 1, 0, 10, 26)
|
|
self.gridLayout.setSpacing(20)
|
|
self.gridLayout.setContentsMargins(20, 30, 20, 20)
|
|
|
|
self.horizontalHeader = self.varView.horizontalHeader()
|
|
self.horizontalHeader.sectionClicked.connect(self.on_view_horizontalHeader_sectionClicked)
|
|
|
|
def createVar(self):
|
|
self.varView.model.append_data(['', '', '', '', '', '', '', '', ''])
|
|
|
|
def forceVar(self):
|
|
check = [i for i,x in enumerate(self.varView.model.checkList) if x == 'Checked']
|
|
forceVars = Globals.getValue('forceVars')
|
|
for i in check:
|
|
value = self.varView.model.datas[i][1]
|
|
min = self.varView.model.datas[i][6]
|
|
max = self.varView.model.datas[i][7]
|
|
pattern = re.compile(r'[^0-9\.-]+')
|
|
if not value or re.findall(pattern, str(value)):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"请输入强制值或数字",
|
|
QMessageBox.Yes)
|
|
return
|
|
if i > 16:
|
|
if not value.isdigit:
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"请输入0或1",
|
|
QMessageBox.Yes)
|
|
return
|
|
if min and max and i < 16:
|
|
if float(value) < float(min) or float(value) > float(max):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
else:
|
|
min = None
|
|
max = None
|
|
|
|
if (float(value) > 20 or float(value)) < 4 and i < 8:
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
if (float(value) > 10000 or float(value) < 0.1) and 7 < i < 16:
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"超出量程范围",
|
|
QMessageBox.Yes)
|
|
return
|
|
if i < 8:
|
|
self.varView.model.table.realList[i] = getRealAO(float(value), float(max), float(min))
|
|
self.varView.model.table.valueList[i] = float(value)
|
|
else:
|
|
self.varView.model.table.realList[i] = float(value)
|
|
self.varView.model.table.valueList[i] = float(value)
|
|
self.varView.valueList[i] = float(value)
|
|
forceVars.add(self.varView.model.datas[i][3])
|
|
Globals.setValue('forceVars', forceVars)
|
|
|
|
|
|
|
|
class FFSimulateWidgets(VarWidgets):
|
|
def __init__(self, parent=None):
|
|
super(FFSimulateWidgets, self).__init__(parent)
|
|
|
|
def setupUI(self):
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
# self.createBtn = QPushButton(QIcon(':/static/add.png'), '新建变量')
|
|
# self.createBtn.setObjectName('createBtn')
|
|
# self.createBtn.setIconSize(QSize(22, 22))
|
|
# self.createBtn.clicked.connect(self.createVar)
|
|
|
|
self.forceBtn = QPushButton(QIcon(':/static/start.png'), '批量强制')
|
|
self.forceBtn.setObjectName('forceBtn')
|
|
self.forceBtn.setIconSize(QSize(22, 22))
|
|
self.forceBtn.clicked.connect(self.forceVar)
|
|
|
|
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
|
|
self.startProtocolBtn.setObjectName('startProtocolBtn')
|
|
self.startProtocolBtn.setIconSize(QSize(22, 22))
|
|
self.startProtocolBtn.clicked.connect(self.startProtocol)
|
|
|
|
self.clearBtn = QPushButton(QIcon(':/static/clear.png'), '清除颜色')
|
|
self.clearBtn.setObjectName('clearBtn')
|
|
self.clearBtn.setIconSize(QSize(22, 22))
|
|
self.clearBtn.clicked.connect(self.clearColour)
|
|
|
|
self.varView = FFSimulateTableView()
|
|
self.varView.setObjectName('FFSimulateTable')
|
|
self.proxy = QtCore.QSortFilterProxyModel(self)
|
|
self.proxy.setSourceModel(self.varView.model)
|
|
|
|
self.varView.setModel(self.proxy)
|
|
self.varView.proxy = self.proxy
|
|
|
|
self.timer = QTimer(self)
|
|
# 将定时器超时信号与槽函数showTime()连接
|
|
self.timer.timeout.connect(self.proxy.invalidate)
|
|
self.timer.start(50) # 启动timer
|
|
|
|
Globals.setValue('FFSimulateTable', self.varView)
|
|
|
|
self.gridLayout = QtWidgets.QGridLayout(self)
|
|
# self.gridLayout.addWidget(self.createBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.forceBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.startProtocolBtn, 0, 1, 1, 1)
|
|
self.gridLayout.addWidget(self.clearBtn, 0, 2, 1, 1)
|
|
|
|
self.gridLayout.addWidget(self.varView, 1, 0, 10, 26)
|
|
self.gridLayout.setSpacing(20)
|
|
self.gridLayout.setContentsMargins(20, 30, 20, 20)
|
|
|
|
self.horizontalHeader = self.varView.horizontalHeader()
|
|
self.horizontalHeader.sectionClicked.connect(self.on_view_horizontalHeader_sectionClicked)
|
|
|
|
def createVar(self):
|
|
self.varView.model.append_data(['', '', '', '', '', '', '', '', ''])
|
|
|
|
def forceVar(self):
|
|
check = [i for i,x in enumerate(self.varView.model.checkList) if x == 'Checked']
|
|
forceVars = Globals.getValue('forceVars')
|
|
for i in check:
|
|
value = self.varView.model.datas[i][1]
|
|
if i > 7:
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"该变量无法强制",
|
|
QMessageBox.Yes)
|
|
return
|
|
pattern = re.compile(r'[^0-9\.-]+')
|
|
if not value or re.findall(pattern, str(value)):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"请输入强制值或数字",
|
|
QMessageBox.Yes)
|
|
return
|
|
if i > 3:
|
|
if not re.match('^[01]+$', str(value)):
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"请输入0或1",
|
|
QMessageBox.Yes)
|
|
return
|
|
try:
|
|
self.varView.workThread.FFSimulate.writeValue(i, value)
|
|
except:
|
|
reply = QMessageBox.question(self.parent(),
|
|
'警告',
|
|
"请先打开通讯",
|
|
QMessageBox.Yes)
|
|
return
|
|
self.varView.valueList[i] = float(value)
|
|
forceVars.add(self.varView.model.datas[i][3])
|
|
Globals.setValue('forceVars', forceVars)
|
|
|
|
|
|
class HartSimulateWidgets(VarWidgets):
|
|
def __init__(self, parent=None):
|
|
super(HartSimulateWidgets, self).__init__(parent)
|
|
|
|
def setupUI(self):
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
self.startProtocolBtn = QPushButton(QIcon(':/static/startProtocol.png'), '开始通讯')
|
|
self.startProtocolBtn.setObjectName('startProtocolBtn')
|
|
self.startProtocolBtn.setIconSize(QSize(22, 22))
|
|
self.startProtocolBtn.clicked.connect(self.startProtocol)
|
|
|
|
self.varView = HartSimulateTableView()
|
|
self.varView.setObjectName('HartSimulateTable')
|
|
self.proxy = QtCore.QSortFilterProxyModel(self)
|
|
self.proxy.setSourceModel(self.varView.model)
|
|
|
|
self.varView.setModel(self.proxy)
|
|
self.varView.proxy = self.proxy
|
|
|
|
self.timer = QTimer(self)
|
|
# 将定时器超时信号与槽函数showTime()连接
|
|
self.timer.timeout.connect(self.proxy.invalidate)
|
|
self.timer.start(50) # 启动timer
|
|
|
|
Globals.setValue('HartSimulateTable', self.varView)
|
|
|
|
|
|
self.gridLayout = QtWidgets.QGridLayout(self)
|
|
# self.gridLayout.addWidget(self.createBtn, 0, 0, 1, 1)
|
|
# self.gridLayout.addWidget(self.forceBtn, 0, 0, 1, 1)
|
|
self.gridLayout.addWidget(self.startProtocolBtn, 0, 0, 1, 1)
|
|
# self.gridLayout.addWidget(self.clearBtn, 0, 2, 1, 1)
|
|
|
|
self.gridLayout.addWidget(self.varView, 1, 0, 10, 26)
|
|
self.gridLayout.setSpacing(20)
|
|
self.gridLayout.setContentsMargins(20, 30, 20, 20)
|
|
|
|
|
|
# self.comboBox.currentIndexChanged.connect(self.on_comboBox_currentIndexChanged)
|
|
|
|
self.horizontalHeader = self.varView.horizontalHeader()
|
|
self.horizontalHeader.sectionClicked.connect(self.on_view_horizontalHeader_sectionClicked)
|
|
|