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

@@ -14,12 +14,14 @@ from datetime import datetime
# 尝试导入 tkinterweb 和 markdown2
try:
from tkinterweb import HtmlFrame
HAS_TKINTERWEB = True
except ImportError:
HAS_TKINTERWEB = False
try:
import markdown2
HAS_MARKDOWN2 = True
except ImportError:
HAS_MARKDOWN2 = False
@@ -34,7 +36,7 @@ class DeleteProgressWindow:
title: str = "执行删除",
managers: str = "",
dryrun: bool = False,
on_cancel: Optional[Callable] = None
on_cancel: Optional[Callable] = None,
):
"""
初始化删除进度窗口
@@ -100,14 +102,13 @@ class DeleteProgressWindow:
self.progress_frame.pack(fill=tk.X, pady=(0, 10))
self.progress_var = tk.StringVar(value="准备中...")
self.progress_label = ttk.Label(self.progress_frame, textvariable=self.progress_var)
self.progress_label = ttk.Label(
self.progress_frame, textvariable=self.progress_var
)
self.progress_label.pack(anchor="w")
self.progress_bar = ttk.Progressbar(
self.progress_frame,
mode='determinate',
length=660,
maximum=100
self.progress_frame, mode="determinate", length=660, maximum=100
)
self.progress_bar.pack(fill=tk.X, pady=5)
@@ -120,15 +121,15 @@ class DeleteProgressWindow:
height=10,
wrap=tk.WORD,
state=tk.DISABLED,
font=('Consolas', 9)
font=("Consolas", 9),
)
self.log_text.pack(fill=tk.BOTH, expand=True)
# 配置日志标签颜色
self.log_text.tag_configure('info', foreground='black')
self.log_text.tag_configure('success', foreground='green')
self.log_text.tag_configure('warning', foreground='orange')
self.log_text.tag_configure('error', foreground='red')
self.log_text.tag_configure("info", foreground="black")
self.log_text.tag_configure("success", foreground="green")
self.log_text.tag_configure("warning", foreground="orange")
self.log_text.tag_configure("error", foreground="red")
# 报告区域(完成后显示)- 初始隐藏
self.report_frame = ttk.LabelFrame(self.main_frame, text="执行报告", padding=5)
@@ -145,7 +146,7 @@ class DeleteProgressWindow:
height=20,
wrap=tk.WORD,
state=tk.DISABLED,
font=('Consolas', 9)
font=("Consolas", 9),
)
self.report_text.pack(fill=tk.BOTH, expand=True)
@@ -154,18 +155,12 @@ class DeleteProgressWindow:
button_frame.pack(fill=tk.X)
self.cancel_button = ttk.Button(
button_frame,
text="取消执行",
command=self._on_cancel
button_frame, text="取消执行", command=self._on_cancel
)
self.cancel_button.pack(side=tk.RIGHT)
# 关闭按钮(初始隐藏)
self.close_button = ttk.Button(
button_frame,
text="关闭",
command=self.close
)
self.close_button = ttk.Button(button_frame, text="关闭", command=self.close)
def _on_cancel(self):
"""处理取消操作"""
@@ -187,7 +182,7 @@ class DeleteProgressWindow:
"""
if total > 0:
percentage = int((current / total) * 100)
self.progress_bar['value'] = percentage
self.progress_bar["value"] = percentage
self.progress_var.set(message)
else:
self.progress_var.set(message)
@@ -263,8 +258,7 @@ class DeleteProgressWindow:
"""
# 使用 markdown2 转换
html_body = markdown2.markdown(
markdown_content,
extras=['tables', 'fenced-code-blocks']
markdown_content, extras=["tables", "fenced-code-blocks"]
)
# 添加样式
@@ -340,59 +334,65 @@ class DeleteProgressWindow:
Returns:
HTML 内容
"""
lines = markdown_content.split('\n')
html_parts = ['<!DOCTYPE html><html><head><meta charset="UTF-8">',
'<style>',
'body { font-family: "Microsoft YaHei", Arial, sans-serif; font-size: 12px; padding: 10px; }',
'h1 { color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px; }',
'h2 { color: #34495e; border-bottom: 1px solid #bdc3c7; margin-top: 20px; }',
'table { border-collapse: collapse; width: 100%; margin: 10px 0; }',
'th, td { border: 1px solid #bdc3c7; padding: 8px; text-align: left; }',
'th { background-color: #3498db; color: white; }',
'</style></head><body>']
lines = markdown_content.split("\n")
html_parts = [
'<!DOCTYPE html><html><head><meta charset="UTF-8">',
"<style>",
'body { font-family: "Microsoft YaHei", Arial, sans-serif; font-size: 12px; padding: 10px; }',
"h1 { color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px; }",
"h2 { color: #34495e; border-bottom: 1px solid #bdc3c7; margin-top: 20px; }",
"table { border-collapse: collapse; width: 100%; margin: 10px 0; }",
"th, td { border: 1px solid #bdc3c7; padding: 8px; text-align: left; }",
"th { background-color: #3498db; color: white; }",
"</style></head><body>",
]
in_table = False
for line in lines:
if line.startswith('# '):
html_parts.append(f'<h1>{line[2:]}</h1>')
elif line.startswith('## '):
html_parts.append(f'<h2>{line[3:]}</h2>')
elif line.startswith('| '):
if line.startswith("# "):
html_parts.append(f"<h1>{line[2:]}</h1>")
elif line.startswith("## "):
html_parts.append(f"<h2>{line[3:]}</h2>")
elif line.startswith("| "):
if not in_table:
html_parts.append('<table>')
html_parts.append("<table>")
in_table = True
# 检查是否是表头分隔行
if '|--' in line or '|-' in line:
if "|--" in line or "|-" in line:
continue
cells = [cell.strip() for cell in line.split('|')[1:-1]]
cells = [cell.strip() for cell in line.split("|")[1:-1]]
if cells:
# 第一行作为表头
if html_parts[-1] == '<table>':
html_parts.append('<tr>' + ''.join(f'<th>{c}</th>' for c in cells) + '</tr>')
if html_parts[-1] == "<table>":
html_parts.append(
"<tr>" + "".join(f"<th>{c}</th>" for c in cells) + "</tr>"
)
else:
html_parts.append('<tr>' + ''.join(f'<td>{c}</td>' for c in cells) + '</tr>')
elif line.startswith('- '):
html_parts.append(
"<tr>" + "".join(f"<td>{c}</td>" for c in cells) + "</tr>"
)
elif line.startswith("- "):
if in_table:
html_parts.append('</table>')
html_parts.append("</table>")
in_table = False
html_parts.append(f'<li>{line[2:]}</li>')
elif line.strip() == '':
html_parts.append(f"<li>{line[2:]}</li>")
elif line.strip() == "":
if in_table:
html_parts.append('</table>')
html_parts.append("</table>")
in_table = False
html_parts.append('<br>')
html_parts.append("<br>")
else:
if in_table:
html_parts.append('</table>')
html_parts.append("</table>")
in_table = False
if line.strip():
html_parts.append(f'<p>{line}</p>')
html_parts.append(f"<p>{line}</p>")
if in_table:
html_parts.append('</table>')
html_parts.append("</table>")
html_parts.append('</body></html>')
return '\n'.join(html_parts)
html_parts.append("</body></html>")
return "\n".join(html_parts)
def _markdown_to_text(self, markdown_content: str) -> str:
"""
@@ -404,34 +404,34 @@ class DeleteProgressWindow:
Returns:
格式化后的文本
"""
lines = markdown_content.split('\n')
lines = markdown_content.split("\n")
result = []
for line in lines:
# 标题
if line.startswith('# '):
result.append('=' * 60)
if line.startswith("# "):
result.append("=" * 60)
result.append(line[2:])
result.append('=' * 60)
elif line.startswith('## '):
result.append('')
result.append("=" * 60)
elif line.startswith("## "):
result.append("")
result.append(line[3:])
result.append('-' * 40)
elif line.startswith('| '):
result.append("-" * 40)
elif line.startswith("| "):
# 表格行 - 保持原样
result.append(line)
elif line.startswith('|--') or line.startswith('|-'):
elif line.startswith("|--") or line.startswith("|-"):
# 表格分隔线 - 跳过
continue
elif line.startswith('- '):
elif line.startswith("- "):
# 列表项
result.append(' ' + line)
elif line.strip() == '':
result.append('')
result.append(" " + line)
elif line.strip() == "":
result.append("")
else:
result.append(line)
return '\n'.join(result)
return "\n".join(result)
def close(self):
"""关闭窗口"""
@@ -444,4 +444,4 @@ class DeleteProgressWindow:
def set_completed(self):
"""设置为完成状态"""
self.cancel_button.pack_forget()
self.close_button.pack(side=tk.RIGHT)
self.close_button.pack(side=tk.RIGHT)