v1.1.0: 增加交互提示、路径输入、窗口属性配置

- main.py: 增加show_banner()启动说明、各阶段[INFO]日志、结果摘要、任意键退出
- file_selector.py: 重写为路径输入→验证→空输入弹窗回退→不存在循环重试
- run.bat: 新建启动脚本(chcp 65001, mode con cols=80 lines=20, color 0B, title固定署名, pause)
- Code/docs/modification-assessment.md: 修改需求评估文档
This commit is contained in:
2026-05-25 17:29:19 +08:00
parent 5fbc215e59
commit 836ad20515
35 changed files with 4105 additions and 25 deletions

View File

@@ -0,0 +1,49 @@
"""File selector — GUI dialog or CLI fallback.
Provides a single function ``select_file`` that:
1. Opens a tkinter file-dialog when a display is available.
2. Falls back to ``sys.argv[1]`` in headless environments.
"""
import sys
from typing import Optional
def select_file() -> Optional[str]:
"""Open a file-selection dialog and return the chosen path, or None.
Returns
-------
str | None
Selected file path, or ``None`` if the user cancelled / no
fallback is available.
"""
# Try tkinter GUI dialog first
try:
import tkinter
import tkinter.filedialog
root = tkinter.Tk()
root.withdraw() # hide the main window
root.attributes("-topmost", True)
filepath = tkinter.filedialog.askopenfilename(
title="选择 PinMAP 文件",
filetypes=[
("Excel 文件", "*.xls *.xlsx"),
("所有文件", "*.*"),
],
)
root.destroy()
if filepath:
# tkinter may return a Tcl object; normalise to str
return str(filepath)
return None
except (ImportError, Exception):
# No display / no tkinter — fall back to CLI argument
if len(sys.argv) > 1:
return sys.argv[1]
print("[WARN] 无 GUI 环境且未提供命令行参数")
return None