|
|
|
@ -11,6 +11,7 @@ class MainTop(QtWidgets.QWidget):
|
|
|
|
|
self.MainWindow = MainWindow
|
|
|
|
|
self.setupUi()
|
|
|
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
|
self.setupSearchListeners()
|
|
|
|
|
# self.trendWidget = TrendWidgets()
|
|
|
|
|
|
|
|
|
|
def setupUi(self):
|
|
|
|
@ -71,17 +72,78 @@ class MainTop(QtWidgets.QWidget):
|
|
|
|
|
self.horizontalLayout.setStretch(4, 5)
|
|
|
|
|
|
|
|
|
|
def searchEditTextChanged(self, text):
|
|
|
|
|
# 获取当前活动界面的索引
|
|
|
|
|
currentIndex = self.MainWindow.rightWidget.currentIndex()
|
|
|
|
|
|
|
|
|
|
# 检查是否在趋势界面
|
|
|
|
|
if currentIndex == 2: # 趋势界面
|
|
|
|
|
trendWidget = self.MainWindow.rightWidget.widget(2)
|
|
|
|
|
if hasattr(trendWidget, 'performSearch'):
|
|
|
|
|
trendWidget.performSearch(text)
|
|
|
|
|
elif hasattr(trendWidget, 'filterVarList'):
|
|
|
|
|
trendWidget.filterVarList(text)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# 获取当前活动的变量表格
|
|
|
|
|
currentVarWidget = self.getCurrentVarTable()
|
|
|
|
|
|
|
|
|
|
if currentVarWidget:
|
|
|
|
|
# 在变量管理界面,直接搜索当前表格
|
|
|
|
|
self.performVarTableSearch(currentVarWidget, text)
|
|
|
|
|
else:
|
|
|
|
|
# 使用原有逻辑处理其他界面
|
|
|
|
|
self.performLegacySearch(text)
|
|
|
|
|
|
|
|
|
|
def getCurrentVarTable(self):
|
|
|
|
|
"""获取当前显示的变量表格Widget"""
|
|
|
|
|
# 检查当前是否在变量管理界面
|
|
|
|
|
if self.MainWindow.rightWidget.currentIndex() != 1:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
# 获取变量管理TabWidget
|
|
|
|
|
varManageTabWidget = self.MainWindow.rightWidget.widget(1)
|
|
|
|
|
|
|
|
|
|
# 获取当前活动的Tab
|
|
|
|
|
currentTabIndex = varManageTabWidget.currentIndex()
|
|
|
|
|
currentTabWidget = varManageTabWidget.widget(currentTabIndex)
|
|
|
|
|
|
|
|
|
|
# 检查是否是支持搜索的变量表格(排除Profibus)
|
|
|
|
|
if currentTabIndex == 8: # Profibus界面,不支持搜索
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
# 检查是否有变量表格相关属性
|
|
|
|
|
if hasattr(currentTabWidget, 'varView') or hasattr(currentTabWidget, 'model'):
|
|
|
|
|
return currentTabWidget
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def performVarTableSearch(self, varWidget, text):
|
|
|
|
|
"""对变量表格执行搜索"""
|
|
|
|
|
try:
|
|
|
|
|
# 优先使用统一的performSearch接口
|
|
|
|
|
if hasattr(varWidget, 'performSearch'):
|
|
|
|
|
varWidget.performSearch(text)
|
|
|
|
|
|
|
|
|
|
# VarWidgets类型(Modbus相关和其他继承类)
|
|
|
|
|
elif hasattr(varWidget, 'proxy') and hasattr(varWidget, 'on_lineEdit_textChanged'):
|
|
|
|
|
# 设置搜索列为变量名列(通常是第3列)
|
|
|
|
|
if hasattr(varWidget, 'on_comboBox_currentIndexChanged'):
|
|
|
|
|
varWidget.on_comboBox_currentIndexChanged(3)
|
|
|
|
|
varWidget.on_lineEdit_textChanged(text)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"搜索执行失败: {e}")
|
|
|
|
|
|
|
|
|
|
def performLegacySearch(self, text):
|
|
|
|
|
"""执行原有的搜索逻辑"""
|
|
|
|
|
index = Globals.getValue('SearchWidget')
|
|
|
|
|
# print(index, 'aaaaa')
|
|
|
|
|
|
|
|
|
|
if index == 0:
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).on_comboBox_currentIndexChanged(1)
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).on_lineEdit_textChanged(text)
|
|
|
|
|
elif index == 1:
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).on_comboBox_currentIndexChanged(3)
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).on_lineEdit_textChanged(text)
|
|
|
|
|
elif index == 2:
|
|
|
|
|
# self.MainWindow.rightWidget.widget(index).on_comboBox_currentIndexChanged(0)
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).on_lineEdit_textChanged(text)
|
|
|
|
|
elif index == 2: # 趋势界面
|
|
|
|
|
if hasattr(self.MainWindow.rightWidget.widget(index), 'filterVarList'):
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).filterVarList(text)
|
|
|
|
|
elif index == 3:
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).on_comboBox_currentIndexChanged(1)
|
|
|
|
|
self.MainWindow.rightWidget.widget(index).on_lineEdit_textChanged(text)
|
|
|
|
@ -106,4 +168,85 @@ class MainTop(QtWidgets.QWidget):
|
|
|
|
|
|
|
|
|
|
def mouseDoubleClickEvent(self, e): # 双击
|
|
|
|
|
self.showMax()
|
|
|
|
|
|
|
|
|
|
def setupSearchListeners(self):
|
|
|
|
|
"""设置搜索相关的事件监听"""
|
|
|
|
|
try:
|
|
|
|
|
# 监听主界面切换
|
|
|
|
|
self.MainWindow.rightWidget.currentChanged.connect(self.onMainWidgetChanged)
|
|
|
|
|
|
|
|
|
|
# 监听变量管理Tab切换
|
|
|
|
|
if hasattr(self.MainWindow, 'varManageTabWidget'):
|
|
|
|
|
self.MainWindow.varManageTabWidget.currentChanged.connect(self.onVarTabChanged)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"设置搜索监听失败: {e}")
|
|
|
|
|
|
|
|
|
|
def onMainWidgetChanged(self, index):
|
|
|
|
|
"""主界面切换时更新搜索状态"""
|
|
|
|
|
self.updateSearchPlaceholder()
|
|
|
|
|
self.searchEdit.clear()
|
|
|
|
|
|
|
|
|
|
def onVarTabChanged(self, index):
|
|
|
|
|
"""变量管理Tab切换时更新搜索状态"""
|
|
|
|
|
if self.MainWindow.rightWidget.currentIndex() == 1: # 在变量管理界面
|
|
|
|
|
self.updateSearchPlaceholder()
|
|
|
|
|
self.searchEdit.clear()
|
|
|
|
|
|
|
|
|
|
def updateSearchPlaceholder(self):
|
|
|
|
|
"""根据当前界面更新搜索框占位符和状态"""
|
|
|
|
|
try:
|
|
|
|
|
currentIndex = self.MainWindow.rightWidget.currentIndex()
|
|
|
|
|
|
|
|
|
|
if currentIndex == 2:
|
|
|
|
|
# 趋势界面
|
|
|
|
|
self.searchEdit.setPlaceholderText("搜索历史变量...")
|
|
|
|
|
self.searchEdit.setEnabled(True)
|
|
|
|
|
|
|
|
|
|
elif currentIndex == 1:
|
|
|
|
|
# 变量管理界面
|
|
|
|
|
currentVarWidget = self.getCurrentVarTable()
|
|
|
|
|
if currentVarWidget:
|
|
|
|
|
# 支持搜索的变量表格
|
|
|
|
|
placeholder = self.getVarWidgetPlaceholder(currentVarWidget)
|
|
|
|
|
self.searchEdit.setPlaceholderText(placeholder)
|
|
|
|
|
self.searchEdit.setEnabled(True)
|
|
|
|
|
else:
|
|
|
|
|
# 不支持搜索的Tab(如Profibus)
|
|
|
|
|
self.searchEdit.setPlaceholderText("当前界面不支持搜索")
|
|
|
|
|
self.searchEdit.setEnabled(False)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# 其他界面
|
|
|
|
|
self.searchEdit.setPlaceholderText("搜索...")
|
|
|
|
|
self.searchEdit.setEnabled(True)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"更新搜索占位符失败: {e}")
|
|
|
|
|
self.searchEdit.setPlaceholderText("搜索...")
|
|
|
|
|
self.searchEdit.setEnabled(True)
|
|
|
|
|
|
|
|
|
|
def getVarWidgetPlaceholder(self, varWidget):
|
|
|
|
|
"""根据变量Widget类型获取搜索占位符"""
|
|
|
|
|
try:
|
|
|
|
|
# 获取当前Tab索引来确定类型
|
|
|
|
|
varManageTabWidget = self.MainWindow.rightWidget.widget(1)
|
|
|
|
|
currentTabIndex = varManageTabWidget.currentIndex()
|
|
|
|
|
|
|
|
|
|
placeholderMap = {
|
|
|
|
|
0: "搜索Modbus TCP主站变量...",
|
|
|
|
|
1: "搜索Modbus TCP从站变量...",
|
|
|
|
|
2: "搜索Modbus RTU主站变量...",
|
|
|
|
|
3: "搜索Modbus RTU从站变量...",
|
|
|
|
|
4: "搜索IO变量...",
|
|
|
|
|
5: "搜索TC/RTD变量...",
|
|
|
|
|
6: "搜索HART读取变量...",
|
|
|
|
|
7: "搜索HART模拟变量...",
|
|
|
|
|
9: "搜索远程通讯变量..."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return placeholderMap.get(currentTabIndex, "搜索变量...")
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"获取占位符失败: {e}")
|
|
|
|
|
return "搜索变量..."
|
|
|
|
|
|