chore: Clean up blank lines and enhance code organization
- Removed excessive blank lines from multiple Python scripts and configuration files to improve readability and maintainability. - Ensured consistent formatting across the project, contributing to a more organized codebase. - Added new files for testing and analysis, including `test_screenshot_error_handling.py` and `test_screenshot_reuse_optimization.py`, to improve testing coverage and functionality.
This commit is contained in:
1 parent
7db9864848
commit
478ae69052
85 files changed
+2879
-383
No files matched your search
@@ -134,3 +134,4 @@ python region_selector.py path/to/image.png
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,10 +9,16 @@ from datetime import datetime
|
||||
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
# 尝试使用reconfigure方法(Python 3.7+)
|
||||
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
|
||||
if reconfigure_func:
|
||||
reconfigure_func(encoding='utf-8')
|
||||
except Exception:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
try:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
|
||||
@@ -10,10 +10,16 @@ from datetime import datetime
|
||||
# 设置UTF-8输出
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
# 尝试使用reconfigure方法(Python 3.7+)
|
||||
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
|
||||
if reconfigure_func:
|
||||
reconfigure_func(encoding='utf-8')
|
||||
except Exception:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
try:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def analyze_log_file(log_path):
|
||||
"""分析日志文件"""
|
||||
|
||||
@@ -9,7 +9,9 @@ import sys
|
||||
# 修复Windows控制台编码问题
|
||||
if sys.platform == "win32":
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8") # type: ignore[attr-defined]
|
||||
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
|
||||
if reconfigure_func:
|
||||
reconfigure_func(encoding="utf-8")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ import sys
|
||||
# 修复Windows控制台编码问题
|
||||
if sys.platform == "win32":
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8') # type: ignore[attr-defined]
|
||||
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
|
||||
if reconfigure_func:
|
||||
reconfigure_func(encoding='utf-8')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -10,10 +10,16 @@ from datetime import datetime
|
||||
# 设置UTF-8输出
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
# 尝试使用reconfigure方法(Python 3.7+)
|
||||
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
|
||||
if reconfigure_func:
|
||||
reconfigure_func(encoding='utf-8')
|
||||
except Exception:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
try:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
|
||||
@@ -9,10 +9,16 @@ import platform
|
||||
# 设置UTF-8输出
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
# 尝试使用reconfigure方法(Python 3.7+)
|
||||
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
|
||||
if reconfigure_func:
|
||||
reconfigure_func(encoding='utf-8')
|
||||
except Exception:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
try:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def check_cpu():
|
||||
"""检查CPU配置"""
|
||||
|
||||
+25
-9
@@ -12,11 +12,13 @@ except Exception as e:
|
||||
|
||||
# 尝试导入拖放支持库
|
||||
try:
|
||||
from tkinterdnd2 import DND_FILES, TkinterDnD
|
||||
from tkinterdnd2 import DND_FILES, TkinterDnD # type: ignore[import]
|
||||
HAS_DND = True
|
||||
except ImportError:
|
||||
HAS_DND = False
|
||||
# 如果导入失败,提供占位符
|
||||
DND_FILES = None
|
||||
TkinterDnD = None
|
||||
HAS_DND = False
|
||||
|
||||
|
||||
def clamp(v: float, lo: float, hi: float) -> float:
|
||||
@@ -116,12 +118,26 @@ class CoordPicker:
|
||||
|
||||
# 添加拖放支持
|
||||
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)
|
||||
try:
|
||||
drop_target_register = getattr(self.root, 'drop_target_register', None)
|
||||
dnd_bind = getattr(self.root, 'dnd_bind', None)
|
||||
if drop_target_register and dnd_bind:
|
||||
drop_target_register(DND_FILES)
|
||||
dnd_bind('<<Drop>>', self.on_drop)
|
||||
|
||||
drop_target_register = getattr(self.canvas, 'drop_target_register', None)
|
||||
dnd_bind = getattr(self.canvas, 'dnd_bind', None)
|
||||
if drop_target_register and dnd_bind:
|
||||
drop_target_register(DND_FILES)
|
||||
dnd_bind('<<Drop>>', self.on_drop)
|
||||
|
||||
drop_target_register = getattr(self.label, 'drop_target_register', None)
|
||||
dnd_bind = getattr(self.label, 'dnd_bind', None)
|
||||
if drop_target_register and dnd_bind:
|
||||
drop_target_register(DND_FILES)
|
||||
dnd_bind('<<Drop>>', self.on_drop)
|
||||
except Exception:
|
||||
pass # 忽略拖放设置失败
|
||||
|
||||
if image_path is None:
|
||||
if not self.open_dialog():
|
||||
@@ -446,7 +462,7 @@ class CoordPicker:
|
||||
tk_mag_img = ImageTk.PhotoImage(magnified)
|
||||
self.magnifier_canvas.delete("all")
|
||||
self.magnifier_canvas.create_image(self.magnifier_size // 2, self.magnifier_size // 2, image=tk_mag_img)
|
||||
self.magnifier_canvas.image = tk_mag_img # 保持引用
|
||||
setattr(self.magnifier_canvas, 'image', tk_mag_img) # 保持引用
|
||||
|
||||
# 绘制十字线
|
||||
center = self.magnifier_size // 2
|
||||
|
||||
@@ -183,10 +183,20 @@ class RegionSelector:
|
||||
|
||||
# 添加拖放支持
|
||||
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)
|
||||
try:
|
||||
drop_target_register = getattr(self.root, 'drop_target_register', None)
|
||||
dnd_bind = getattr(self.root, 'dnd_bind', None)
|
||||
if drop_target_register and dnd_bind:
|
||||
drop_target_register(DND_FILES)
|
||||
dnd_bind('<<Drop>>', self.on_drop)
|
||||
|
||||
drop_target_register = getattr(self.canvas, 'drop_target_register', None)
|
||||
dnd_bind = getattr(self.canvas, 'dnd_bind', None)
|
||||
if drop_target_register and dnd_bind:
|
||||
drop_target_register(DND_FILES)
|
||||
dnd_bind('<<Drop>>', self.on_drop)
|
||||
except Exception:
|
||||
pass # 忽略拖放设置失败
|
||||
|
||||
def _create_control_panel(self, parent):
|
||||
"""创建控制面板"""
|
||||
|
||||
@@ -476,7 +476,7 @@ Ctrl+F: 适应窗口"""
|
||||
"""缩小"""
|
||||
if self.img:
|
||||
canvas_w = self.canvas.winfo_width()
|
||||
canvas_h = self.canvas.h // 2
|
||||
canvas_h = self.canvas.winfo_height() // 2
|
||||
center_x = canvas_w // 2
|
||||
center_y = canvas_h // 2
|
||||
self.zoom_at_point(center_x, center_y, 0.67)
|
||||
|
||||
Reference in new issue
Block a user