fix:实现配置功能,实现园长一键签名功能

This commit is contained in:
2025-12-19 12:23:00 +08:00
parent 0e47603d23
commit 14b8c19dfe
19 changed files with 307 additions and 107 deletions

View File

@@ -12,7 +12,7 @@ import traceback
import comtypes.client
from config.config import load_config
from utils.agent_utils import generate_comment
from utils.file_utils import check_file_exists
from utils.file_utils import check_file_exists, get_output_pptx_files
from utils.image_utils import find_image_path
from utils.zodiac_utils import calculate_zodiac
from utils.growt_utils import (
@@ -22,6 +22,7 @@ from utils.growt_utils import (
replace_four_page,
replace_five_page,
)
from utils.pptx_utils import replace_picture
# 如果你之前没有全局定义 console这里定义一个
console = Console()
@@ -331,7 +332,7 @@ def generate_report(stop_event: threading.Event = None, progress_callback=None):
# ==========================================
# 5. 转换格式(根据names.xlsx文件生成PPT转PDF)
# 4. 转换格式(根据names.xlsx文件生成PPT转PDF)
# ==========================================
def batch_convert_folder(folder_path, stop_event: threading.Event = None, progress_callback=None):
"""
@@ -496,3 +497,49 @@ def generate_zodiac(stop_event: threading.Event = None, progress_callback=None):
except Exception as e:
logger.error(f"程序运行出错: {str(e)}")
logger.error(traceback.format_exc())
# ==========================================
# 6. 一键生成园长签名(根据输出文件夹生成签名)
# ==========================================
def generate_signature(progress_callback=None) -> str:
"""
生成园长签名
"""
try:
# 获取所有的PPT (此时返回的是文件名或路径的列表)
pptx_files = get_output_pptx_files(config["output_folder"])
if not pptx_files:
logger.warning("没有找到 PPT 文件")
return "未找到文件"
logger.info(f"开始生成签名,共 {len(pptx_files)} 个 PPT 文件...")
img_path = config.get("signature_image") # 签名图片路径
if not img_path or not os.path.exists(img_path):
logger.error(f"签名图片不存在: {img_path}")
logger.warning(f"⚠️ 警告: 缺少签名照片('signature'")
return
logger.info(f"签名图片存在: {img_path}")
for i, filename in enumerate(pptx_files):
# 获取完整绝对路径
pptx_path = os.path.join(config["output_folder"], filename)
# --- 关键修改点 1: 打开 PPT 对象 ---
prs = Presentation(pptx_path)
# --- 关键修改点 2: 传递 prs 对象而不是路径字符串 ---
replace_picture(prs, 1, "signature", img_path)
# --- 关键修改点 3: 保存修改后的 PPT ---
prs.save(pptx_path)
# 更新进度条 (如果有 callback)
if progress_callback:
progress_callback(i + 1, len(pptx_files),f"[{i + 1}/{len(pptx_files)}] 生成签名完成: {filename}")
logger.success(f"[{i + 1}/{len(pptx_files)}] 生成签名完成: {filename}")
if progress_callback:
progress_callback(len(pptx_files), len(pptx_files), "签名生成完成")
except Exception as e:
logger.error(f"generate_signature 发生未知错误: {e}")
return str(e)