2025-10-18 18:29:40 +08:00
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
from typing import List
|
|
|
|
|
|
from PySide6.QtCore import Qt, Signal, QEasingCurve, QUrl, QSize, QTimer
|
|
|
|
|
|
from PySide6.QtGui import QIcon, QDesktopServices, QColor
|
|
|
|
|
|
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QVBoxLayout,
|
|
|
|
|
|
QFrame, QWidget, QSpacerItem, QSizePolicy)
|
|
|
|
|
|
|
|
|
|
|
|
from .widgets.status_monitor_widget import StatusMonitorWidget
|
|
|
|
|
|
from .widgets.hopper_widget import HopperWidget
|
|
|
|
|
|
from .widgets.arc_progress_widget import ArcProgressWidget
|
|
|
|
|
|
from .widgets.production_progress_widget import ProductionProgressWidget
|
|
|
|
|
|
from .widgets.system_button_widget import SystemButtonWidget
|
2025-10-20 18:10:07 +08:00
|
|
|
|
from .widgets.vibration_video_widget import VibrationVideoWidget
|
2025-10-18 18:29:40 +08:00
|
|
|
|
|
|
|
|
|
|
class MainWindow(QWidget):
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
self.initWindow()
|
|
|
|
|
|
self.createSubWidgets() # 创建子部件
|
|
|
|
|
|
self.setupLayout() # 设置布局
|
|
|
|
|
|
self.connectSignalToSlot()
|
|
|
|
|
|
|
|
|
|
|
|
def connectSignalToSlot(self):
|
|
|
|
|
|
# 可添加信号槽连接
|
|
|
|
|
|
self.system_button_widget.buttons["系统启动"].clicked.connect(self.handleSystemStart)
|
|
|
|
|
|
self.system_button_widget.buttons["系统停止"].clicked.connect(self.handleSystemStop)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handleSystemStart(self):
|
|
|
|
|
|
# 测试
|
|
|
|
|
|
self.production_progress.testProgress(60)
|
|
|
|
|
|
self.arc_progress.testProgress(60)
|
|
|
|
|
|
|
|
|
|
|
|
def handleSystemStop(self):
|
|
|
|
|
|
# 测试
|
|
|
|
|
|
self.production_progress.animation.stop()
|
|
|
|
|
|
self.arc_progress.animation.stop()
|
|
|
|
|
|
|
|
|
|
|
|
def initWindow(self):
|
|
|
|
|
|
"""初始化窗口基本属性"""
|
|
|
|
|
|
self.setWindowTitle("中交三航主界面") # 设置窗口标题
|
|
|
|
|
|
self.setMinimumSize(1280, 1040) # 设置最小尺寸(可根据需求调整)
|
|
|
|
|
|
# 设置主界面窗口背景色
|
|
|
|
|
|
self.setStyleSheet("background-color: #ffffff;")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def createSubWidgets(self):
|
|
|
|
|
|
"""创建所有子部件实例"""
|
|
|
|
|
|
self.status_monitor = StatusMonitorWidget() # 最上方:状态监控部件
|
|
|
|
|
|
self.hopper_widget = HopperWidget() # 中间1:料斗部件
|
|
|
|
|
|
self.arc_progress = ArcProgressWidget() # 中间2:弧形进度部件
|
|
|
|
|
|
self.production_progress = ProductionProgressWidget() # 生产进度部件
|
|
|
|
|
|
self.system_button_widget = SystemButtonWidget() # 系统控制按钮
|
2025-10-20 18:10:07 +08:00
|
|
|
|
self.vibration_video = VibrationVideoWidget() # 振捣视频控件
|
2025-10-18 18:29:40 +08:00
|
|
|
|
|
|
|
|
|
|
def setupLayout(self):
|
|
|
|
|
|
"""设置垂直布局,从上到下排列部件"""
|
|
|
|
|
|
main_layout = QVBoxLayout(self) # 主布局:垂直布局
|
|
|
|
|
|
# 设置布局间距(部件之间的距离)和边距(布局与窗口边缘的距离)
|
|
|
|
|
|
main_layout.setSpacing(0) # 部件间距0px
|
|
|
|
|
|
main_layout.setContentsMargins(15, 15, 15, 15) # 上下左右边距15px
|
|
|
|
|
|
|
2025-10-20 18:10:07 +08:00
|
|
|
|
sub_v_layout = QVBoxLayout()
|
|
|
|
|
|
sub_v_layout.setSpacing(0)
|
2025-10-18 18:29:40 +08:00
|
|
|
|
# 依次添加部件到布局(从上到下)
|
2025-10-20 18:10:07 +08:00
|
|
|
|
# sub_v_layout.addWidget(self.status_monitor, alignment=Qt.AlignHCenter)
|
|
|
|
|
|
sub_v_layout.addWidget(self.hopper_widget, alignment=Qt.AlignHCenter)
|
|
|
|
|
|
sub_v_layout.addWidget(self.arc_progress, alignment=Qt.AlignHCenter)
|
|
|
|
|
|
sub_v_layout.addWidget(self.production_progress, alignment=Qt.AlignHCenter)
|
|
|
|
|
|
# sub_v_layout.addWidget(self.system_button_widget, alignment=Qt.AlignHCenter)
|
|
|
|
|
|
|
|
|
|
|
|
middle_h_layout = QHBoxLayout()
|
|
|
|
|
|
middle_h_layout.setSpacing(20)
|
|
|
|
|
|
# 加入垂直子布局(设置拉伸因子1,让其占满水平剩余空间)
|
|
|
|
|
|
middle_h_layout.addLayout(sub_v_layout, stretch=1)
|
|
|
|
|
|
# 加入振捣视频控件(对齐方式为顶部)
|
|
|
|
|
|
middle_h_layout.addWidget(self.vibration_video, alignment=Qt.AlignTop)
|
|
|
|
|
|
|
|
|
|
|
|
# === 添加到著布局
|
|
|
|
|
|
main_layout.addLayout(middle_h_layout)
|
2025-10-18 18:29:40 +08:00
|
|
|
|
|
|
|
|
|
|
# 将布局应用到主窗口
|
|
|
|
|
|
self.setLayout(main_layout)
|
|
|
|
|
|
|
|
|
|
|
|
def resizeEvent(self, e):
|
|
|
|
|
|
"""窗口大小变化时的回调"""
|
|
|
|
|
|
super().resizeEvent(e)
|
|
|
|
|
|
|
|
|
|
|
|
def closeEvent(self, e):
|
|
|
|
|
|
"""窗口关闭时的回调"""
|
|
|
|
|
|
super().closeEvent(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
import sys
|
|
|
|
|
|
app = QApplication([])
|
|
|
|
|
|
window = MainWindow()
|
|
|
|
|
|
window.show()
|
|
|
|
|
|
sys.exit(app.exec())
|