1029更新

main
zhangxuxutm 2 years ago
parent 6075970a7c
commit 489224378b

@ -184,9 +184,13 @@ class MainWindow(QMainWindow):
# self.setAttribute(Qt.WA_TranslucentBackground) # 设置窗口背景透明 # self.setAttribute(Qt.WA_TranslucentBackground) # 设置窗口背景透明
self.setWindowFlag(Qt.FramelessWindowHint) self.setWindowFlag(Qt.FramelessWindowHint)
def exButtonClicked(self, index): def exButtonClicked(self, index):
if not Globals.getValue('currentPro') and index != 0:
return -1
self.rightWidget.setCurrentIndex(index) self.rightWidget.setCurrentIndex(index)
# print(index) if index in [4, 5]:
return
Globals.setValue('SearchWidget', index) Globals.setValue('SearchWidget', index)
@ -195,39 +199,38 @@ class MainWindow(QMainWindow):
if proType == -1: if proType == -1:
return return
elif proType in ['0', '1']: elif proType in ['0', '1']:
self.rightWidget.setCurrentIndex(4) if self.exButtonClicked(4) != -1:
self.TcpSettingWidget.setupUI() self.TcpSettingWidget.setupUI()
elif proType in ['2', '3']: elif proType in ['2', '3']:
self.rightWidget.setCurrentIndex(5) if self.exButtonClicked(5) != -1:
self.RtuSettingWidget.setupUI() self.RtuSettingWidget.setupUI()
def varShow(self): def varShow(self):
proType = Globals.getValue('currentProType') proType = Globals.getValue('currentProType')
# print(type(proType))
if proType == -1: if proType == -1:
return return
elif proType in ['0', '1', '2', '3']: elif proType in ['0', '1', '2', '3']:
self.rightWidget.setCurrentIndex(1) self.exButtonClicked(1)
Globals.setValue('SearchWidget', 1) Globals.setValue('SearchWidget', 1)
elif proType in ['4']: elif proType in ['4']:
self.rightWidget.setCurrentIndex(6) self.exButtonClicked(6)
Globals.setValue('SearchWidget', 6) Globals.setValue('SearchWidget', 6)
elif proType in ['5']: elif proType in ['5']:
self.rightWidget.setCurrentIndex(7) self.exButtonClicked(7)
Globals.setValue('SearchWidget', 7) Globals.setValue('SearchWidget', 7)
elif proType in ['6']: elif proType in ['6']:
self.rightWidget.setCurrentIndex(8) self.exButtonClicked(8)
Globals.setValue('SearchWidget', 8) Globals.setValue('SearchWidget', 8)
elif proType in ['7']: elif proType in ['7']:
self.rightWidget.setCurrentIndex(9) self.exButtonClicked(9)
self.ffWidget.initDevView() self.ffWidget.initDevView()
Globals.setValue('SearchWidget', 9) Globals.setValue('SearchWidget', 9)
elif proType in ['8']: elif proType in ['8']:
self.rightWidget.setCurrentIndex(10) self.exButtonClicked(10)
Globals.setValue('SearchWidget', 10) Globals.setValue('SearchWidget', 10)
elif proType in ['9']: elif proType in ['9']:
self.rightWidget.setCurrentIndex(11) self.exButtonClicked(11)
Globals.setValue('SearchWidget', 11) Globals.setValue('SearchWidget', 11)
#枚举参数 #枚举参数

@ -233,14 +233,14 @@ class ProjectButtonDelegate(QItemDelegate):
def exchange_action(self): def exchange_action(self):
# 切换工程按钮槽函数 # 切换工程按钮槽函数
sender = self.sender() sender = self.sender()
projectNumber = Globals.getValue('projectNumber') projectName = Globals.getValue('currentPro')
if projectNumber == sender.index[0]: if projectName == str(self.parent().model.datas[sender.index[0]][1]):
reply = QMessageBox.question(self.parent(), reply = QMessageBox.question(self.parent(),
'警告', '警告',
"工程已打开", "工程已打开",
QMessageBox.Yes) QMessageBox.Yes)
return return
print(sender.index[0]) # print(sender.index[0])
if sender.index[0] in self.parent().model.editableList: if sender.index[0] in self.parent().model.editableList:
reply = QMessageBox.question(self.parent(), reply = QMessageBox.question(self.parent(),
'警告', '警告',
@ -255,8 +255,6 @@ class ProjectButtonDelegate(QItemDelegate):
if proType in ['0', '1', '2', '3']: if proType in ['0', '1', '2', '3']:
Globals.getValue('varTable').model.initTable() Globals.getValue('varTable').model.initTable()
# if lastproType in ['0', '1', '2', '3']:
# Globals.getValue('varTable').model.refreshComboBox()
elif proType in ['4']: elif proType in ['4']:
Globals.getValue('HartTable').model.initTable() Globals.getValue('HartTable').model.initTable()
elif proType in ['5']: elif proType in ['5']:
@ -269,7 +267,6 @@ class ProjectButtonDelegate(QItemDelegate):
Globals.getValue('HartSimulateTable').model.initTable() Globals.getValue('HartSimulateTable').model.initTable()
Globals.getValue('userTable').model.initTable() Globals.getValue('userTable').model.initTable()
Globals.getValue('HistoryWidget').exchangeProject() Globals.getValue('HistoryWidget').exchangeProject()
Globals.setValue('projectNumber', sender.index[0])
self.parent().proxy.invalidate() self.parent().proxy.invalidate()
@ -297,7 +294,7 @@ class ProjectButtonDelegate(QItemDelegate):
return return
if sender.oldName: if sender.oldName:
if ProjectManage.editProject(name = sender.oldName, Nname = name, des = des): if ProjectManage.editProject(name = sender.oldName, Nname = name, des = des, proType = proType):
reply = QMessageBox.question(self.parent(), reply = QMessageBox.question(self.parent(),
'警告', '警告',
"工程名相同", "工程名相同",
@ -319,6 +316,7 @@ class ProjectButtonDelegate(QItemDelegate):
proMes.append('') proMes.append('')
model.insert_data(proMes, rowIndex) model.insert_data(proMes, rowIndex)
model.remove_row(rowIndex + 1) model.remove_row(rowIndex + 1)
self.parent().proxy.invalidate()
def delete_action(self): def delete_action(self):
@ -327,6 +325,8 @@ class ProjectButtonDelegate(QItemDelegate):
name = str(model.datas[sender.index[0]][1]) name = str(model.datas[sender.index[0]][1])
ProjectManage.deleteProject(name = name) ProjectManage.deleteProject(name = name)
model.remove_row(sender.index[0]) model.remove_row(sender.index[0])
if name == Globals.getValue('currentPro'):
Globals.setValue('currentPro', None)
class ProTypeBoxDelegate(ProjectButtonDelegate): class ProTypeBoxDelegate(ProjectButtonDelegate):
def __init__(self, parent=None): def __init__(self, parent=None):
@ -341,6 +341,7 @@ class ProTypeBoxDelegate(ProjectButtonDelegate):
cmBox = getattr(self, comboBox) cmBox = getattr(self, comboBox)
item = ['MODBUSTCP 主站模式', 'MODBUSTCP 从站模式', 'MODBUSRTU 主站模式', 'MODBUSRTU 从站模式','HART', 'TCRTD', 'AO/DO/PI', 'FF', 'FF模拟', 'HART模拟'] item = ['MODBUSTCP 主站模式', 'MODBUSTCP 从站模式', 'MODBUSRTU 主站模式', 'MODBUSRTU 从站模式','HART', 'TCRTD', 'AO/DO/PI', 'FF', 'FF模拟', 'HART模拟']
# item = ['MODBUSTCP 主站模式', 'MODBUSTCP 从站模式', 'MODBUSRTU 主站模式', 'MODBUSRTU 从站模式']
cmBox.addItems(item) cmBox.addItems(item)
cmBox.index = [index.row(), index.column()] cmBox.index = [index.row(), index.column()]
if self.parent().model.datas[index.row()][index.column()] in range(10): if self.parent().model.datas[index.row()][index.column()] in range(10):

@ -53,14 +53,7 @@ class ActualTrend(QtWidgets.QMainWindow):
# self.n += 1 # self.n += 1
varName = self.varName varName = self.varName
varMM = ModbusVarManage.getByName(varName) varMM = ModbusVarManage.getByName(varName)
minY = -100
maxY = 100
if varMM:
minY, maxY = varMM[-2], varMM[-1]
minY = float(minY)
maxY = float(maxY)
self._dynamic_ax.clear() self._dynamic_ax.clear()
acttime = time.strftime('%H:%M:%S', time.localtime(time.time())) acttime = time.strftime('%H:%M:%S', time.localtime(time.time()))
@ -81,6 +74,13 @@ class ActualTrend(QtWidgets.QMainWindow):
except Exception as e: except Exception as e:
print(e) print(e)
if not varMM[-2] and not varMM[-1]:
minY = min(self.yQueue.list) - 5
maxY = max(self.yQueue.list) + 5
else:
minY = float(varMM[-2]) - float(5)
maxY = float(varMM[-1]) + float(5)
name_list = self.xQueue.list name_list = self.xQueue.list
value_list = np.array(self.yQueue.list) value_list = np.array(self.yQueue.list)
pos_list = np.arange(len(name_list)) pos_list = np.arange(len(name_list))

@ -183,6 +183,8 @@ class TrendWidgets(QWidget):
# 获取所有的趋势表 # 获取所有的趋势表
mems = InfluxMem.get_all() mems = InfluxMem.get_all()
self.proName = Globals.getValue('currentPro') self.proName = Globals.getValue('currentPro')
if not self.proName:
return
self.timeBox.clear() self.timeBox.clear()
if mems is 'Error': if mems is 'Error':
return return

@ -268,7 +268,8 @@ class VarWidgets(QtWidgets.QWidget):
path = QFileDialog.getOpenFileName(self, "Choose File", "./","VarExcel (*.xlsx);;All Files (*)")[0] path = QFileDialog.getOpenFileName(self, "Choose File", "./","VarExcel (*.xlsx);;All Files (*)")[0]
if not path: if not path:
return return
ModbusVarManage.importModbusVar(path) result = ModbusVarManage.importModbusVar(path)
QMessageBox.question(self.parent(), '提示', result, QMessageBox.Yes)
self.varView.model.initTable() self.varView.model.initTable()
def exportVar(self): def exportVar(self):

@ -111,13 +111,16 @@ class ProjectManage(object):
# print(name) # print(name)
# print(Globals.getValue('currentPro')) # print(Globals.getValue('currentPro'))
Client.initDB() Client.initDB()
if name == Globals.getValue('currentPro'):
Globals.getValue('currentProDB').close()
if not Project.getByName(name): if not Project.getByName(name):
print('不存在的工程', Project.getByName(name)) print('不存在的工程', Project.getByName(name))
return return
try: try:
shutil.rmtree(os.path.join('project', name)) if name == Globals.getValue('currentPro'):
self.closePopen()
Globals.getValue('currentProDB').close()
Globals.setValue('currentPro', None)
QTimer.singleShot(1000, lambda:shutil.rmtree(os.path.join('project', name)))
except OSError as e: except OSError as e:
print(e) print(e)
Project.deleteProject(name = name) Project.deleteProject(name = name)
@ -150,6 +153,8 @@ class ProjectManage(object):
if proType == '7': if proType == '7':
Globals.getValue('FFThread').start() Globals.getValue('FFThread').start()
# initDB # initDB
@classmethod @classmethod
def closePopen(self): def closePopen(self):
@ -260,20 +265,46 @@ class ProjectManage(object):
return historyDB return historyDB
@classmethod @classmethod
def editProject(self, name, Nname, des): def editProject(self, name, Nname, des, proType):
# 修改工程信息 # 修改工程信息
name = str(name) name = str(name)
Nname = str(Nname) Nname = str(Nname)
des = str(des) des = str(des)
Client.initDB() Client.initDB()
if Project.getByName(Nname):
if name == Nname:
if name == Globals.getValue('currentPro'):
self.editCurProject(name, Nname, proType, des)
return
Project.update(projectName = Nname, description = des).where(Project.projectName == name).execute()
QTimer.singleShot(1000, lambda:os.rename(os.path.join('project', name), os.path.join('project', Nname)))
elif Project.getByName(Nname):
return '已有同名工程' return '已有同名工程'
elif not Project.getByName(name): elif not Project.getByName(name):
print('不存在的工程') print('不存在的工程')
return return
else: else:
if name == Globals.getValue('currentPro'):
self.editCurProject(name, Nname, proType, des)
return
Project.update(projectName = Nname, description = des).where(Project.projectName == name).execute() Project.update(projectName = Nname, description = des).where(Project.projectName == name).execute()
os.rename(os.path.join('project', name), os.path.join('project', Nname)) QTimer.singleShot(1000, lambda:os.rename(os.path.join('project', name), os.path.join('project', Nname)))
@classmethod
def editCurProject(self, name, Nname, proType, des):
self.closePopen()
Globals.getValue('currentProDB').close()
Project.update(projectName = Nname, description = des).where(Project.projectName == name).execute()
QTimer.singleShot(1000, lambda:self.reNameCurProDir(name, Nname, proType))
Globals.getValue('MainWindow').varWidget.initIcon()
Globals.setValue('currentPro', Nname)
@classmethod
def reNameCurProDir(self, name, Nname, proType):
os.rename(os.path.join('project', name), os.path.join('project', Nname))
self.switchProject(Nname, proType)
@classmethod @classmethod
def getAllProject(self): def getAllProject(self):

@ -44,26 +44,39 @@ 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 '表头错误'
errorConList = []
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]
varName = l[nameIndex] varName = l[nameIndex]
varType = l[typeIndex] varType = l[typeIndex]
des = l[desIndex] des = '' if l[desIndex] == 'None' else l[desIndex]
address = l[addrIndex] address = l[addrIndex]
slaveID = l[slaveIndex] slaveID = l[slaveIndex]
min = l[minIndex] min = '' if l[minIndex] == 'None' else l[minIndex]
max = l[maxIndex] max = '' if l[maxIndex] == 'None' else l[maxIndex]
if {varName, varType, address, slaveID} & {'None'}:
errorConList.append('{}行导入失败,有关键字段为空'.format(str(index + 1)))
continue
if varType not in ['0', '1', '3', '4']:
errorConList.append('{}行导入失败,变量类型有误'.format(str(index + 1)))
continue
if ModBusVar.getByName(varName): if ModBusVar.getByName(varName):
ModBusVar.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVar.varName == varName).execute() ModBusVar.update(varType = varType, description = des, address = address, slaveID = slaveID, min = min, max = max, order = 'int').where(ModBusVar.varName == varName).execute()
else: else:
ModBusVarModel = ModBusVar() 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) errorConList.append('{}行导入失败,{}'.format(str(index + 1), str(e)))
print('{}行导入出错'.format(index + 1)) continue
else:
if errorConList:
return '\r\n'.join(errorConList)
else:
return '导入成功'
@classmethod @classmethod
def exportModbusVar(self, excelPath): def exportModbusVar(self, excelPath):

Loading…
Cancel
Save