main
zhangxuxutm 2 years ago
parent ef753e3595
commit f08f3fce2d

@ -88,22 +88,34 @@ class AreaTabWidget(QMainWindow):
deviceName = self.areaTabWidget.parent().parent().parent().parent().parent().windowTitle() deviceName = self.areaTabWidget.parent().parent().parent().parent().parent().windowTitle()
index = self.areaTabWidget.currentIndex() index = self.areaTabWidget.currentIndex()
alldevices = DevicesManange.getAllDevice()
for device in alldevices:
if deviceName in device:
areas = device[3]
if areas is not None:
areas = json.loads(areas)
area = areas[index]
type = area["type"]
print(area, type,'ssss')
if index != -1: if index != -1:
self.areaTabWidget.removeTab(index) self.areaTabWidget.removeTab(index)
del self.widgetList[index] del self.widgetList[index]
Device.delAreas(deviceName, index) Device.delAreas(deviceName, index)
self.mainwindow.devicesManange.getDevice(deviceName).delArea(index) self.mainwindow.devicesManange.getDevice(deviceName).delArea(index, type)
self.mainwindow.devicesManange.recalculateAddress() self.mainwindow.devicesManange.recalculateAddress()
def addAreaWidget(self, widgetList, loacl = True, init = False): def addAreaWidget(self, widgetList, loacl = True, init = False):
dataType = widgetList[0].currentText() dataType = widgetList[0].currentText()
print(widgetList)
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 = self.areaTabWidget.parent().parent().parent().parent().parent().windowTitle() deviceName = self.areaTabWidget.parent().parent().parent().parent().parent().windowTitle()
widgetList = [] widgetLists = []
while areaLayout.count(): while areaLayout.count():
item = areaLayout.takeAt(0) item = areaLayout.takeAt(0)
@ -116,7 +128,7 @@ class AreaTabWidget(QMainWindow):
QMessageBox.warning(self, '警告', '请输入字节长度。') QMessageBox.warning(self, '警告', '请输入字节长度。')
else: else:
widgetList[0].setEnabled(False)
if dataType in ['AI', 'AO']: if dataType in ['AI', 'AO']:
areaLabel = QLabel(dataType + str(1) + ": " + byteLineEdit + 'Byte' ) areaLabel = QLabel(dataType + str(1) + ": " + byteLineEdit + 'Byte' )
areaLabel2 =QLabel('0') areaLabel2 =QLabel('0')
@ -125,7 +137,8 @@ class AreaTabWidget(QMainWindow):
areaLayout.addWidget(areaLabel, 0, 0) areaLayout.addWidget(areaLabel, 0, 0)
areaLayout.addWidget(areaLabel2, 0, 1) areaLayout.addWidget(areaLabel2, 0, 1)
areaLayout.addItem(self.horizontalSpacer, 0, 4) areaLayout.addItem(self.horizontalSpacer, 0, 4)
self.widgetList.append([areaLabel2, areaLayout]) widgetLists.append([areaLabel2, areaLayout])
elif '主站' in deviceName and dataType == 'AO' or ('从站' in deviceName and dataType == 'AI'): elif '主站' in deviceName and dataType == 'AO' or ('从站' in deviceName and dataType == 'AI'):
areaLineEdit = QLineEdit('0') areaLineEdit = QLineEdit('0')
editbtn = QPushButton('强制') editbtn = QPushButton('强制')
@ -135,7 +148,8 @@ class AreaTabWidget(QMainWindow):
areaLayout.addWidget(editbtn, 0, 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.wirteValue(btn)) editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn))
self.widgetList.append([areaLabel2, areaLineEdit, editbtn, areaLayout]) widgetLists.append([areaLabel2, areaLineEdit, editbtn, areaLayout])
self.widgetList.append(widgetLists)
else: else:
channelNumber = int(byteLineEdit) * 8 channelNumber = int(byteLineEdit) * 8
@ -147,15 +161,15 @@ class AreaTabWidget(QMainWindow):
areaLabel2 = QLabel('0') areaLabel2 = QLabel('0')
areaLayout.addWidget(areaLabel, i // 2, i % 2) areaLayout.addWidget(areaLabel, i // 2, i % 2)
areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 1) areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 1)
widgetList.append([areaLabel2, areaLayout]) widgetLists.append([areaLabel2, 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')
areaLayout.addWidget(areaLabel, i // 2, i % 2 + 2) areaLayout.addWidget(areaLabel, i // 2, i % 2 + 2)
areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 3) areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 3)
widgetList.append([areaLabel2, areaLayout]) widgetLists.append([areaLabel2, areaLayout])
self.widgetList.append(widgetList) self.widgetList.append(widgetLists)
if '主站' in deviceName and dataType == 'DO' or ( if '主站' in deviceName and dataType == 'DO' or (
'从站' in deviceName and dataType == 'DI'): '从站' in deviceName and dataType == 'DI'):
for i in range(int(channelNumber)): for i in range(int(channelNumber)):
@ -170,7 +184,7 @@ class AreaTabWidget(QMainWindow):
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.wirteValue(btn)) editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn))
widgetList.append([areaLabel2, areaLineEdit, editbtn]) widgetLists.append([areaLabel2, areaLineEdit, editbtn])
else: else:
areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte') areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte')
areaLabel2 = QLabel('0') areaLabel2 = QLabel('0')
@ -183,15 +197,15 @@ class AreaTabWidget(QMainWindow):
areaLayout.addWidget(editbtn, i // 2, i % 2 + 7) areaLayout.addWidget(editbtn, i // 2, i % 2 + 7)
editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn)) editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn))
widgetList.append([areaLabel2, areaLineEdit, editbtn]) widgetLists.append([areaLabel2, areaLineEdit, editbtn])
self.widgetList.append(widgetList) self.widgetList.append(widgetLists)
areaLayout.addItem(self.verticalSpacer, int(byteLineEdit) * 8 ,0) areaLayout.addItem(self.verticalSpacer, int(byteLineEdit) * 8 ,0)
index = self.areaTabWidget.currentIndex() + 1 index = self.areaTabWidget.currentIndex() + 1
areaId = DevicesManange.getAreaID(deviceName) areaId = DevicesManange.getAreaID(deviceName)
if areaId is not None and index in areaId: if areaId is not None and index in areaId:
if loacl: if loacl:
print(index)
del self.widgetList[index - 1] del self.widgetList[index - 1]
if init: if init:
return return
@ -214,13 +228,16 @@ class AreaTabWidget(QMainWindow):
def wirteValue(self, editBtn): def wirteValue(self, editBtn):
deviceName = self.areaTabWidget.parent().parent().parent().parent().parent().windowTitle() deviceName = self.areaTabWidget.parent().parent().parent().parent().parent().windowTitle()
index = self.areaTabWidget.currentIndex() index = self.areaTabWidget.currentIndex()
tabwidget = self.areaTabWidget.currentWidget() valueList = []
if len(self.widgetList) > 0:
for widgetLists in self.widgetList:
for widgetList in widgetLists:
if isinstance(widgetList[1], QLineEdit):
valueList.append(int(widgetList[1].text()))
for widget in self.widgetList:
if editBtn in widget:
value = widget[1].text()
print(deviceName, index, value)
def readValue(self): def readValue(self):
@ -238,18 +255,15 @@ class AreaTabWidget(QMainWindow):
areaIdList.append(areaId) areaIdList.append(areaId)
deviceList.append([deviceName, areaIdList]) deviceList.append([deviceName, areaIdList])
index = self.areaTabWidget.currentIndex() index = self.areaTabWidget.currentIndex()
print(self.widgetList,'fff')
i = 1
if len(self.widgetList) > 0: if len(self.widgetList) > 0:
if isinstance(self.widgetList[index][0], list):
widgetLists = self.widgetList[index] widgetLists = self.widgetList[index]
for widgetList in widgetLists: for widgetList in widgetLists:
widgetList[0].setText(str(i)) widgetList[0].setText('AAA')
i += 1
else:
widgetLists = self.widgetList[index]
widgetLists[0].setText('aaa')

@ -66,13 +66,11 @@ class Device():
self.outputEndAddress = endAddress self.outputEndAddress = endAddress
def editArea(self, index, type, order, bytes): def editArea(self, index, order, bytes):
if type in ["DI", "AI"]: if type in ["DI", "AI"]:
self.inputAreas[index].type = type
self.inputAreas[index].order = order self.inputAreas[index].order = order
self.inputAreas[index].bytes = bytes self.inputAreas[index].bytes = bytes
elif type in ["AO", "DO"]: elif type in ["AO", "DO"]:
self.outputAreas[index].type = type
self.outputAreas[index].order = order self.outputAreas[index].order = order
self.outputAreas[index].bytes = bytes self.outputAreas[index].bytes = bytes
# self.recalculateAddress() # self.recalculateAddress()

Loading…
Cancel
Save