1028更新实时趋势

main
zhangxuxutm 2 years ago
parent 2aff31b61e
commit 379b3cd4d9

@ -91,12 +91,17 @@ class ActualTrend(QtWidgets.QMainWindow):
self._dynamic_ax.plot(pos_list, value_list, 'bo-', linewidth=2) self._dynamic_ax.plot(pos_list, value_list, 'bo-', linewidth=2)
# self._dynamic_ax.set_xlim(0,10) # self._dynamic_ax.set_xlim(0,10)
self._dynamic_ax.set_ylim(minY, maxY) self._dynamic_ax.set_ylim(minY, maxY)
# print(id(self._dynamic_ax))
self._dynamic_ax.figure.canvas.draw() self._dynamic_ax.figure.canvas.draw()
def closeEvent(self, event): def closeEvent(self, event):
# 判断是否点击了窗口的关闭按钮 # 判断是否点击了窗口的关闭按钮
if event.type() == event.Close: if event.type() == event.Close:
self._timer.stop() self._timer.stop()
self.hide()
def showEvent(self, event):
self._timer.start()
if __name__ == "__main__": if __name__ == "__main__":
qapp = QtWidgets.QApplication(sys.argv) qapp = QtWidgets.QApplication(sys.argv)

@ -230,10 +230,17 @@ class ModBusTCPSlaveModel(VarTableModel):
class VarButtonDelegate(QItemDelegate): class VarButtonDelegate(QItemDelegate):
"""该类用于向单元格中添加按钮 任务表格""" """该类用于向单元格中添加按钮 任务表格"""
trendWidgetDict = {}
def __init__(self, parent=None): def __init__(self, parent=None):
super(VarButtonDelegate, self).__init__(parent) super(VarButtonDelegate, self).__init__(parent)
def trendWidget(self, varName):
if varName not in self.trendWidgetDict:
trendWidget = ActualTrend(varName = varName)
self.trendWidgetDict[varName] = trendWidget
return self.trendWidgetDict[varName]
def paint(self, painter, option, index): def paint(self, painter, option, index):
if not self.parent().indexWidget(index): if not self.parent().indexWidget(index):
button1 = QPushButton( button1 = QPushButton(
@ -442,7 +449,7 @@ class VarButtonDelegate(QItemDelegate):
if model.table.parent._isPopenOpen: if model.table.parent._isPopenOpen:
sender = self.sender() sender = self.sender()
name = str(model.datas[sender.index[0]][3]) name = str(model.datas[sender.index[0]][3])
trend = ActualTrend(varName = name) trend = self.trendWidget(varName = name)
trend.show() trend.show()
class ModbusTypeBox(QItemDelegate): class ModbusTypeBox(QItemDelegate):

@ -346,14 +346,14 @@ class ProjectManage(object):
zipf.extractall('project') zipf.extractall('project')
project = Project() projectList = []
projectList = []
for n in zipProjects: for n in zipProjects:
jsonPath = os.path.join('project', n, 'config', 'config.json') jsonPath = os.path.join('project', n, 'config', 'config.json')
with open(jsonPath, 'r') as f: with open(jsonPath, 'r') as f:
data = json.load(f) data = json.load(f)
proType = data['ProjectType'] proType = data['ProjectType']
des = data['description'] des = data['description']
project = Project()
project.createProject(n, proType, des) project.createProject(n, proType, des)
projectList.append(n) projectList.append(n)

@ -44,9 +44,8 @@ class ModbusVarManage(object):
maxIndex = index maxIndex = index
# print(IDIndex, slaveIndex, nameIndex, desIndex, typeIndex, addrIndex, minIndex, maxIndex) # print(IDIndex, slaveIndex, nameIndex, desIndex, typeIndex, addrIndex, minIndex, maxIndex)
if IDIndex == None or slaveIndex == None or nameIndex == None or desIndex == None or typeIndex == None or addrIndex == None or minIndex == None or maxIndex == None: if IDIndex == None or slaveIndex == None or nameIndex == None or desIndex == None or typeIndex == None or addrIndex == None or minIndex == None or maxIndex == None:
# print('表头错误') print('表头错误')
return '表头错误' return '表头错误'
for index, row in enumerate(list(ws.iter_rows())[1:]): for index, row in enumerate(list(ws.iter_rows())[1:]):
try: try:
l = [str(x.value) for x in row] l = [str(x.value) for x in row]
@ -57,14 +56,14 @@ class ModbusVarManage(object):
slaveID = l[slaveIndex] slaveID = l[slaveIndex]
min = l[minIndex] min = l[minIndex]
max = l[maxIndex] max = l[maxIndex]
ModBusVarModel = ModBusVar() if ModBusVar.getByName(varName):
if ModBusVarModel.getByName(varName): ModBusVar.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVar.varName == varName).execute()
ModBusVarModel.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVarModel.varName == varName)
else: else:
ModBusVarModel = ModBusVar()
ModBusVarModel.createVar(varName = varName, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int') ModBusVarModel.createVar(varName = varName, varType = varType, des = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int')
except Exception as e: except Exception as e:
print(e) print(e)
return '{}行导入出错'.format(index + 1) print('{}行导入出错'.format(index + 1))
@classmethod @classmethod
def exportModbusVar(self, excelPath): def exportModbusVar(self, excelPath):

@ -13,4 +13,7 @@ redis
msgpack-python msgpack-python
pythonnet pythonnet
influxdb_client influxdb_client
PyQtWebEngine PyQtWebEngine
pythonnet
pyecharts
pyDes
Loading…
Cancel
Save