diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/UI/AreaTabWidget.py b/UI/AreaTabWidget.py index 204a5ac..46d2abf 100644 --- a/UI/AreaTabWidget.py +++ b/UI/AreaTabWidget.py @@ -1,4 +1,5 @@ import sys +import json from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout, QLabel, QPushButton, \ QHBoxLayout, QComboBox, QLineEdit, QSpacerItem, QSizePolicy, QGridLayout, QMessageBox from PyQt5 import QtCore @@ -69,8 +70,12 @@ class AreaTabWidget(QMainWindow): delAreaBtn.clicked.connect(self.removeAreaTab) + 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) @@ -119,7 +124,7 @@ class AreaTabWidget(QMainWindow): mainLayout.addLayout(topLayout, 1) 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) @@ -138,46 +143,48 @@ class AreaTabWidget(QMainWindow): - def addAreaWidget(self, widgetList): + def addAreaWidget(self, widgetList, okBtn): dataType = widgetList[0].currentText() order = self.dataTypeTranslate(widgetList[1].currentText()) byteLineEdit = widgetList[2].text() areaLayout = widgetList[3] deviceName = widgetList[4] + print(okBtn.parent(),'ssss') if len(byteLineEdit) == 0: QMessageBox.warning(self, '警告', '请输入字节长度。') + else: for i in range(3): widgetList[i].setEnabled(False) if dataType in ['AI', 'AO']: - if i % 2 == 0: - areaLabel = QLabel(dataType + str(i + 1 ) + ": " + byteLineEdit + 'Byte' ) - areaLabel2 =QLabel('0') - areaLineEdit = QLineEdit('0') - editbtn = QPushButton('强制') - - areaLayout.addWidget(areaLabel, i//2, i % 2) - areaLayout.addWidget(areaLabel2, i//2, i % 2 + 1 ) - areaLayout.addWidget(areaLineEdit, i//2, i % 2 + 2 ) - areaLayout.addWidget(editbtn, i // 2, i % 2 + 3) - areaLayout.addItem(self.horizontalSpacer, 0, 4) - editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn)) - self.widgetList.append([areaLabel2, areaLineEdit, editbtn]) - else: - areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte') - areaLabel2 = QLabel('0') - areaLineEdit = QLineEdit('0') - editbtn = QPushButton('强制') - - areaLayout.addWidget(areaLabel, i // 2, i % 2 + 4) - areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 6) - areaLayout.addWidget(areaLineEdit, i // 2, i % 2 + 6) - areaLayout.addWidget(editbtn, i // 2, i % 2 + 7) - editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn)) - self.widgetList.append([areaLabel2, areaLineEdit, editbtn]) + + areaLabel = QLabel(dataType + str(1) + ": " + byteLineEdit + 'Byte' ) + areaLabel2 =QLabel('0') + areaLineEdit = QLineEdit('0') + editbtn = QPushButton('强制') + + areaLayout.addWidget(areaLabel, 0, 0) + areaLayout.addWidget(areaLabel2, 0, 1 ) + areaLayout.addWidget(areaLineEdit, 0, 2 ) + areaLayout.addWidget(editbtn, 0, 3) + areaLayout.addItem(self.horizontalSpacer, 0, 4) + editbtn.clicked.connect(lambda checked, btn=editbtn: self.wirteValue(btn)) + self.widgetList.append([areaLabel2, areaLineEdit, editbtn, areaLayout]) + # else: + # areaLabel = QLabel(dataType + str(i + 1) + ": " + byteLineEdit + 'Byte') + # areaLabel2 = QLabel('0') + # areaLineEdit = QLineEdit('0') + # editbtn = QPushButton('强制') + # + # areaLayout.addWidget(areaLabel, i // 2, i % 2 + 4) + # areaLayout.addWidget(areaLabel2, i // 2, i % 2 + 6) + # areaLayout.addWidget(areaLineEdit, i // 2, i % 2 + 6) + # areaLayout.addWidget(editbtn, i // 2, i % 2 + 7) + # editbtn.clicked.connect(lambda checked, btn=editbtn: self.forceEdit(btn)) + # self.widgetList.append([areaLabel2, areaLineEdit, editbtn]) else: channelNumber = int(byteLineEdit) * 8 for i in range(int(channelNumber)): @@ -191,7 +198,7 @@ class AreaTabWidget(QMainWindow): areaLayout.addWidget(areaLabel2, i//2, i % 2 + 1 ) areaLayout.addWidget(areaLineEdit, i//2, i % 2 + 2 ) 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]) else: 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(areaLineEdit, i // 2, i % 2 + 6) 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]) areaLayout.addItem(self.verticalSpacer, int(byteLineEdit) * 8 ,0) @@ -214,14 +221,29 @@ class AreaTabWidget(QMainWindow): self.dataTypeDict = {'不转换': 'ABCD', '字节转换': 'DCBA', '字转换': 'CDAB', '字内转换': 'BADC'} 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: 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__': app = QApplication(sys.argv) diff --git a/UI/MainWindow.py b/UI/MainWindow.py index 360066e..4ad5ce6 100644 --- a/UI/MainWindow.py +++ b/UI/MainWindow.py @@ -128,15 +128,8 @@ class MainWindow(QMainWindow): 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): - pass + AreaTabWidget().readValue() def tran(self, dataType, order): if dataType == 'AI': @@ -166,9 +159,7 @@ class AreaQMdiSubWindow(QMdiSubWindow): super().__init__() self.parentWindow = parentWindow def closeEvent(self, event): - print(self.parentWindow.subWindows) self.parentWindow.subWindows.remove(self) - print(self.parentWindow.subWindows) DeviceDB.deleteDevice(deviceName = self.windowTitle())