添加项目核心文件和 .gitignore
This commit is contained in:
60
main.py
60
main.py
@@ -1,37 +1,57 @@
|
||||
import logging
|
||||
import sys
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from gui.main_window import MainWindow
|
||||
|
||||
def setup_logging():
|
||||
"""设置日志"""
|
||||
log_dir = Path.home() / ".cursor_switcher" / "logs"
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
log_file = log_dir / "switcher.log"
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||
handlers=[
|
||||
logging.FileHandler(log_file, encoding="utf-8"),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
)
|
||||
logging.info("日志系统初始化完成")
|
||||
try:
|
||||
log_dir = Path.home() / ".cursor_switcher" / "logs"
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
log_file = log_dir / "switcher.log"
|
||||
|
||||
# 只输出到文件,不输出到控制台
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||
handlers=[
|
||||
logging.FileHandler(log_file, encoding="utf-8"),
|
||||
]
|
||||
)
|
||||
except Exception as e:
|
||||
# 不打印错误信息,只记录到日志
|
||||
pass
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
try:
|
||||
setup_logging()
|
||||
logging.info("启动GUI界面...")
|
||||
|
||||
# 检查Python版本
|
||||
logging.info(f"Python版本: {sys.version}")
|
||||
|
||||
# 检查工作目录
|
||||
logging.info(f"当前工作目录: {Path.cwd()}")
|
||||
|
||||
# 检查模块路径
|
||||
logging.info("Python路径:")
|
||||
for p in sys.path:
|
||||
logging.info(f" - {p}")
|
||||
|
||||
logging.info("正在初始化主窗口...")
|
||||
window = MainWindow()
|
||||
|
||||
logging.info("正在启动主窗口...")
|
||||
window.run()
|
||||
except KeyboardInterrupt:
|
||||
logging.info("程序被用户中断")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"程序运行出错: {str(e)}")
|
||||
finally:
|
||||
logging.info("程序退出")
|
||||
error_msg = f"程序运行出错: {str(e)}\n{traceback.format_exc()}"
|
||||
logging.error(error_msg)
|
||||
# 使用tkinter的消息框显示错误
|
||||
from tkinter import messagebox
|
||||
messagebox.showerror("错误", error_msg)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user