You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
DeepSeek AI助手 - 主程序入口
该文件是DeepSeek AI助手应用程序的入口点负责初始化应用程序的主窗口和核心组件。
应用程序基于Tkinter和customtkinter构建提供AI聊天、日程管理和待办事项管理功能。
"""
# 导入必要的模块
import tkinter as tk # Tkinter GUI库
import sys # 系统模块用于修改Python路径
import os # 操作系统模块,用于路径操作
# 添加项目根目录到Python路径确保可以正确导入其他模块
# 获取当前文件的绝对路径,然后向上两级找到项目根目录
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(project_root)
# 从项目模块中导入核心组件
from ui.chat_ui import DeepSeekChatUI # 主聊天界面类
from chat.deepseek_api import DeepSeekAPI # DeepSeek API客户端类
from logger.logger_manager import LoggerManager # 日志管理器类
# 程序主入口
if __name__ == "__main__":
# 创建Tkinter主窗口对象
root = tk.Tk()
# 设置全局异常处理器
def handle_global_exception(exc_type, exc_value, exc_traceback):
"""处理全局未捕获的异常"""
import traceback
error_msg = f"全局未捕获异常: {exc_type.__name__}: {exc_value}\n"
error_msg += "".join(traceback.format_tb(exc_traceback))
print(error_msg)
# 创建临时日志管理器记录错误
from logger.logger_manager import LoggerManager
temp_logger = LoggerManager(None)
temp_logger.log("error", error_msg)
sys.excepthook = handle_global_exception
# 初始化DeepSeek API客户端
# 该客户端负责与DeepSeek服务器通信处理API请求和响应
api = DeepSeekAPI()
# 初始化日志管理器
# 该管理器负责记录系统日志,包括错误信息
logger_manager = LoggerManager(None)
# 初始化主聊天界面
# 将主窗口、API客户端和日志管理器作为参数传递给界面类
app = DeepSeekChatUI(root, api, logger_manager)
# 启动Tkinter主事件循环
# 该循环监听用户交互并更新UI程序会一直运行直到主窗口关闭
root.mainloop()