|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
|
|
|
|
|
from ast import match_case
|
|
|
|
|
from tkinter.ttk import Combobox
|
|
|
|
|
from numpy import mat
|
|
|
|
|
import qtawesome
|
|
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
|
from PyQt5.QtWidgets import QStyledItemDelegate, QStyle, QComboBox, QMessageBox, QPushButton,QStackedWidget, QLineEdit, QVBoxLayout, QHBoxLayout, QWidget, QLabel, QSplitter, QButtonGroup
|
|
|
|
@ -28,7 +30,8 @@ class TbCombox(QComboBox):
|
|
|
|
|
def initUI(self):
|
|
|
|
|
# 创建ComboBox
|
|
|
|
|
|
|
|
|
|
self.addItems(["选项很长很长很长", "选项2", "选项3"])
|
|
|
|
|
self.addItems(["压力转换块 ", "温度转换块", "物位转换块", "流量转换块"])
|
|
|
|
|
|
|
|
|
|
self.setEditable(True) # 设置为可编辑以应用样式表隐藏文本
|
|
|
|
|
self.setObjectName('tbcombox')
|
|
|
|
|
# 设置样式隐藏文本
|
|
|
|
@ -44,8 +47,8 @@ class TbCombox(QComboBox):
|
|
|
|
|
self.setFixedSize(30, 40)
|
|
|
|
|
|
|
|
|
|
# 确保下拉列表宽度适应最长项
|
|
|
|
|
max_width = max(self.fontMetrics().width(self.itemText(i)) for i in range(self.count()))
|
|
|
|
|
self.view().setMinimumWidth(max_width)
|
|
|
|
|
# max_width = max(self.fontMetrics().width(self.itemText(i)) for i in range(self.count()))
|
|
|
|
|
self.view().setMinimumWidth(100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -55,6 +58,7 @@ class DynamicAddBlock(QHBoxLayout):
|
|
|
|
|
self.blocklist = blocklist
|
|
|
|
|
self.buttonlist = []
|
|
|
|
|
self.blockViewlist = []
|
|
|
|
|
self.tbList = ['PressureTranslationBlock', 'TemperatureTranslationBlock', 'LevelTranslationBlock', 'FlowTranslationBlock'] #存放四个转换块
|
|
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
|
|
def initUI(self):
|
|
|
|
@ -66,12 +70,12 @@ class DynamicAddBlock(QHBoxLayout):
|
|
|
|
|
pblockBtn = QPushButton('物理块')
|
|
|
|
|
|
|
|
|
|
pblockBtn.setCheckable(True)
|
|
|
|
|
pblockBtn.setFixedSize(90, 43)
|
|
|
|
|
# pblockBtn.setFixedSize(90, 43)
|
|
|
|
|
pblockBtn.setObjectName("parameBtn")
|
|
|
|
|
pblockBtn.setIcon(qtawesome.icon('fa.th-large', color='#1fbb6f'))
|
|
|
|
|
# pblockBtn.setCheckable(True)
|
|
|
|
|
pblockBtn.clicked.connect(lambda _, pbbtn = pblockBtn: self.switchParameterWidget(pbbtn))
|
|
|
|
|
self.addWidget(pblockBtn)
|
|
|
|
|
self.addWidget(pblockBtn, 3)
|
|
|
|
|
self.buttonlist.append(pblockBtn)
|
|
|
|
|
physicalBlockView = ParmView(PhysicalBlock)
|
|
|
|
|
self.blockViewlist.append(physicalBlockView)
|
|
|
|
@ -82,16 +86,16 @@ class DynamicAddBlock(QHBoxLayout):
|
|
|
|
|
|
|
|
|
|
for i in range(fbNumber):
|
|
|
|
|
fblockBtn = QPushButton('功能块' + str(i + 1))
|
|
|
|
|
fblockBtn.setFixedSize(90, 43)
|
|
|
|
|
# fblockBtn.setFixedSize(90, 43)
|
|
|
|
|
fblockBtn.setCheckable(True)
|
|
|
|
|
fblockBtn.setObjectName("parameBtn")
|
|
|
|
|
fblockBtn.setIcon(qtawesome.icon('fa.th-large', color='#1fbb6f'))
|
|
|
|
|
fblockBtn.clicked.connect(lambda _, fbbtn = fblockBtn: self.switchParameterWidget(fbbtn))
|
|
|
|
|
self.addWidget(fblockBtn)
|
|
|
|
|
self.addWidget(fblockBtn, 3)
|
|
|
|
|
self.buttonlist.append(fblockBtn)
|
|
|
|
|
aiFunctionBlockView = ParmView(AIFunctionBlock)
|
|
|
|
|
self.blockViewlist.append(aiFunctionBlockView)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(tbNumber):
|
|
|
|
|
tbwidget = QWidget()
|
|
|
|
|
tbwidget.setObjectName('tbwidget')
|
|
|
|
@ -99,44 +103,46 @@ class DynamicAddBlock(QHBoxLayout):
|
|
|
|
|
|
|
|
|
|
tbwidget.setLayout(tblayout)
|
|
|
|
|
tbcombox = TbCombox()
|
|
|
|
|
|
|
|
|
|
tblockBtn = QPushButton('转换块' + str(i + 1))
|
|
|
|
|
tblockBtn.setObjectName("parameBtn")
|
|
|
|
|
tblockBtn.setFixedSize(90, 43)
|
|
|
|
|
tbcombox.setCurrentIndex(0)
|
|
|
|
|
tblockBtn = QPushButton('压力转换块' + str(i + 1))
|
|
|
|
|
tblockBtn.setObjectName("tbparameBtn")
|
|
|
|
|
# tblockBtn.setFixedSize(130, 43)
|
|
|
|
|
tblockBtn.setCheckable(True)
|
|
|
|
|
tblockBtn.setIcon(qtawesome.icon('fa.th-large', color='#1fbb6f'))
|
|
|
|
|
tblockBtn.clicked.connect(lambda _, tbbtn = tblockBtn: self.switchParameterWidget(tbbtn))
|
|
|
|
|
tbcombox.currentIndexChanged.connect(lambda index, combox = tbcombox, tbbtn = tblockBtn : self.chooseTbtype(index, combox, tbbtn))
|
|
|
|
|
|
|
|
|
|
tblayout.addWidget(tblockBtn)
|
|
|
|
|
tblayout.addWidget(tbcombox)
|
|
|
|
|
self.addWidget(tbwidget)
|
|
|
|
|
# tblockBtn.clicked.connect(lambda _, tbbtn = tblockBtn: self.switchParameterWidget(tbbtn))
|
|
|
|
|
tblockBtn.clicked.connect(lambda _, combox = tbcombox, tbbtn = tblockBtn : self.switchTbtype(combox.currentIndex(), combox, tbbtn))
|
|
|
|
|
tbcombox.currentIndexChanged.connect(lambda index, combox = tbcombox, tbbtn = tblockBtn : self.switchTbtype(index, combox, tbbtn))
|
|
|
|
|
|
|
|
|
|
tblayout.addWidget(tblockBtn, 6)
|
|
|
|
|
tblayout.addWidget(tbcombox, 1)
|
|
|
|
|
tblayout.setSpacing(0)
|
|
|
|
|
self.addWidget(tbwidget, 5)
|
|
|
|
|
self.buttonlist.append(tblockBtn)
|
|
|
|
|
pressureTBlockView = ParmView(PressureTranslationBlock)
|
|
|
|
|
self.blockViewlist.append(pressureTBlockView)
|
|
|
|
|
for tb in self.tbList:
|
|
|
|
|
tbBlockView = ParmView(globals()[tb])
|
|
|
|
|
self.blockViewlist.append(tbBlockView)
|
|
|
|
|
|
|
|
|
|
self.parameterButtonGroup = QButtonGroup()
|
|
|
|
|
self.parameterButtonGroup.setExclusive(True)
|
|
|
|
|
for button in self.buttonlist:
|
|
|
|
|
self.parameterButtonGroup.addButton(button)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.parameStackWidget = QStackedWidget()
|
|
|
|
|
for view in self.blockViewlist:
|
|
|
|
|
self.parameStackWidget.addWidget(view)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def switchParameterWidget(self, buttonType):
|
|
|
|
|
print(buttonType)
|
|
|
|
|
for index , button in enumerate(self.buttonlist):
|
|
|
|
|
if button == buttonType:
|
|
|
|
|
self.parameStackWidget.setCurrentIndex(index)
|
|
|
|
|
|
|
|
|
|
def chooseTbtype(self, index, combox, button):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def switchTbtype(self, index, combox, button):
|
|
|
|
|
|
|
|
|
|
tbType = combox.itemText(index)
|
|
|
|
|
button.setText(tbType)
|
|
|
|
|
buttonNumber = button.text()[-1:]
|
|
|
|
|
button.setText(tbType + str(buttonNumber))
|
|
|
|
|
if button.isChecked():
|
|
|
|
|
stackIndex = (int(self.blocklist[0]) + int(self.blocklist[1]) + index) + (int(buttonNumber) - 1) * 4
|
|
|
|
|
self.parameStackWidget.setCurrentIndex(stackIndex)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BlockParameterManageWidget(QWidget):
|
|
|
|
@ -209,11 +215,11 @@ class BlockParameterManageWidget(QWidget):
|
|
|
|
|
self.loadingDataWidget.loadData()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.settingLayout.addLayout(self.blockLayout)
|
|
|
|
|
self.settingLayout.addWidget(QSplitter(), 18)
|
|
|
|
|
self.settingLayout.addLayout(self.blockLayout, 7)
|
|
|
|
|
self.settingLayout.addWidget(QSplitter(), 11)
|
|
|
|
|
self.mainlayout.addWidget(self.blockLayout.parameStackWidget, 20)
|
|
|
|
|
model = self.blockLayout.parameStackWidget.currentWidget().model
|
|
|
|
|
model.updateColumn(5, '查询中...')
|
|
|
|
|
model.updateColumn(5, '查询中sdadadsda\r\nsdasdsasasad\r\nasdsadsad...')
|
|
|
|
|
else:
|
|
|
|
|
reply = QMessageBox.question(self.parent(),
|
|
|
|
|
'警告',
|
|
|
|
|