chore: Remove obsolete scripts and enhance path configuration
- Deleted `check_md_files.py` and `fix_cursor_md_issue.py` as they are no longer needed. - Added new functions in `path_config.py` for better path management, including actions log and run_cli paths. - Updated various modules to utilize the new path configuration, ensuring consistency and maintainability across the project.
This commit is contained in:
1 parent
b9849b9f5a
commit
bdf9312bc9
58 files changed
+2472
-854
No files matched your search
@@ -15,7 +15,12 @@ if sys.platform == "win32":
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
CONFIG_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config", "config.json")
|
||||
try:
|
||||
import path_config
|
||||
CONFIG_PATH = path_config.get_config_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
CONFIG_PATH = path_config.get_config_path()
|
||||
|
||||
|
||||
def check_conflicts(cfg: dict) -> list:
|
||||
|
||||
+59
-2
@@ -10,6 +10,14 @@ try:
|
||||
except Exception as e:
|
||||
raise SystemExit(f"tkinter 不可用:{e}\n请安装带 tkinter 的 Python,或改用画图/PS/GIMP 取坐标。")
|
||||
|
||||
# 尝试导入拖放支持库
|
||||
try:
|
||||
from tkinterdnd2 import DND_FILES, TkinterDnD
|
||||
HAS_DND = True
|
||||
except ImportError:
|
||||
HAS_DND = False
|
||||
TkinterDnD = None
|
||||
|
||||
|
||||
def clamp(v: float, lo: float, hi: float) -> float:
|
||||
return lo if v < lo else hi if v > hi else v
|
||||
@@ -28,7 +36,11 @@ class CoordPicker:
|
||||
self.file_list: list[Path] = []
|
||||
self.file_idx: int = -1
|
||||
|
||||
self.root = tk.Tk()
|
||||
# 使用 TkinterDnD 支持拖放(如果可用)
|
||||
if HAS_DND:
|
||||
self.root = TkinterDnD.Tk()
|
||||
else:
|
||||
self.root = tk.Tk()
|
||||
|
||||
# 菜单 + 快捷键
|
||||
menubar = tk.Menu(self.root)
|
||||
@@ -51,13 +63,25 @@ class CoordPicker:
|
||||
self._canvas_image_id = self.canvas.create_image(0, 0, anchor=tk.NW)
|
||||
|
||||
self.status = tk.StringVar()
|
||||
self.status.set("移动鼠标查看坐标;单击复制坐标;Ctrl+O 打开图片")
|
||||
if HAS_DND:
|
||||
self.status.set("移动鼠标查看坐标;单击复制坐标;Ctrl+O 打开图片;或直接拖放图片到窗口")
|
||||
else:
|
||||
self.status.set("移动鼠标查看坐标;单击复制坐标;Ctrl+O 打开图片(提示:安装 tkinterdnd2 可支持拖放)")
|
||||
self.label = tk.Label(self.root, textvariable=self.status, anchor="w")
|
||||
self.label.pack(fill=tk.X)
|
||||
|
||||
self.canvas.bind("<Motion>", self.on_move)
|
||||
self.canvas.bind("<Button-1>", self.on_click)
|
||||
|
||||
# 添加拖放支持
|
||||
if HAS_DND:
|
||||
self.root.drop_target_register(DND_FILES)
|
||||
self.root.dnd_bind('<<Drop>>', self.on_drop)
|
||||
self.canvas.drop_target_register(DND_FILES)
|
||||
self.canvas.dnd_bind('<<Drop>>', self.on_drop)
|
||||
self.label.drop_target_register(DND_FILES)
|
||||
self.label.dnd_bind('<<Drop>>', self.on_drop)
|
||||
|
||||
if image_path is None:
|
||||
if not self.open_dialog():
|
||||
raise SystemExit(2)
|
||||
@@ -181,6 +205,39 @@ class CoordPicker:
|
||||
if self._load_by_index(self.file_idx - 1):
|
||||
self.status.set(f"上一张: {self.image_path.name if self.image_path else ''}")
|
||||
|
||||
def on_drop(self, event) -> None:
|
||||
"""处理拖放事件"""
|
||||
if not HAS_DND:
|
||||
return
|
||||
|
||||
try:
|
||||
# 获取拖放的文件路径
|
||||
files = self.root.tk.splitlist(event.data)
|
||||
if not files:
|
||||
return
|
||||
|
||||
# 取第一个文件
|
||||
file_path = files[0]
|
||||
# 移除可能的花括号(Windows 拖放可能包含)
|
||||
file_path = file_path.strip('{}')
|
||||
|
||||
path = Path(file_path)
|
||||
if not path.exists():
|
||||
self.status.set(f"文件不存在: {path}")
|
||||
return
|
||||
|
||||
# 检查是否为图片文件
|
||||
exts = {".png", ".jpg", ".jpeg", ".bmp", ".webp"}
|
||||
if path.suffix.lower() not in exts:
|
||||
self.status.set(f"不是支持的图片格式: {path.suffix}")
|
||||
return
|
||||
|
||||
# 加载图片
|
||||
self.set_image(path, update_list=True)
|
||||
self.status.set(f"已加载: {path.name}")
|
||||
except Exception as e:
|
||||
self.status.set(f"拖放失败: {e}")
|
||||
|
||||
def run(self):
|
||||
self.root.mainloop()
|
||||
|
||||
|
||||
Reference in new issue
Block a user