89 lines
3.5 KiB
Python
89 lines
3.5 KiB
Python
|
|
# 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
|
|||
|
|
|
|||
|
|
|
|||
|
|
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() # 系统控制按钮
|
|||
|
|
|
|||
|
|
def setupLayout(self):
|
|||
|
|
"""设置垂直布局,从上到下排列部件"""
|
|||
|
|
main_layout = QVBoxLayout(self) # 主布局:垂直布局
|
|||
|
|
# 设置布局间距(部件之间的距离)和边距(布局与窗口边缘的距离)
|
|||
|
|
main_layout.setSpacing(0) # 部件间距0px
|
|||
|
|
main_layout.setContentsMargins(15, 15, 15, 15) # 上下左右边距15px
|
|||
|
|
|
|||
|
|
# 依次添加部件到布局(从上到下)
|
|||
|
|
main_layout.addWidget(self.status_monitor, alignment=Qt.AlignHCenter)
|
|||
|
|
main_layout.addWidget(self.hopper_widget, alignment=Qt.AlignHCenter)
|
|||
|
|
main_layout.addWidget(self.arc_progress, alignment=Qt.AlignHCenter)
|
|||
|
|
main_layout.addWidget(self.production_progress, alignment=Qt.AlignHCenter)
|
|||
|
|
main_layout.addWidget(self.system_button_widget, alignment=Qt.AlignHCenter)
|
|||
|
|
|
|||
|
|
# 将布局应用到主窗口
|
|||
|
|
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())
|