Files
zjsh_mixing_system_ui/main_window.py
2025-11-16 11:55:28 +08:00

114 lines
4.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding: utf-8
from typing import List
from PySide6.QtCore import Qt, Signal, QEasingCurve, QUrl, QSize, QTimer, QEvent
from PySide6.QtGui import QIcon, QDesktopServices, QColor, QPalette, QBrush, QImage
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QVBoxLayout,
QFrame, QWidget, QSpacerItem, QSizePolicy, QMainWindow, QPushButton)
from system_nav_bar import SystemNavBar
from bottom_control_widget import BottomControlWidget
from dispatch_task import DispatchDetailsDialog
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.initWindow()
self.createSubWidgets() # 创建子部件
self.setupLayout() # 设置布局
def initWindow(self):
"""初始化窗口基本属性"""
self.setWindowTitle("中交三航主界面") # 设置窗口标题
# 设置最小尺寸(可根据需求调整)
# 触摸屏尺寸为 1280*800
self.setMinimumSize(1280, 800)
self.setObjectName("MainWindow")
# Qt.FramelessWindowHint
self.setWindowFlags(Qt.FramelessWindowHint) # 无边框窗口
# 设置主界面背景图片
try:
self.background_image = QImage("主界面背景.png")
if self.background_image.isNull():
raise Exception("图片为空,可能路径错误或格式不支持")
# print("图片加载成功")
except Exception as e:
print(f"主界面背景图片加载失败: {e}")
self.background_image = None
return # 加载背景失败
self.update_background()
def createSubWidgets(self):
"""创建所有子部件实例"""
self.system_nav_bar = SystemNavBar() # 最上方:系统导航栏
self.bottom_control_widget = BottomControlWidget() # 最下方: 控制的按钮 (系统诊断、系统中心等)
# 中间:任务派单
self.dispatch_dialog = DispatchDetailsDialog(self)
def setupLayout(self):
"""设置垂直布局,从上到下排列部件"""
main_layout = QVBoxLayout(self) # 主布局:垂直布局
main_layout.setSpacing(0) # 部件间距0px
main_layout.setContentsMargins(0, 0, 0, 0) # 左上右下边距0px
# 添加最上方的 系统导航栏包括系统标题、中交三航的logo等
main_layout.addWidget(self.system_nav_bar, alignment=Qt.AlignTop)
# 添加中间内容区
main_layout.addWidget(self.dispatch_dialog, alignment=Qt.AlignCenter)
# 添加最下方的 控制按钮控件
main_layout.addWidget(self.bottom_control_widget, alignment=Qt.AlignBottom)
# 关闭按钮
self.system_nav_bar.msg_container.close_btn.clicked.connect(self.close)
# 将布局应用到主窗口
self.setLayout(main_layout)
def show_dispatch_dialog(self):
"""显示派单详细弹窗(居中显示在主界面)"""
# 计算弹窗居中位置
main_geometry = self.frameGeometry()
dialog_geometry = self.dispatch_dialog.frameGeometry()
dialog_geometry.moveCenter(main_geometry.center())
self.dispatch_dialog.move(dialog_geometry.topLeft())
# 显示弹窗
self.dispatch_dialog.show()
def update_background(self):
"""更新主界面背景图片"""
if self.background_image and not self.background_image.isNull():
palette = self.palette()
# 按当前窗口尺寸缩放图片
scaled_image = self.background_image.scaled(
self.size(),
Qt.IgnoreAspectRatio,
Qt.SmoothTransformation
)
palette.setBrush(QPalette.Window, QBrush(scaled_image))
self.setPalette(palette)
self.setAutoFillBackground(True)
def resizeEvent(self, e):
"""窗口大小变化时的回调"""
super().resizeEvent(e)
self.update_background() # 重新加载背景图片
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape: # 按下Esc键, 退出界面
self.close()
super().keyPressEvent(event)
if __name__ == "__main__":
import sys
app = QApplication([])
window = MainWindow()
window.show() # 显示主界面
# window.showFullScreen() # 全屏显示主界面
sys.exit(app.exec())