from PyQt5.QtWidgets import QPushButton,QStackedWidget, QLineEdit, QVBoxLayout, QHBoxLayout, QWidget, QLabel, QSplitter from utils.DBModels.DeviceParModels import * from UI.BlockParameterView import PressureTBlockView, AIFunctionBlockView, PhysicalBlockView from UI.SearchAddressWidget import SearchAddressWidget class BlockParameterManageWidget(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.pressureTBlockView = PressureTBlockView() self.aiFunctionBlockView = AIFunctionBlockView() self.physicalBlockView = PhysicalBlockView() self.mainlayout = QVBoxLayout() self.parameStackWidget = QStackedWidget() self.settingLayout = QHBoxLayout() self.deviceAddressLabel = QLabel('从站地址') self.deviceAddressEdit = QLineEdit() self.confirmBtn = QPushButton('确定') self.confirmBtn.clicked.connect(self.testUI) self.deviceAddressSearchBtn = QPushButton('查找') self.deviceAddressSearchBtn.clicked.connect(self.searchAddress) self.pblockBtn = QPushButton('物理块') # self.pblockBtn.setCheckable(True) self.pblockBtn.clicked.connect(lambda: self.switchParameterWidget('pblockBtn')) self.fblockBtn = QPushButton('功能块') self.fblockBtn.clicked.connect(lambda: self.switchParameterWidget('fblockBtn')) # self.pblockBtn.setCheckable(True) self.tblockBtn = QPushButton('转换块') self.tblockBtn.clicked.connect(lambda: self.switchParameterWidget('tblockBtn')) # self.tblockBtn.setCheckable(True) self.settingLayout.addWidget(self.deviceAddressLabel, 1) self.settingLayout.addWidget(self.deviceAddressEdit, 1) self.settingLayout.addWidget(self.confirmBtn, 1) self.settingLayout.addWidget(self.deviceAddressSearchBtn, 1) self.settingLayout.addWidget(self.pblockBtn, 1) self.settingLayout.addWidget(self.fblockBtn, 1) self.settingLayout.addWidget(self.tblockBtn, 1) self.settingLayout.addWidget(QSplitter(), 18) self.mainlayout.addLayout(self.settingLayout,1) self.parameStackWidget.addWidget(self.physicalBlockView) self.parameStackWidget.addWidget(self.aiFunctionBlockView) self.parameStackWidget.addWidget(self.pressureTBlockView) self.mainlayout.addWidget(self.parameStackWidget, 20) # self.proxy = QtCore.QSortFilterProxyModel(self) # self.parameTableView.proxy = self.proxy # self.proxy.setSourceModel(self.parameTableView.model) # self.parameTableView.setModel(self.proxy) # datas = PressureTranslationBlock.getallParame() # for index, data in enumerate(datas): # desc = data[2].replace('\r\n', '').replace('\n', '') # lines = [desc[i:i+50] + "\r\n" for i in range(0, len(desc), 50)] # # 合并列表为一个字符串,移除最后一个换行符 # result = "".join(lines).rstrip("\r\n") # data[2] = result # data = data + ['', '', ''] # self.parameTableView.model.append_data(data) # self.parameTableView.setVerticalHeader(ParamsVHeader(self, self.parameTableView.model.datas)) self.setLayout(self.mainlayout) def switchParameterWidget(self,blockType): match blockType: case "pblockBtn": self.parameStackWidget.setCurrentIndex(0) case "fblockBtn": self.parameStackWidget.setCurrentIndex(1) case "tblockBtn": self.parameStackWidget.setCurrentIndex(2) def testUI(self): model = self.parameStackWidget.currentWidget().model model.updateColumn(5, '查询中...') def searchAddress(self): self.searchAddressWidget = SearchAddressWidget(self.deviceAddressEdit) self.searchAddressWidget.show()