""" 测试LLMClipboard分类配置管理功能 """ import os import sys import json import logging from PyQt6.QtWidgets import QApplication from PyQt6.QtCore import QTimer # 配置日志记录 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) # 添加项目根目录到Python路径 project_root = os.path.dirname(os.path.abspath(__file__)) if project_root not in sys.path: sys.path.append(project_root) from llmclipboard.document_processor import DocumentProcessor from llmclipboard.category_manager import CategoryManagerDialog from llmclipboard.gui import MainWindow def test_category_manager_dialog(): """测试分类管理器对话框""" logger.info("开始测试分类管理器对话框") # 创建应用程序实例 app = QApplication(sys.argv) # 确定配置文件路径 if getattr(sys, 'frozen', False): # 打包环境 - 使用可执行文件所在目录 config_dir = os.path.dirname(sys.executable) else: # 开发环境 - 使用项目根目录 config_dir = project_root categories_file = os.path.join(config_dir, 'categories.json') logger.info(f"分类配置文件路径: {categories_file}") # 加载当前分类 if os.path.exists(categories_file): logger.info(f"分类配置文件已存在: {categories_file}") with open(categories_file, 'r', encoding='utf-8') as f: categories = json.load(f) logger.info(f"当前分类: {categories}") else: logger.info(f"分类配置文件不存在: {categories_file}") categories = {} # 创建分类管理器对话框 dialog = CategoryManagerDialog(categories) # 连接信号 def on_categories_updated(new_categories): logger.info(f"分类已更新: {new_categories}") # 保存到文件 with open(categories_file, 'w', encoding='utf-8') as f: json.dump(new_categories, f, ensure_ascii=False, indent=2) logger.info(f"分类已保存到文件: {categories_file}") dialog.categories_updated.connect(on_categories_updated) # 显示对话框 dialog.show() # 5秒后自动关闭 QTimer.singleShot(60000, dialog.close) # 运行应用程序 sys.exit(app.exec()) def test_main_window_category_management(): """测试主窗口的分类管理功能""" logger.info("开始测试主窗口的分类管理功能") # 创建应用程序实例 app = QApplication(sys.argv) # 创建主窗口 window = MainWindow() # 显示窗口 window.show() # 运行应用程序 sys.exit(app.exec()) if __name__ == "__main__": # 选择要运行的测试 test_category_manager_dialog() # test_main_window_category_management()