main
zhangxuxutm 2 years ago
parent 5d3797f928
commit 84ca050d90

@ -1,4 +1,5 @@
import sys import sys
import json
from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout, QLabel, QPushButton, \ from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout, QLabel, QPushButton, \
QHBoxLayout, QComboBox, QLineEdit, QSpacerItem, QSizePolicy, QGridLayout, QMessageBox QHBoxLayout, QComboBox, QLineEdit, QSpacerItem, QSizePolicy, QGridLayout, QMessageBox
from PyQt5 import QtCore from PyQt5 import QtCore
@ -69,8 +70,12 @@ class AreaTabWidget(QMainWindow):
delAreaBtn.clicked.connect(self.removeAreaTab) delAreaBtn.clicked.connect(self.removeAreaTab)
widgetList.extend([dataTypeCombox, orderCombox, byteLineEdit, areaLayout, deviceName]) widgetList.extend([dataTypeCombox, orderCombox, byteLineEdit, areaLayout, deviceName])
self.addAreaWidget(widgetList)
okBtn.clicked.connect(lambda checked, btn=okBtn: self.addAreaWidget(widgetList, okBtn))
self.addAreaWidget(widgetList, okBtn)
areaTabWidget.setLayout(mainLayout) areaTabWidget.setLayout(mainLayout)
@ -119,7 +124,7 @@ class AreaTabWidget(QMainWindow):
mainLayout.addLayout(topLayout, 1) mainLayout.addLayout(topLayout, 1)
mainLayout.addLayout(areaLayout, 9) mainLayout.addLayout(areaLayout, 9)
okBtn.clicked.connect(lambda: self.addAreaWidget(widgetList)) okBtn.clicked.connect(lambda checked, btn=okBtn: self.addAreaWidget(widgetList, okBtn))
delAreaBtn.clicked.connect(self.removeAreaTab) delAreaBtn.clicked.connect(self.removeAreaTab)
@ -138,46 +143,48 @@ class AreaTabWidget(QMainWindow):
def addAreaWidget(self, widgetList): def addAreaWidget(self, widgetList, okBtn):
dataType = widgetList[0].currentText() dataType = widgetList[0].currentText()
order = self.dataTypeTranslate(widgetList[1].currentText()) order = self.dataTypeTranslate(widgetList[1].currentText())
byteLineEdit = widgetList[2].text() byteLineEdit = widgetList[2].text()
areaLayout = widgetList[3] areaLayout = widgetList[3]
deviceName = widgetList[4] deviceName = widgetList[4]
print(okBtn.parent(),'ssss')
if len(byteLineEdit) == 0: if len(byteLineEdit) == 0:
QMessageBox.warning(self, '警告', '请输入字节长度。') QMessageBox.warning(self, '警告', '请输入字节长度。')
else: else:
for i in range(3): for i in range(3):
widgetList[i].setEnabled(False) widgetList[i].setEnabled(False)
if dataType in ['AI', 'AO']: if dataType in ['AI', 'AO']:
if i % 2 == 0:
areaLabel = QLabel(dataType + str(i + 1 ) + ": " + byteLineEdit + 'Byte' ) areaLabel = QLabel(dataType + str(1) + ": " + byteLineEdit + 'Byte' )
areaLabel2 =QLabel('0') areaLabel2 =QLabel('0')
areaLineEdit = QLineEdit('0') areaLineEdit = QLineEdit('0')
editbtn = QPushButton('强制') editbtn = QPushButton('强制')
areaLayout.addWidget(areaLabel, i//2, i % 2) areaLayout.addWidget(areaLabel, 0, 0)
areaLayout.addWidget(areaLabel2, i//2, i % 2 + 1 ) areaLayout.addWidget(areaLabel2, 0, 1 )
areaLayout.addWidget(areaLineEdit, i//2, i % 2 + 2 ) areaLayout.addWidget(areaLineEdit, 0, 2 )
areaLayout.addWidget(editbtn, i // 2, i % 2 + 3) areaLayout.addWidget(editbtn, 0, 3)
areaLayout.addItem(self.horizontalSpacer, 0, 4) areaLayout.addItem(self.horizontalSpacer, 0, 4)
editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn)) editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn))
self.widgetList.append([areaLabel2, areaLineEdit, editbtn]) self.widgetList.append([areaLabel2, areaLineEdit, editbtn, areaLayout])
else: # else:
areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte') # areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte')
areaLabel2 = QLabel('0') # areaLabel2 = QLabel('0')
areaLineEdit = QLineEdit('0') # areaLineEdit = QLineEdit('0')
editbtn = QPushButton('强制') # editbtn = QPushButton('强制')
#
areaLayout.addWidget(areaLabel, i // 2, i % 2 + 4) # areaLayout.addWidget(areaLabel, i // 2, i % 2 + 4)
areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 6) # areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 6)
areaLayout.addWidget(areaLineEdit, i // 2, i % 2 + 6) # areaLayout.addWidget(areaLineEdit, i // 2, i % 2 + 6)
areaLayout.addWidget(editbtn, i // 2, i % 2 + 7) # areaLayout.addWidget(editbtn, i // 2, i % 2 + 7)
editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn)) # editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn))
self.widgetList.append([areaLabel2, areaLineEdit, editbtn]) # self.widgetList.append([areaLabel2, areaLineEdit, editbtn])
else: else:
channelNumber = int(byteLineEdit) * 8 channelNumber = int(byteLineEdit) * 8
for i in range(int(channelNumber)): for i in range(int(channelNumber)):
@ -191,7 +198,7 @@ class AreaTabWidget(QMainWindow):
areaLayout.addWidget(areaLabel2, i//2, i % 2 + 1 ) areaLayout.addWidget(areaLabel2, i//2, i % 2 + 1 )
areaLayout.addWidget(areaLineEdit, i//2, i % 2 + 2 ) areaLayout.addWidget(areaLineEdit, i//2, i % 2 + 2 )
areaLayout.addWidget(editbtn, i // 2, i % 2 + 3) areaLayout.addWidget(editbtn, i // 2, i % 2 + 3)
editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn)) editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn))
self.widgetList.append([areaLabel2, areaLineEdit, editbtn]) self.widgetList.append([areaLabel2, areaLineEdit, editbtn])
else: else:
areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte') areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte')
@ -203,7 +210,7 @@ class AreaTabWidget(QMainWindow):
areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 5) areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 5)
areaLayout.addWidget(areaLineEdit, i // 2, i % 2 + 6) areaLayout.addWidget(areaLineEdit, i // 2, i % 2 + 6)
areaLayout.addWidget(editbtn, i // 2, i % 2 + 7) areaLayout.addWidget(editbtn, i // 2, i % 2 + 7)
editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn)) editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn))
self.widgetList.append([areaLabel2, areaLineEdit, editbtn]) self.widgetList.append([areaLabel2, areaLineEdit, editbtn])
areaLayout.addItem(self.verticalSpacer, int(byteLineEdit) * 8 ,0) areaLayout.addItem(self.verticalSpacer, int(byteLineEdit) * 8 ,0)
@ -214,14 +221,29 @@ class AreaTabWidget(QMainWindow):
self.dataTypeDict = {'不转换': 'ABCD', '字节转换': 'DCBA', '字转换': 'CDAB', '字内转换': 'BADC'} self.dataTypeDict = {'不转换': 'ABCD', '字节转换': 'DCBA', '字转换': 'CDAB', '字内转换': 'BADC'}
return self.dataTypeDict[order] return self.dataTypeDict[order]
def forceEdit(self, editBtn): def wirteValue(self, editBtn):
deviceName = self.areaTabWidget.parent().parent().parent().parent().parent().windowTitle()
index = self.areaTabWidget.currentIndex()
for widget in self.widgetList: for widget in self.widgetList:
if editBtn in widget: if editBtn in widget:
widget[0].setText(widget[1].text()) value = widget[1].text()
print(deviceName, index, value)
def readValue(self):
deviceList = []
areaIdList = []
devices = DevicesManange.getAllDevice()
for device in devices:
deviceName = device[0]
areas = device[3]
if areas is not None:
areas = json.loads(areas)
for area in areas:
areaId = area["id"]
areaIdList.append(areaId)
deviceList.append([deviceName, areaIdList])
print(deviceList)
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)

@ -128,15 +128,8 @@ class MainWindow(QMainWindow):
self.deviceWidget(windowTitle) self.deviceWidget(windowTitle)
def writeValue(self):
for deviceNames in self.subWindows:
deviceName = deviceNames.windowTitle()
areas = [[1,2,3,4,5],[2,3,4,5]]
for area in areas:
pass
def startProtocol(self): def startProtocol(self):
pass AreaTabWidget().readValue()
def tran(self, dataType, order): def tran(self, dataType, order):
if dataType == 'AI': if dataType == 'AI':
@ -166,9 +159,7 @@ class AreaQMdiSubWindow(QMdiSubWindow):
super().__init__() super().__init__()
self.parentWindow = parentWindow self.parentWindow = parentWindow
def closeEvent(self, event): def closeEvent(self, event):
print(self.parentWindow.subWindows)
self.parentWindow.subWindows.remove(self) self.parentWindow.subWindows.remove(self)
print(self.parentWindow.subWindows)
DeviceDB.deleteDevice(deviceName = self.windowTitle()) DeviceDB.deleteDevice(deviceName = self.windowTitle())

Loading…
Cancel
Save