style: format all Python files with Black

Apply Black formatter to the entire codebase for consistent code style.

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-02-26 22:44:03 +08:00
parent 1b16842a2c
commit 3b7c00377f
46 changed files with 1488 additions and 974 deletions

View File

@@ -15,11 +15,11 @@ class LogText(tk.Frame):
# 日志级别颜色配置
LOG_COLORS = {
'INFO': '#000000', # 黑色
'SUCCESS': '#008000', # 绿色
'WARNING': '#FF8C00', # 深橙色
'ERROR': '#FF0000', # 红色
'DEBUG': '#808080', # 灰色
"INFO": "#000000", # 黑色
"SUCCESS": "#008000", # 绿色
"WARNING": "#FF8C00", # 深橙色
"ERROR": "#FF0000", # 红色
"DEBUG": "#808080", # 灰色
}
def __init__(self, parent, readonly=True, **kwargs):
@@ -67,19 +67,19 @@ class LogText(tk.Frame):
def _make_readonly(self):
"""通过绑定事件使文本框只读"""
# 允许复制、全选等常用操作,阻止其他编辑操作
self.text.bind('<Key>', self._handle_key)
self.text.bind('<Button-1>', self._allow_click) # 允许左键点击选择
self.text.bind("<Key>", self._handle_key)
self.text.bind("<Button-1>", self._allow_click) # 允许左键点击选择
def _handle_key(self, event):
"""处理按键事件,允许复制操作,阻止编辑"""
# 允许的快捷键
allowed_keys = [
'Control-c', # 复制
'Control-C', # 复制(大写)
'Control-a', # 全选
'Control-A', # 全选(大写)
'Control-x', # 剪切(虽然剪不了,但不报错)
'Control-X',
"Control-c", # 复制
"Control-C", # 复制(大写)
"Control-a", # 全选
"Control-A", # 全选(大写)
"Control-x", # 剪切(虽然剪不了,但不报错)
"Control-X",
]
# 检查是否是允许的快捷键
@@ -93,14 +93,14 @@ class LogText(tk.Frame):
return # 允许执行
# 其他所有按键都阻止
return 'break'
return "break"
def _allow_click(self, event):
"""允许点击和选择文本"""
# 不打断事件,允许正常的选择操作
return
def log(self, message: str, level: str = 'INFO') -> None:
def log(self, message: str, level: str = "INFO") -> None:
"""
添加日志消息
@@ -111,46 +111,46 @@ class LogText(tk.Frame):
# 确保 tags 已配置
self._ensure_tags_configured()
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
log_message = f"[{timestamp}] [{level}] {message}\n"
# 插入文本
tag = level.lower() if self._tags_configured else None
if tag:
try:
self.text.insert('end', log_message, (tag,))
self.text.insert("end", log_message, (tag,))
except Exception:
# 如果带标签插入失败,尝试不带标签
self.text.insert('end', log_message)
self.text.insert("end", log_message)
else:
self.text.insert('end', log_message)
self.text.insert("end", log_message)
# 自动滚动到底部
self.text.see('end')
self.text.see("end")
def info(self, message: str) -> None:
"""添加 INFO 级别日志"""
self.log(message, 'INFO')
self.log(message, "INFO")
def success(self, message: str) -> None:
"""添加 SUCCESS 级别日志"""
self.log(message, 'SUCCESS')
self.log(message, "SUCCESS")
def warning(self, message: str) -> None:
"""添加 WARNING 级别日志"""
self.log(message, 'WARNING')
self.log(message, "WARNING")
def error(self, message: str) -> None:
"""添加 ERROR 级别日志"""
self.log(message, 'ERROR')
self.log(message, "ERROR")
def debug(self, message: str) -> None:
"""添加 DEBUG 级别日志"""
self.log(message, 'DEBUG')
self.log(message, "DEBUG")
def clear(self) -> None:
"""清空日志"""
self.text.delete('1.0', 'end')
self.text.delete("1.0", "end")
def save_to_file(self, file_path: str) -> bool:
"""
@@ -163,8 +163,8 @@ class LogText(tk.Frame):
是否成功
"""
try:
with open(file_path, 'w', encoding='utf-8') as f:
f.write(self.text.get('1.0', 'end-1c'))
with open(file_path, "w", encoding="utf-8") as f:
f.write(self.text.get("1.0", "end-1c"))
return True
except Exception as e:
self.error(f"保存日志失败: {e}")
@@ -182,5 +182,6 @@ class LogText(tk.Frame):
def apply_font(self, font_family: str, font_size: int):
"""应用字体设置"""
from tkinter import font as tk_font
font_spec = tk_font.Font(family=font_family, size=font_size)
self.text.configure(font=font_spec)