from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QGridLayout, QPushButton, QSizePolicy) from PySide6.QtGui import QFontDatabase from PySide6.QtCore import Signal import os from info_core.defines import * from info_core.MyQtClass import ConfigComboBoxGroup, FolderImportWidget, ImageAnalysisWidget class ReportGeneratorUI(QMainWindow): send_baogao_choose_info = Signal(list[str]) def __init__(self): super().__init__() # 加载字体 self.load_font() # 设置窗口属性 self.setWindowTitle("报告生成器") self.setMinimumSize(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT) # 主窗口部件 self.central_widget = QWidget() self.setCentralWidget(self.central_widget) # 主布局 self.main_layout = QGridLayout(self.central_widget) self.main_layout.setSpacing(MAIN_LAYOUT_SPACING) self.main_layout.setContentsMargins(*MAIN_LAYOUT_MARGINS) # 初始化UI self.init_ui() def load_font(self): """加载自定义字体""" if os.path.exists(FONT_PATH): font_id = QFontDatabase.addApplicationFont(FONT_PATH) if font_id == -1: print("字体加载失败,将使用系统默认字体") else: print(f"字体文件未找到: {FONT_PATH},将使用系统默认字体") def init_ui(self): """初始化所有UI组件""" # 第一行:项目信息和人员配置 self.project_group = ConfigComboBoxGroup("项目基本信息") self.staff_group = ConfigComboBoxGroup("单次检查配置信息", is_project=False) self.main_layout.addWidget(self.project_group, 0, 0) self.main_layout.addWidget(self.staff_group, 0, 1) # 第二行:导入图片路径、填写机组信息 self.picture_group = FolderImportWidget("导入图片路径") self.main_layout.addWidget(self.picture_group, 1, 0) self.image_analysis = ImageAnalysisWidget("填写机组信息") self.main_layout.addWidget(self.image_analysis, 1, 1) # 连接信号 self.picture_group.main_folder_selected.connect(self.image_analysis.set_image_folder) self.image_analysis.generate_path_selected.connect(self.on_generate_path_selected) # 获取请求信号,调用获取函数,发送更新信号 self.picture_group.get_baogao_choose_info.connect(self.get_baogao_choose_info) self.send_baogao_choose_info.connect(self.picture_group.update_baogao_choose_info) # 第三行:生成报告按钮(跨两列) self.create_generate_button() self.generate_btn.setEnabled(False) self.main_layout.addWidget(self.generate_btn, 2, 0, 1, 2) # 设置列和行的拉伸比例 self.main_layout.setColumnStretch(0, 1) # 第一列拉伸比例 self.main_layout.setColumnStretch(1, 1) # 第二列拉伸比例 self.main_layout.setRowStretch(0, 1) # 第一行拉伸比例为1 self.main_layout.setRowStretch(1, 4) # 第二行拉伸比例为4 self.main_layout.setRowStretch(2, 0) # 第三行不拉伸(固定高度) def on_generate_path_selected(self, path): self.generate_btn.setEnabled(True) def get_baogao_choose_info(self): search_file_list = [] if self.image_analysis.check_is_waibu: search_file_list.append("外汇总") if self.image_analysis.check_is_neibu: search_file_list.append("内汇总") if self.image_analysis.check_is_fanglei: search_file_list.append("防汇总") self.send_baogao_choose_info.emit(search_file_list) def create_button(self, text): """创建统一风格的按钮""" btn = QPushButton(text) btn.setStyleSheet(BUTTON_STYLE) btn.setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT) return btn def create_generate_button(self): """创建生成报告按钮""" self.generate_btn = QPushButton("生成报告") self.generate_btn.setStyleSheet(PRIMARY_BUTTON_STYLE) self.generate_btn.setFixedHeight(50) self.generate_btn.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) if __name__ == "__main__": app = QApplication([]) window = ReportGeneratorUI() window.show() app.exec()