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

@@ -39,10 +39,10 @@ class CheckboxTreeview(ttk.Treeview):
self.on_checkbox_change = on_checkbox_change # checkbox 状态改变回调
# 排序状态
self.sort_column = None # 当前排序列的列标识符
self.sort_direction = None # 'asc', 'desc', 或 None
self.sort_column = None # 当前排序列的列标识符
self.sort_direction = None # 'asc', 'desc', 或 None
self.sortable_columns = ["选择", "材料名称"] # 可排序的列白名单
self.original_headings = {} # 存储原始列标题文本(不含箭头)
self.original_headings = {} # 存储原始列标题文本(不含箭头)
# 存储原始列标题(延迟执行以确保标题已设置)
self.after(100, self._store_original_headings)
@@ -121,7 +121,7 @@ class CheckboxTreeview(ttk.Treeview):
# 初始化 checkbox 状态为未选中
checkbox_char = values[0] if values else ""
self.checkboxes[item] = (checkbox_char == "")
self.checkboxes[item] = checkbox_char == ""
return item
@@ -134,8 +134,8 @@ class CheckboxTreeview(ttk.Treeview):
def _store_original_headings(self):
"""存储原始列标题文本(不含箭头)"""
for col in self['columns']:
self.original_headings[col] = self.heading(col, 'text')
for col in self["columns"]:
self.original_headings[col] = self.heading(col, "text")
def _get_column_id_from_column_index(self, column_index):
"""将列索引 ('#1', '#2') 转换为列标识符
@@ -147,7 +147,7 @@ class CheckboxTreeview(ttk.Treeview):
列标识符,如 '选择', '材料名称'
"""
index = int(column_index[1:]) - 1
columns = self['columns']
columns = self["columns"]
if 0 <= index < len(columns):
return columns[index]
return None
@@ -173,15 +173,15 @@ class CheckboxTreeview(ttk.Treeview):
# 确定新的排序方向
if self.sort_column == column_id:
# 同一列asc -> desc -> None
if self.sort_direction == 'asc':
new_direction = 'desc'
elif self.sort_direction == 'desc':
if self.sort_direction == "asc":
new_direction = "desc"
elif self.sort_direction == "desc":
new_direction = None
else:
new_direction = 'asc'
new_direction = "asc"
else:
# 不同列:从升序开始
new_direction = 'asc'
new_direction = "asc"
# 应用排序
if new_direction:
@@ -208,35 +208,33 @@ class CheckboxTreeview(ttk.Treeview):
for item in self.get_children():
values = self.item(item, "values")
checkbox_state = self.checkboxes.get(item, False)
items_data.append({
'item_id': item,
'values': values,
'checked': checkbox_state
})
items_data.append(
{"item_id": item, "values": values, "checked": checkbox_state}
)
# 根据列和方向排序
if column_id == "选择":
# 按复选框状态排序(选中在前,未选中在后)
items_data.sort(key=lambda x: x['checked'], reverse=(direction == 'desc'))
items_data.sort(key=lambda x: x["checked"], reverse=(direction == "desc"))
elif column_id == "材料名称":
# 按材料名称排序
items_data.sort(
key=lambda x: str(x['values'][1]) if len(x['values']) > 1 else "",
reverse=(direction == 'desc')
key=lambda x: str(x["values"][1]) if len(x["values"]) > 1 else "",
reverse=(direction == "desc"),
)
# 重新排列项目顺序(使用 detach 和 move 保留项目ID和状态
for item_data in items_data:
self.move(item_data['item_id'], '', 'end')
self.move(item_data["item_id"], "", "end")
def _update_heading_display(self):
"""更新列标题显示(添加/移除排序箭头)"""
for col in self['columns']:
for col in self["columns"]:
original = self.original_headings.get(col, col)
if col == self.sort_column:
# 添加排序箭头
arrow = "" if self.sort_direction == 'asc' else ""
arrow = "" if self.sort_direction == "asc" else ""
self.heading(col, text=original + arrow)
else:
# 移除箭头,显示原始标题
self.heading(col, text=original)
self.heading(col, text=original)