742 lines
32 KiB
Python
742 lines
32 KiB
Python
|
|
from PySide6.QtWidgets import (
|
|||
|
|
QMainWindow, QWidget, QLabel, QGridLayout, QVBoxLayout, QHBoxLayout,
|
|||
|
|
QTableWidget, QTableWidgetItem, QHeaderView, QFrame, QSplitter,
|
|||
|
|
QPushButton, QLineEdit, QAbstractItemView
|
|||
|
|
)
|
|||
|
|
from PySide6.QtGui import QFont, QAction, QBrush, QColor
|
|||
|
|
from PySide6.QtCore import Qt
|
|||
|
|
|
|||
|
|
class MainWindowUI(QMainWindow):
|
|||
|
|
def __init__(self):
|
|||
|
|
super().__init__()
|
|||
|
|
self.setWindowTitle("腾智微丝产线包装系统")
|
|||
|
|
self.resize(1200, 800)
|
|||
|
|
self.init_ui()
|
|||
|
|
|
|||
|
|
def init_ui(self):
|
|||
|
|
# 设置字体
|
|||
|
|
self.title_font = QFont("微软雅黑", 16, QFont.Bold)
|
|||
|
|
self.second_title_font = QFont("微软雅黑", 14, QFont.Bold)
|
|||
|
|
self.normal_font = QFont("微软雅黑", 12)
|
|||
|
|
self.small_font = QFont("微软雅黑", 9)
|
|||
|
|
|
|||
|
|
# 创建菜单栏
|
|||
|
|
self.create_menu()
|
|||
|
|
|
|||
|
|
# 创建中央部件
|
|||
|
|
self.central_widget = QWidget()
|
|||
|
|
self.setCentralWidget(self.central_widget)
|
|||
|
|
|
|||
|
|
# 创建主布局 - 水平分割
|
|||
|
|
self.main_layout = QHBoxLayout(self.central_widget)
|
|||
|
|
self.main_layout.setContentsMargins(5, 5, 5, 5)
|
|||
|
|
self.main_layout.setSpacing(5)
|
|||
|
|
|
|||
|
|
# 创建左侧面板
|
|||
|
|
self.left_panel = QWidget()
|
|||
|
|
self.left_layout = QVBoxLayout(self.left_panel)
|
|||
|
|
self.left_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.left_layout.setSpacing(5)
|
|||
|
|
self.create_left_panel()
|
|||
|
|
|
|||
|
|
# 创建右侧面板
|
|||
|
|
self.right_panel = QWidget()
|
|||
|
|
self.right_layout = QVBoxLayout(self.right_panel)
|
|||
|
|
self.right_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.right_layout.setSpacing(5)
|
|||
|
|
self.create_right_panel()
|
|||
|
|
|
|||
|
|
# 添加左右面板到主布局
|
|||
|
|
self.main_layout.addWidget(self.left_panel, 1) # 左侧面板占比较小
|
|||
|
|
self.main_layout.addWidget(self.right_panel, 2) # 右侧面板占比较大
|
|||
|
|
|
|||
|
|
def create_menu(self):
|
|||
|
|
# 创建菜单栏
|
|||
|
|
self.menubar = self.menuBar()
|
|||
|
|
|
|||
|
|
# 用户操作菜单
|
|||
|
|
self.user_menu = self.menubar.addMenu("用户操作页")
|
|||
|
|
self.main_action = QAction("主页面", self)
|
|||
|
|
self.user_menu.addAction(self.main_action)
|
|||
|
|
|
|||
|
|
# 系统设置菜单
|
|||
|
|
self.system_menu = self.menubar.addMenu("系统设置")
|
|||
|
|
self.settings_action = QAction("设置页面", self)
|
|||
|
|
self.system_menu.addAction(self.settings_action)
|
|||
|
|
|
|||
|
|
def create_left_panel(self):
|
|||
|
|
# 标题
|
|||
|
|
self.title_label = QLabel("腾智微丝产线包装系统")
|
|||
|
|
self.title_label.setFont(self.title_font)
|
|||
|
|
self.title_label.setAlignment(Qt.AlignCenter)
|
|||
|
|
self.title_label.setStyleSheet("color: #1a237e; padding: 10px; background-color: #f5f5f5; border-radius: 4px;")
|
|||
|
|
self.left_layout.addWidget(self.title_label)
|
|||
|
|
|
|||
|
|
# 项目信息表格 - 使用QFrame包裹,添加边框
|
|||
|
|
self.project_frame = QFrame()
|
|||
|
|
self.project_frame.setFrameShape(QFrame.StyledPanel)
|
|||
|
|
self.project_frame.setLineWidth(1)
|
|||
|
|
self.project_frame.setFixedHeight(150) # 调整这个值可以控制整体高度
|
|||
|
|
self.project_layout = QVBoxLayout(self.project_frame)
|
|||
|
|
self.project_layout.setContentsMargins(5, 5, 5, 5)
|
|||
|
|
|
|||
|
|
# 项目表格
|
|||
|
|
self.project_table = QTableWidget(4, 5)
|
|||
|
|
self.project_table.setHorizontalHeaderLabels(["项目", "用电", "数量", "产量", "开机率"])
|
|||
|
|
self.project_table.setVerticalHeaderLabels(["当日", "当月", "当年", "累计"])
|
|||
|
|
self.project_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|||
|
|
self.project_table.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|||
|
|
self.project_table.setEditTriggers(QTableWidget.NoEditTriggers) # 设置为不可编辑
|
|||
|
|
|
|||
|
|
# 设置表格样式
|
|||
|
|
self.project_table.setStyleSheet("""
|
|||
|
|
QTableWidget {
|
|||
|
|
border: none;
|
|||
|
|
gridline-color: #dddddd;
|
|||
|
|
}
|
|||
|
|
QHeaderView::section {
|
|||
|
|
background-color: #f0f0f0;
|
|||
|
|
padding: 4px;
|
|||
|
|
border: 1px solid #cccccc;
|
|||
|
|
font-weight: bold;
|
|||
|
|
}
|
|||
|
|
""")
|
|||
|
|
|
|||
|
|
self.project_layout.addWidget(self.project_table)
|
|||
|
|
|
|||
|
|
self.left_layout.addWidget(self.project_frame)
|
|||
|
|
|
|||
|
|
# 任务信息区域 - 使用QFrame包裹,添加边框
|
|||
|
|
self.task_frame = QFrame()
|
|||
|
|
self.task_frame.setFrameShape(QFrame.StyledPanel)
|
|||
|
|
self.task_frame.setLineWidth(1)
|
|||
|
|
self.task_frame.setFixedHeight(180)
|
|||
|
|
self.task_layout = QVBoxLayout(self.task_frame)
|
|||
|
|
self.task_layout.setContentsMargins(8, 8, 8, 8)
|
|||
|
|
|
|||
|
|
# 任务标签
|
|||
|
|
self.task_label = QLabel("任务")
|
|||
|
|
self.task_label.setFont(self.normal_font)
|
|||
|
|
self.task_label.setAlignment(Qt.AlignLeft)
|
|||
|
|
self.task_label.setStyleSheet("font-weight: bold; color: #333333;")
|
|||
|
|
self.task_layout.addWidget(self.task_label)
|
|||
|
|
|
|||
|
|
# 任务表格 - 使用合并单元格实现一级二级标题
|
|||
|
|
self.task_table = QTableWidget(3, 4) # 3行4列:一级标题行、二级标题行、数据行
|
|||
|
|
self.task_table.setEditTriggers(QTableWidget.NoEditTriggers) # 设置为不可编辑
|
|||
|
|
self.task_table.horizontalHeader().setVisible(False)
|
|||
|
|
self.task_table.verticalHeader().setVisible(False)
|
|||
|
|
self.task_table.setShowGrid(True)
|
|||
|
|
|
|||
|
|
# 设置列宽均等
|
|||
|
|
self.task_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|||
|
|
|
|||
|
|
# 第一行:订单量和完成量 (一级标题)
|
|||
|
|
self.task_table.setSpan(0, 0, 1, 2) # 订单量跨2列
|
|||
|
|
self.task_table.setSpan(0, 2, 1, 2) # 完成量跨2列
|
|||
|
|
|
|||
|
|
order_item = QTableWidgetItem("订单量")
|
|||
|
|
order_item.setTextAlignment(Qt.AlignCenter)
|
|||
|
|
order_item.setFont(self.normal_font)
|
|||
|
|
self.task_table.setItem(0, 0, order_item)
|
|||
|
|
|
|||
|
|
completed_item = QTableWidgetItem("完成量")
|
|||
|
|
completed_item.setTextAlignment(Qt.AlignCenter)
|
|||
|
|
completed_item.setFont(self.normal_font)
|
|||
|
|
self.task_table.setItem(0, 2, completed_item)
|
|||
|
|
|
|||
|
|
# 第二行:二级标题
|
|||
|
|
headers = ["总生产数量", "总生产公斤", "已完成数量", "已完成公斤"]
|
|||
|
|
for col, header in enumerate(headers):
|
|||
|
|
item = QTableWidgetItem(header)
|
|||
|
|
item.setTextAlignment(Qt.AlignCenter)
|
|||
|
|
item.setFont(self.small_font)
|
|||
|
|
self.task_table.setItem(1, col, item)
|
|||
|
|
|
|||
|
|
|
|||
|
|
# 设置行高
|
|||
|
|
self.task_table.setRowHeight(0, 30) # 一级标题行高
|
|||
|
|
self.task_table.setRowHeight(1, 30) # 二级标题行高
|
|||
|
|
self.task_table.setRowHeight(2, 30) # 数据行高
|
|||
|
|
self.task_layout.addWidget(self.task_table)
|
|||
|
|
|
|||
|
|
# 订单行
|
|||
|
|
self.order_layout = QHBoxLayout()
|
|||
|
|
self.order_label = QLabel("订单")
|
|||
|
|
self.order_label.setFont(QFont("微软雅黑", 12, QFont.Bold))
|
|||
|
|
self.order_label.setFixedHeight(30)
|
|||
|
|
self.order_label.setStyleSheet("padding: 0 5px; color: #333333;")
|
|||
|
|
|
|||
|
|
self.order_edit = QLineEdit()
|
|||
|
|
self.order_edit.setReadOnly(True)
|
|||
|
|
self.order_edit.setFont(QFont("微软雅黑", 12))
|
|||
|
|
self.order_edit.setText("ORD-2025-001") # 设置默认订单号
|
|||
|
|
self.order_edit.setStyleSheet("background-color: #f9f9f9; border: 1px solid #cccccc; border-radius: 3px; padding: 2px 5px;")
|
|||
|
|
|
|||
|
|
self.order_layout.addWidget(self.order_label)
|
|||
|
|
self.order_layout.addWidget(self.order_edit)
|
|||
|
|
self.task_layout.addLayout(self.order_layout)
|
|||
|
|
|
|||
|
|
self.left_layout.addWidget(self.task_frame)
|
|||
|
|
|
|||
|
|
# 上料区 - 使用QFrame包裹,添加边框
|
|||
|
|
self.material_frame = QFrame()
|
|||
|
|
self.material_frame.setFrameShape(QFrame.StyledPanel)
|
|||
|
|
self.material_frame.setLineWidth(1)
|
|||
|
|
self.material_frame.setFixedHeight(300) # 增加高度以匹配图片
|
|||
|
|
self.material_frame.setStyleSheet("QFrame { background-color: #f8f8f8; }")
|
|||
|
|
self.material_layout = QHBoxLayout(self.material_frame)
|
|||
|
|
self.material_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.material_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 上料区标签
|
|||
|
|
self.material_label = QLabel("上料区")
|
|||
|
|
self.material_label.setFont(self.normal_font)
|
|||
|
|
self.material_label.setAlignment(Qt.AlignCenter)
|
|||
|
|
self.material_label.setFixedWidth(100) # 设置固定宽度
|
|||
|
|
self.material_label.setStyleSheet("background-color: #e0e0e0; border-right: 1px solid #cccccc; font-weight: bold;")
|
|||
|
|
self.material_layout.addWidget(self.material_label)
|
|||
|
|
|
|||
|
|
# 上料区内容 - 这里可以添加更多控件
|
|||
|
|
self.material_content = QWidget()
|
|||
|
|
self.material_content.setStyleSheet("background-color: black;") # 黑色背景适合显示相机画面
|
|||
|
|
self.material_content_layout = QVBoxLayout(self.material_content)
|
|||
|
|
self.material_content_layout.setContentsMargins(0, 0, 0, 0) # 移除内边距以便相机画面填满
|
|||
|
|
self.material_layout.addWidget(self.material_content)
|
|||
|
|
|
|||
|
|
self.left_layout.addWidget(self.material_frame)
|
|||
|
|
|
|||
|
|
# 托盘号行 - 使用QFrame包裹,添加边框
|
|||
|
|
self.tray_frame = QFrame()
|
|||
|
|
self.tray_frame.setFrameShape(QFrame.StyledPanel)
|
|||
|
|
self.tray_frame.setLineWidth(1)
|
|||
|
|
self.tray_layout = QHBoxLayout(self.tray_frame)
|
|||
|
|
self.tray_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.tray_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
self.tray_label = QLabel("托盘号")
|
|||
|
|
self.tray_label.setFont(self.normal_font)
|
|||
|
|
self.tray_label.setAlignment(Qt.AlignCenter)
|
|||
|
|
self.tray_label.setFixedWidth(100) # 设置固定宽度
|
|||
|
|
self.tray_label.setStyleSheet("background-color: #e0e0e0; border-right: 1px solid #cccccc; font-weight: bold;")
|
|||
|
|
self.tray_layout.addWidget(self.tray_label)
|
|||
|
|
|
|||
|
|
self.tray_edit = QLineEdit()
|
|||
|
|
self.tray_edit.setReadOnly(True)
|
|||
|
|
self.tray_edit.setStyleSheet("border: none; padding: 5px 10px;")
|
|||
|
|
self.tray_edit.setFont(QFont("微软雅黑", 12))
|
|||
|
|
self.tray_layout.addWidget(self.tray_edit)
|
|||
|
|
|
|||
|
|
self.left_layout.addWidget(self.tray_frame)
|
|||
|
|
|
|||
|
|
# 下料区 - 使用QFrame包裹,添加边框
|
|||
|
|
self.output_frame = QFrame()
|
|||
|
|
self.output_frame.setFrameShape(QFrame.StyledPanel)
|
|||
|
|
self.output_frame.setLineWidth(1)
|
|||
|
|
self.output_frame.setFixedHeight(200) # 增加高度以匹配图片
|
|||
|
|
self.output_frame.setStyleSheet("QFrame { background-color: #f8f8f8; }")
|
|||
|
|
self.output_layout = QHBoxLayout(self.output_frame)
|
|||
|
|
self.output_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.output_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 下料区标签
|
|||
|
|
self.output_label = QLabel("下料")
|
|||
|
|
self.output_label.setFont(self.normal_font)
|
|||
|
|
self.output_label.setAlignment(Qt.AlignCenter)
|
|||
|
|
self.output_label.setFixedWidth(100) # 设置固定宽度
|
|||
|
|
self.output_label.setStyleSheet("background-color: #e0e0e0; border-right: 1px solid #cccccc; font-weight: bold;")
|
|||
|
|
self.output_layout.addWidget(self.output_label)
|
|||
|
|
|
|||
|
|
# 下料区内容 - 这里可以添加更多控件
|
|||
|
|
self.output_content = QWidget()
|
|||
|
|
self.output_content.setStyleSheet("background-color: white;")
|
|||
|
|
self.output_content_layout = QVBoxLayout(self.output_content)
|
|||
|
|
self.output_content_layout.setContentsMargins(10, 10, 10, 10)
|
|||
|
|
self.output_layout.addWidget(self.output_content)
|
|||
|
|
|
|||
|
|
self.left_layout.addWidget(self.output_frame)
|
|||
|
|
|
|||
|
|
# 产线控制区 - 使用QFrame包裹,添加边框
|
|||
|
|
self.control_frame = QFrame()
|
|||
|
|
self.control_frame.setFrameShape(QFrame.StyledPanel)
|
|||
|
|
self.control_frame.setLineWidth(1)
|
|||
|
|
self.control_layout = QHBoxLayout(self.control_frame)
|
|||
|
|
self.control_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.control_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
self.control_label = QLabel("产线")
|
|||
|
|
self.control_label.setFont(self.normal_font)
|
|||
|
|
self.control_label.setAlignment(Qt.AlignCenter)
|
|||
|
|
self.control_label.setFixedWidth(100) # 设置固定宽度
|
|||
|
|
self.control_label.setStyleSheet("background-color: #e0e0e0; border-right: 1px solid #cccccc; font-weight: bold;")
|
|||
|
|
self.control_layout.addWidget(self.control_label)
|
|||
|
|
|
|||
|
|
# 按钮容器
|
|||
|
|
self.button_container = QWidget()
|
|||
|
|
self.button_layout = QGridLayout(self.button_container)
|
|||
|
|
self.button_layout.setContentsMargins(10, 10, 10, 10)
|
|||
|
|
self.button_layout.setSpacing(10) # 增加按钮间距
|
|||
|
|
|
|||
|
|
# 创建按钮并设置样式
|
|||
|
|
button_style = """
|
|||
|
|
QPushButton {
|
|||
|
|
padding: 8px 16px;
|
|||
|
|
font-weight: bold;
|
|||
|
|
border-radius: 4px;
|
|||
|
|
}
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
self.input_button = QPushButton("上料")
|
|||
|
|
self.input_button.setFont(self.normal_font)
|
|||
|
|
self.input_button.setStyleSheet(button_style + "background-color: #e3f2fd; border: 1px solid #2196f3;")
|
|||
|
|
|
|||
|
|
self.output_button = QPushButton("下料")
|
|||
|
|
self.output_button.setFont(self.normal_font)
|
|||
|
|
self.output_button.setStyleSheet(button_style + "background-color: #fff8e1; border: 1px solid #ffc107;")
|
|||
|
|
|
|||
|
|
self.start_button = QPushButton("开始")
|
|||
|
|
self.start_button.setFont(self.normal_font)
|
|||
|
|
self.start_button.setStyleSheet(button_style + "background-color: #e8f5e9; border: 1px solid #4caf50;")
|
|||
|
|
|
|||
|
|
self.stop_button = QPushButton("暂停")
|
|||
|
|
self.stop_button.setFont(self.normal_font)
|
|||
|
|
self.stop_button.setStyleSheet(button_style + "background-color: #ffebee; border: 1px solid #f44336;")
|
|||
|
|
|
|||
|
|
# 使用网格布局排列按钮
|
|||
|
|
self.button_layout.addWidget(self.input_button, 0, 0)
|
|||
|
|
self.button_layout.addWidget(self.output_button, 0, 1)
|
|||
|
|
self.button_layout.addWidget(self.start_button, 0, 2)
|
|||
|
|
self.button_layout.addWidget(self.stop_button, 0, 3)
|
|||
|
|
|
|||
|
|
self.control_layout.addWidget(self.button_container)
|
|||
|
|
|
|||
|
|
self.left_layout.addWidget(self.control_frame)
|
|||
|
|
|
|||
|
|
# 添加弹性空间,确保控件紧凑排列在顶部
|
|||
|
|
self.left_layout.addStretch()
|
|||
|
|
|
|||
|
|
def create_right_panel(self):
|
|||
|
|
# 创建右侧整体框架
|
|||
|
|
self.right_frame = QFrame()
|
|||
|
|
self.right_frame.setFrameShape(QFrame.NoFrame) # 移除框架边框
|
|||
|
|
self.right_frame.setLineWidth(0)
|
|||
|
|
self.right_layout.addWidget(self.right_frame)
|
|||
|
|
|
|||
|
|
# 右侧整体使用垂直布局,不设置边距
|
|||
|
|
self.right_frame_layout = QVBoxLayout(self.right_frame)
|
|||
|
|
self.right_frame_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.right_frame_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 创建一个垂直分割器,用于控制两个表格的高度比例
|
|||
|
|
self.right_splitter = QSplitter(Qt.Vertical)
|
|||
|
|
|
|||
|
|
# 创建微丝产线表格的容器
|
|||
|
|
self.process_container = QWidget()
|
|||
|
|
self.process_container_layout = QVBoxLayout(self.process_container)
|
|||
|
|
self.process_container_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.process_container_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 创建包装记录表格的容器
|
|||
|
|
self.record_container = QWidget()
|
|||
|
|
self.record_container_layout = QVBoxLayout(self.record_container)
|
|||
|
|
self.record_container_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.record_container_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 创建微丝产线表格
|
|||
|
|
self.create_process_table()
|
|||
|
|
self.process_container_layout.addWidget(self.process_frame)
|
|||
|
|
|
|||
|
|
# 创建包装记录表格
|
|||
|
|
self.create_record_table()
|
|||
|
|
self.record_container_layout.addWidget(self.record_frame)
|
|||
|
|
|
|||
|
|
# 将两个容器添加到分割器中
|
|||
|
|
self.right_splitter.addWidget(self.process_container)
|
|||
|
|
self.right_splitter.addWidget(self.record_container)
|
|||
|
|
|
|||
|
|
# 设置初始大小比例:微丝产线占1/3,包装记录占2/3
|
|||
|
|
self.right_splitter.setSizes([100, 200]) # 比例为1:2
|
|||
|
|
|
|||
|
|
# 将分割器添加到右侧布局
|
|||
|
|
self.right_frame_layout.addWidget(self.right_splitter)
|
|||
|
|
|
|||
|
|
# 添加一个通用的表格样式设置方法
|
|||
|
|
def setup_table_common(self, table, hide_headers=True):
|
|||
|
|
"""设置表格的通用样式和属性
|
|||
|
|
|
|||
|
|
Args:
|
|||
|
|
table: 要设置的QTableWidget对象
|
|||
|
|
hide_headers: 是否隐藏默认的表头
|
|||
|
|
"""
|
|||
|
|
# 设置为不可编辑
|
|||
|
|
table.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
|||
|
|
|
|||
|
|
# 隐藏默认表头
|
|||
|
|
if hide_headers:
|
|||
|
|
table.horizontalHeader().setVisible(False)
|
|||
|
|
table.verticalHeader().setVisible(False)
|
|||
|
|
|
|||
|
|
# 显示网格线
|
|||
|
|
table.setShowGrid(True)
|
|||
|
|
|
|||
|
|
# 移除外边框
|
|||
|
|
table.setFrameShape(QFrame.NoFrame)
|
|||
|
|
|
|||
|
|
# 设置表格样式
|
|||
|
|
table.setStyleSheet("""
|
|||
|
|
QTableWidget {
|
|||
|
|
gridline-color: #dddddd;
|
|||
|
|
border: none;
|
|||
|
|
background-color: white;
|
|||
|
|
}
|
|||
|
|
QTableWidget::item {
|
|||
|
|
border: none;
|
|||
|
|
padding: 3px;
|
|||
|
|
}
|
|||
|
|
QTableWidget::item:selected {
|
|||
|
|
background-color: #e0e0ff;
|
|||
|
|
color: black;
|
|||
|
|
}
|
|||
|
|
""")
|
|||
|
|
|
|||
|
|
# 允许用户调整列宽
|
|||
|
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive)
|
|||
|
|
table.horizontalHeader().setStretchLastSection(True)
|
|||
|
|
|
|||
|
|
return table
|
|||
|
|
|
|||
|
|
# 添加一个通用的表头项创建方法
|
|||
|
|
def create_header_item(self, text, font=None, alignment=Qt.AlignCenter, bg_color="#f8f8f8"):
|
|||
|
|
"""创建表头单元格项
|
|||
|
|
|
|||
|
|
Args:
|
|||
|
|
text: 表头文本
|
|||
|
|
font: 字体,默认为None(使用self.normal_font)
|
|||
|
|
alignment: 对齐方式
|
|||
|
|
bg_color: 背景色
|
|||
|
|
|
|||
|
|
Returns:
|
|||
|
|
QTableWidgetItem: 创建的表头项
|
|||
|
|
"""
|
|||
|
|
item = QTableWidgetItem(text)
|
|||
|
|
item.setTextAlignment(alignment)
|
|||
|
|
item.setFont(font or self.normal_font)
|
|||
|
|
item.setBackground(QBrush(QColor(bg_color)))
|
|||
|
|
return item
|
|||
|
|
|
|||
|
|
def create_process_table(self):
|
|||
|
|
"""创建微丝产线表格,包含上料、检验、包装部分"""
|
|||
|
|
# 创建微丝产线框架
|
|||
|
|
self.process_frame = QFrame()
|
|||
|
|
self.process_frame.setFrameShape(QFrame.Box)
|
|||
|
|
self.process_frame.setLineWidth(1)
|
|||
|
|
self.process_frame.setStyleSheet("QFrame { border: 1px solid #dddddd; }")
|
|||
|
|
self.process_layout = QVBoxLayout(self.process_frame)
|
|||
|
|
self.process_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.process_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 微丝产线标题
|
|||
|
|
self.process_title = QLabel("微丝产线")
|
|||
|
|
self.process_title.setFont(self.second_title_font)
|
|||
|
|
self.process_title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|||
|
|
# 调整行高
|
|||
|
|
self.process_title.setFixedHeight(40)
|
|||
|
|
self.process_title.setStyleSheet("background-color: #f8f8f8; padding: 5px; border-bottom: 1px solid #dddddd;")
|
|||
|
|
self.process_layout.addWidget(self.process_title)
|
|||
|
|
|
|||
|
|
|
|||
|
|
# 创建表格内容区域
|
|||
|
|
self.process_content = QWidget()
|
|||
|
|
self.process_content_layout = QVBoxLayout(self.process_content)
|
|||
|
|
self.process_content_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.process_content_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 创建表格 - 支持动态配置检验列数
|
|||
|
|
self.inspection_columns = 3 # 默认3列,可动态配置
|
|||
|
|
# TODO:后续从数据库中读取
|
|||
|
|
self.inspection_headers = ["外观", "线径", "电阻", "硬度", "强度"] # 默认检验标题
|
|||
|
|
total_columns = 2 + self.inspection_columns + 2 # 上料2列 + 检验N列 + 包装2列
|
|||
|
|
|
|||
|
|
self.process_table = QTableWidget(8, total_columns) # 8行:1行标题区域 + 1行列标题 + 6行数据
|
|||
|
|
|
|||
|
|
# 应用通用表格设置
|
|||
|
|
self.setup_table_common(self.process_table)
|
|||
|
|
|
|||
|
|
# 设置行高
|
|||
|
|
self.process_table.setRowHeight(0, 30) # 标题区域行高
|
|||
|
|
self.process_table.setRowHeight(1, 30) # 列标题行高
|
|||
|
|
|
|||
|
|
# 设置数据行的行高
|
|||
|
|
for row in range(2, 8): # 工序行
|
|||
|
|
self.process_table.setRowHeight(row, 35)
|
|||
|
|
|
|||
|
|
# 设置列宽
|
|||
|
|
self.set_process_table_column_widths()
|
|||
|
|
|
|||
|
|
# 创建表头 - 合并单元格
|
|||
|
|
self.create_process_table_headers()
|
|||
|
|
|
|||
|
|
# 填充表格内容
|
|||
|
|
self.fill_process_table_cells()
|
|||
|
|
|
|||
|
|
# 添加表格到布局
|
|||
|
|
self.process_content_layout.addWidget(self.process_table)
|
|||
|
|
self.process_layout.addWidget(self.process_content)
|
|||
|
|
|
|||
|
|
def create_record_table(self):
|
|||
|
|
"""创建包装记录表格"""
|
|||
|
|
# 创建包装记录框架
|
|||
|
|
self.record_frame = QFrame()
|
|||
|
|
self.record_frame.setFrameShape(QFrame.Box)
|
|||
|
|
self.record_frame.setLineWidth(1)
|
|||
|
|
self.record_frame.setStyleSheet("QFrame { border: 1px solid #dddddd; }") # 移除 border-top: none;
|
|||
|
|
self.record_layout = QVBoxLayout(self.record_frame)
|
|||
|
|
self.record_layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
|
self.record_layout.setSpacing(0)
|
|||
|
|
|
|||
|
|
# 包装记录标题
|
|||
|
|
self.record_title = QLabel("包装记录")
|
|||
|
|
self.record_title.setFont(self.second_title_font)
|
|||
|
|
self.record_title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|||
|
|
# 调整行高
|
|||
|
|
self.record_title.setFixedHeight(40)
|
|||
|
|
self.record_title.setStyleSheet("background-color: #f8f8f8; padding: 5px; border-bottom: 1px solid #dddddd;")
|
|||
|
|
self.record_layout.addWidget(self.record_title)
|
|||
|
|
|
|||
|
|
# 创建表格
|
|||
|
|
self.record_table = QTableWidget(14, 7) # 14行7列:序号、订单、材质、规格、托号、轴包装号、重量
|
|||
|
|
|
|||
|
|
# 应用通用表格设置
|
|||
|
|
self.setup_table_common(self.record_table)
|
|||
|
|
|
|||
|
|
# 设置列标题
|
|||
|
|
record_headers = ["序号", "订单", "材质", "规格", "托号", "轴包装号", "重量"]
|
|||
|
|
for col, header in enumerate(record_headers):
|
|||
|
|
self.record_table.setItem(0, col, self.create_header_item(header))
|
|||
|
|
|
|||
|
|
# 设置行高
|
|||
|
|
self.record_table.setRowHeight(0, 35) # 列标题行高
|
|||
|
|
self.record_table.setRowHeight(13, 35) # 合计行高
|
|||
|
|
|
|||
|
|
# 设置数据行的行高
|
|||
|
|
for row in range(1, 13): # 记录行
|
|||
|
|
self.record_table.setRowHeight(row, 35)
|
|||
|
|
|
|||
|
|
# 设置列宽
|
|||
|
|
column_widths = [70, 220, 170, 170, 170, 170, 170] # 各列的默认宽度
|
|||
|
|
for col, width in enumerate(column_widths):
|
|||
|
|
self.record_table.setColumnWidth(col, width)
|
|||
|
|
|
|||
|
|
# 添加表格到布局
|
|||
|
|
self.record_layout.addWidget(self.record_table)
|
|||
|
|
|
|||
|
|
# 填充表格内容
|
|||
|
|
self.fill_record_table_cells()
|
|||
|
|
|
|||
|
|
# 添加一个通用的单元格创建方法
|
|||
|
|
def create_cell_item(self, text, alignment=Qt.AlignCenter):
|
|||
|
|
"""创建表格单元格项
|
|||
|
|
|
|||
|
|
Args:
|
|||
|
|
text: 单元格文本
|
|||
|
|
alignment: 对齐方式
|
|||
|
|
|
|||
|
|
Returns:
|
|||
|
|
QTableWidgetItem: 创建的单元格项
|
|||
|
|
"""
|
|||
|
|
item = QTableWidgetItem(str(text))
|
|||
|
|
item.setTextAlignment(alignment)
|
|||
|
|
return item
|
|||
|
|
|
|||
|
|
def fill_process_table_cells(self):
|
|||
|
|
"""填充微丝产线表格单元格"""
|
|||
|
|
# 工序工程数据
|
|||
|
|
process_data = ["拉丝", "退火", "检验", "包装", "入库", "出库"]
|
|||
|
|
|
|||
|
|
# 填充工序数据
|
|||
|
|
for row in range(6):
|
|||
|
|
# 设置序号
|
|||
|
|
self.process_table.setItem(row + 2, 0, self.create_cell_item(row + 1))
|
|||
|
|
|
|||
|
|
# 设置工序工程名称
|
|||
|
|
self.process_table.setItem(row + 2, 1, self.create_cell_item(process_data[row]))
|
|||
|
|
|
|||
|
|
# 只为前3行设置数据
|
|||
|
|
if row < 3:
|
|||
|
|
# 检验区域 - 动态列
|
|||
|
|
inspection_data = ["合格", f"{0.5 + row * 0.1:.1f}", f"{10 + row * 5}", f"{80 + row * 5}", f"{90 + row * 2}"]
|
|||
|
|
for i in range(min(self.inspection_columns, len(inspection_data))):
|
|||
|
|
self.process_table.setItem(row + 2, 2 + i, self.create_cell_item(inspection_data[i]))
|
|||
|
|
|
|||
|
|
# 包装区域 - 贴标和称重
|
|||
|
|
packaging_start_col = 2 + self.inspection_columns
|
|||
|
|
|
|||
|
|
self.process_table.setItem(row + 2, packaging_start_col, self.create_cell_item("已完成"))
|
|||
|
|
self.process_table.setItem(row + 2, packaging_start_col + 1, self.create_cell_item(f"{50 + row * 10}"))
|
|||
|
|
|
|||
|
|
def fill_record_table_cells(self):
|
|||
|
|
"""填充包装记录表格单元格"""
|
|||
|
|
# 填充序号列
|
|||
|
|
for row in range(12):
|
|||
|
|
self.record_table.setItem(row + 1, 0, self.create_cell_item(row + 1))
|
|||
|
|
|
|||
|
|
# 填充示例数据
|
|||
|
|
record_data = [
|
|||
|
|
["ORD-2025-001", "不锈钢", "0.5mm", "T001", "A001", "50kg"],
|
|||
|
|
["ORD-2025-001", "不锈钢", "0.6mm", "T001", "A002", "55kg"],
|
|||
|
|
["ORD-2025-001", "不锈钢", "0.7mm", "T001", "A003", "60kg"],
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
# 只填充前3行
|
|||
|
|
for row in range(3):
|
|||
|
|
for col, value in enumerate(record_data[row]):
|
|||
|
|
self.record_table.setItem(row + 1, col + 1, self.create_cell_item(value))
|
|||
|
|
|
|||
|
|
# 设置合计行
|
|||
|
|
self.record_table.setItem(13, 0, self.create_header_item("合计"))
|
|||
|
|
|
|||
|
|
# 轴数
|
|||
|
|
self.record_table.setItem(13, 3, self.create_header_item("轴数"))
|
|||
|
|
self.record_table.setItem(13, 4, self.create_cell_item("0"))
|
|||
|
|
|
|||
|
|
# 重量
|
|||
|
|
self.record_table.setItem(13, 5, self.create_header_item("重量"))
|
|||
|
|
self.record_table.setItem(13, 6, self.create_cell_item("0.0"))
|
|||
|
|
|
|||
|
|
def set_inspection_columns(self, columns, headers=None):
|
|||
|
|
"""设置检验列数和标题
|
|||
|
|
|
|||
|
|
Args:
|
|||
|
|
columns: 检验列数量
|
|||
|
|
headers: 检验列标题列表,如果为None则使用默认标题
|
|||
|
|
"""
|
|||
|
|
# 保存旧的列数
|
|||
|
|
old_column_count = self.process_table.columnCount()
|
|||
|
|
|
|||
|
|
# 清除表头行的所有项目
|
|||
|
|
if old_column_count > 0:
|
|||
|
|
for c_idx in range(old_column_count):
|
|||
|
|
# 第0行 - 主标题
|
|||
|
|
item_r0 = self.process_table.takeItem(0, c_idx)
|
|||
|
|
if item_r0:
|
|||
|
|
del item_r0
|
|||
|
|
# 第1行 - 子标题
|
|||
|
|
item_r1 = self.process_table.takeItem(1, c_idx)
|
|||
|
|
if item_r1:
|
|||
|
|
del item_r1
|
|||
|
|
|
|||
|
|
# 更新检验列数
|
|||
|
|
self.inspection_columns = columns
|
|||
|
|
|
|||
|
|
# 更新检验标题
|
|||
|
|
if headers is not None and len(headers) >= columns:
|
|||
|
|
self.inspection_headers = headers
|
|||
|
|
elif len(self.inspection_headers) < columns:
|
|||
|
|
# 如果当前标题不足,扩展标题列表
|
|||
|
|
current_len = len(self.inspection_headers)
|
|||
|
|
for i in range(current_len, columns):
|
|||
|
|
self.inspection_headers.append(f"检验项{i+1}")
|
|||
|
|
|
|||
|
|
# 计算总列数
|
|||
|
|
total_columns = 2 + self.inspection_columns + 2 # 上料2列 + 检验N列 + 包装2列
|
|||
|
|
self.process_table.setColumnCount(total_columns)
|
|||
|
|
|
|||
|
|
# 重新设置列宽
|
|||
|
|
self.set_process_table_column_widths()
|
|||
|
|
|
|||
|
|
# 重新创建表头
|
|||
|
|
self.create_process_table_headers()
|
|||
|
|
|
|||
|
|
# 重新填充数据
|
|||
|
|
self.fill_process_table_cells()
|
|||
|
|
|
|||
|
|
def create_process_table_headers(self):
|
|||
|
|
"""创建微丝产线表格的表头,实现合并单元格"""
|
|||
|
|
# 第一行:上料、检验、包装标题区域
|
|||
|
|
|
|||
|
|
# 上料区域(2列)
|
|||
|
|
self.process_table.setSpan(0, 0, 1, 2)
|
|||
|
|
self.process_table.setItem(0, 0, self.create_header_item("上料"))
|
|||
|
|
|
|||
|
|
# 检验区域(动态列数)
|
|||
|
|
self.process_table.setSpan(0, 2, 1, self.inspection_columns)
|
|||
|
|
self.process_table.setItem(0, 2, self.create_header_item("检验"))
|
|||
|
|
|
|||
|
|
# 包装区域(2列)
|
|||
|
|
packaging_start_col = 2 + self.inspection_columns
|
|||
|
|
self.process_table.setSpan(0, packaging_start_col, 1, 2)
|
|||
|
|
self.process_table.setItem(0, packaging_start_col, self.create_header_item("包装"))
|
|||
|
|
|
|||
|
|
# 第二行:列标题
|
|||
|
|
# 上料区域列标题
|
|||
|
|
material_headers = ["序号", "工序工程"]
|
|||
|
|
for col, header in enumerate(material_headers):
|
|||
|
|
self.process_table.setItem(1, col, self.create_header_item(header))
|
|||
|
|
|
|||
|
|
# 检验区域列标题 - 可动态配置
|
|||
|
|
for i in range(self.inspection_columns):
|
|||
|
|
header_text = ""
|
|||
|
|
if i < len(self.inspection_headers):
|
|||
|
|
header_text = self.inspection_headers[i]
|
|||
|
|
else:
|
|||
|
|
header_text = f"检验项{i+1}" # 如果没有定义足够的标题,使用默认标题
|
|||
|
|
|
|||
|
|
self.process_table.setItem(1, 2 + i, self.create_header_item(header_text))
|
|||
|
|
|
|||
|
|
# 包装区域列标题
|
|||
|
|
packaging_headers = ["贴标", "称重"]
|
|||
|
|
for i, header in enumerate(packaging_headers):
|
|||
|
|
self.process_table.setItem(1, packaging_start_col + i, self.create_header_item(header))
|
|||
|
|
|
|||
|
|
def set_process_table_column_widths(self):
|
|||
|
|
"""设置微丝产线表格的列宽 - 支持动态配置检验列"""
|
|||
|
|
# 上料区域列宽
|
|||
|
|
self.process_table.setColumnWidth(0, 70) # 序号
|
|||
|
|
self.process_table.setColumnWidth(1, 190) # 工序工程
|
|||
|
|
|
|||
|
|
# 检验区域列宽
|
|||
|
|
for i in range(self.inspection_columns):
|
|||
|
|
self.process_table.setColumnWidth(2 + i, 140) # 检验列
|
|||
|
|
|
|||
|
|
# 包装区域列宽
|
|||
|
|
packaging_start_col = 2 + self.inspection_columns
|
|||
|
|
self.process_table.setColumnWidth(packaging_start_col, 140) # 贴标
|
|||
|
|
self.process_table.setColumnWidth(packaging_start_col + 1, 140) # 称重
|
|||
|
|
|
|||
|
|
def create_process_table_headers(self):
|
|||
|
|
"""创建微丝产线表格的表头,实现合并单元格"""
|
|||
|
|
# 第一行:上料、检验、包装标题区域
|
|||
|
|
|
|||
|
|
# 上料区域(2列)
|
|||
|
|
self.process_table.setSpan(0, 0, 1, 2)
|
|||
|
|
self.process_table.setItem(0, 0, self.create_header_item("上料"))
|
|||
|
|
|
|||
|
|
# 检验区域(动态列数)
|
|||
|
|
self.process_table.setSpan(0, 2, 1, self.inspection_columns)
|
|||
|
|
self.process_table.setItem(0, 2, self.create_header_item("检验"))
|
|||
|
|
|
|||
|
|
# 包装区域(2列)
|
|||
|
|
packaging_start_col = 2 + self.inspection_columns
|
|||
|
|
self.process_table.setSpan(0, packaging_start_col, 1, 2)
|
|||
|
|
self.process_table.setItem(0, packaging_start_col, self.create_header_item("包装"))
|
|||
|
|
|
|||
|
|
# 第二行:列标题
|
|||
|
|
# 上料区域列标题
|
|||
|
|
material_headers = ["序号", "工序工程"]
|
|||
|
|
for col, header in enumerate(material_headers):
|
|||
|
|
self.process_table.setItem(1, col, self.create_header_item(header))
|
|||
|
|
|
|||
|
|
# 检验区域列标题 - 可动态配置
|
|||
|
|
for i in range(self.inspection_columns):
|
|||
|
|
header_text = ""
|
|||
|
|
if i < len(self.inspection_headers):
|
|||
|
|
header_text = self.inspection_headers[i]
|
|||
|
|
else:
|
|||
|
|
header_text = f"检验项{i+1}" # 如果没有定义足够的标题,使用默认标题
|
|||
|
|
|
|||
|
|
self.process_table.setItem(1, 2 + i, self.create_header_item(header_text))
|
|||
|
|
|
|||
|
|
# 包装区域列标题
|
|||
|
|
packaging_headers = ["贴标", "称重"]
|
|||
|
|
for i, header in enumerate(packaging_headers):
|
|||
|
|
self.process_table.setItem(1, packaging_start_col + i, self.create_header_item(header))
|