|
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
HART通信主窗口类
|
|
|
|
|
|
实现基于PyQt的HART通信界面主窗口,包含多个功能选项卡
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QTabWidget, QVBoxLayout, QWidget
|
|
|
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
|
|
from PyQt5.QtGui import QFont
|
|
|
|
|
|
|
|
|
|
|
|
# 导入自定义模块
|
|
|
|
|
|
from UI.HartWidgets.HartConnectionWidget import HartConnectionWidget
|
|
|
|
|
|
from UI.HartWidgets.HartDeviceInfoWidget import HartDeviceInfoWidget
|
|
|
|
|
|
from UI.HartWidgets.HartDeviceConfigWidget import HartDeviceConfigWidget
|
|
|
|
|
|
from UI.HartWidgets.HartSensorConfigWidget import HartSensorConfigWidget
|
|
|
|
|
|
from UI.HartWidgets.HartCalibrationWidget import HartCalibrationWidget
|
|
|
|
|
|
from UI.HartWidgets.HartVariableInfoWidget import HartVariableInfoWidget
|
|
|
|
|
|
|
|
|
|
|
|
class HartMainWindow(QWidget):
|
|
|
|
|
|
"""
|
|
|
|
|
|
HART通信主窗口类
|
|
|
|
|
|
实现基于PyQt的HART通信界面主窗口,包含多个功能选项卡
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
"""
|
|
|
|
|
|
初始化主窗口
|
|
|
|
|
|
"""
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
|
|
|
|
# 创建主布局
|
|
|
|
|
|
self.mainLayout = QVBoxLayout(self)
|
|
|
|
|
|
self.mainLayout.setContentsMargins(10, 10, 10, 10)
|
|
|
|
|
|
|
|
|
|
|
|
# 创建选项卡窗口部件
|
|
|
|
|
|
self.tabWidget = QTabWidget()
|
|
|
|
|
|
self.tabWidget.setObjectName("hartTabWidget")
|
|
|
|
|
|
self.tabWidget.tabBar().setObjectName("hartTabBar")
|
|
|
|
|
|
self.tabWidget.setFont(QFont("Microsoft YaHei", 10))
|
|
|
|
|
|
self.mainLayout.addWidget(self.tabWidget)
|
|
|
|
|
|
|
|
|
|
|
|
# 初始化HART通信对象
|
|
|
|
|
|
self.hartComm = None
|
|
|
|
|
|
|
|
|
|
|
|
# 初始化界面
|
|
|
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
|
|
|
|
def initUI(self):
|
|
|
|
|
|
"""
|
|
|
|
|
|
初始化用户界面
|
|
|
|
|
|
"""
|
|
|
|
|
|
# 创建连接设备选项卡
|
|
|
|
|
|
self.connectionWidget = HartConnectionWidget()
|
|
|
|
|
|
self.tabWidget.addTab(self.connectionWidget, "设备连接")
|
|
|
|
|
|
|
|
|
|
|
|
# 创建设备信息选项卡
|
|
|
|
|
|
self.deviceInfoWidget = HartDeviceInfoWidget()
|
|
|
|
|
|
self.tabWidget.addTab(self.deviceInfoWidget, "设备信息")
|
|
|
|
|
|
|
|
|
|
|
|
# 创建变量信息选项卡
|
|
|
|
|
|
self.variableInfoWidget = HartVariableInfoWidget()
|
|
|
|
|
|
self.tabWidget.addTab(self.variableInfoWidget, "变量信息")
|
|
|
|
|
|
|
|
|
|
|
|
# 创建传感器配置选项卡
|
|
|
|
|
|
self.sensorConfigWidget = HartSensorConfigWidget()
|
|
|
|
|
|
self.tabWidget.addTab(self.sensorConfigWidget, "传感器配置")
|
|
|
|
|
|
|
|
|
|
|
|
# 创建校准功能选项卡
|
|
|
|
|
|
self.calibrationWidget = HartCalibrationWidget()
|
|
|
|
|
|
self.tabWidget.addTab(self.calibrationWidget, "校准功能")
|
|
|
|
|
|
|
|
|
|
|
|
# 创建设备配置选项卡
|
|
|
|
|
|
self.deviceConfigWidget = HartDeviceConfigWidget()
|
|
|
|
|
|
self.tabWidget.addTab(self.deviceConfigWidget, "设备配置")
|
|
|
|
|
|
|
|
|
|
|
|
# 将 connectionWidget 实例传递给 deviceConfigWidget
|
|
|
|
|
|
self.deviceConfigWidget.setConnectionWidget(self.connectionWidget)
|
|
|
|
|
|
|
|
|
|
|
|
# 连接信号和槽
|
|
|
|
|
|
self.connectionWidget.connectionStatusChanged.connect(self.onConnectionStatusChanged)
|
|
|
|
|
|
self.connectionWidget.hartCommCreated.connect(self.onHartCommCreated)
|
|
|
|
|
|
|
|
|
|
|
|
def onConnectionStatusChanged(self, connected):
|
|
|
|
|
|
"""
|
|
|
|
|
|
连接状态改变时的处理函数
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
connected (bool): 连接状态
|
|
|
|
|
|
"""
|
|
|
|
|
|
# 根据连接状态启用或禁用其他选项卡
|
|
|
|
|
|
for i in range(1, self.tabWidget.count()):
|
|
|
|
|
|
self.tabWidget.setTabEnabled(i, connected)
|
|
|
|
|
|
|
|
|
|
|
|
def onHartCommCreated(self, hartComm):
|
|
|
|
|
|
"""
|
|
|
|
|
|
HART通信对象创建时的处理函数
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
hartComm (HARTCommunication): HART通信对象
|
|
|
|
|
|
"""
|
|
|
|
|
|
self.hartComm = hartComm
|
|
|
|
|
|
# 将HART通信对象传递给其他选项卡
|
|
|
|
|
|
self.deviceInfoWidget.setHartComm(hartComm)
|
|
|
|
|
|
self.variableInfoWidget.setHartComm(hartComm)
|
|
|
|
|
|
self.sensorConfigWidget.setHartComm(hartComm)
|
|
|
|
|
|
self.calibrationWidget.setHartComm(hartComm)
|
|
|
|
|
|
self.deviceConfigWidget.setHartComm(hartComm)
|