feat: 增强日志显示和方案表格信息展示

This commit is contained in:
dmy
2026-01-04 18:56:00 +08:00
parent dd7265ff4f
commit a42a8ec7f1

42
gui.py
View File

@@ -362,10 +362,12 @@ def index():
def process_log_queue():
if refs["log_box"]:
new_msg = False
while not log_queue.empty():
try:
msg = log_queue.get_nowait()
refs["log_box"].push(msg)
new_msg = True
if msg.startswith("--- Scenario"):
scenario_name = msg.replace("---", "").strip()
if refs["status_label"]:
@@ -377,6 +379,11 @@ def index():
refs["status_label"].text = "准备开始计算..."
except queue.Empty:
break
if new_msg:
# 强制日志框滚动到最底部,确保最后一行可见
ui.run_javascript(
'const el = document.querySelector(".analysis-log-box"); if (el) { el.scrollTop = el.scrollHeight; }'
)
log_timer = ui.timer(0.1, process_log_queue)
if refs["status_label"]:
@@ -432,10 +439,33 @@ def index():
name_display = f"(推荐) {name_display}"
is_best = True
# 生成备注信息
note = ""
original_name = res["name"]
# 识别算法
if "MST Method" in original_name:
note += "最小生成树算法(无容量约束基准); "
elif "Base" in original_name:
note += "基础扇区扫描(单次扫描); "
elif "Rotational" in original_name:
note += "旋转扫描优化(全局最优角度); "
elif "Esau-Williams" in original_name:
note += "Esau-Williams启发式算法(权衡距离与容量); "
# 识别电缆策略
if "Standard" in original_name:
note += "不包含可选电缆型号。"
elif "With Optional" in original_name:
note += "含可选电缆型号。"
elif "No Max" in original_name:
note += "不包含可选电缆型号,且可使用的最大截面电缆降一档截面。"
row_dict = {
"name": name_display,
"cost_wan": round(res["cost"] / 10000, 2),
"loss_kw": round(res["loss"], 2),
"cost_wan": f"{res['cost'] / 10000:.2f}",
"loss_kw": f"{res['loss']:.2f}",
"note": note,
"original_name": res["name"],
}
table_data.append(row_dict)
@@ -471,7 +501,7 @@ def index():
"w-full mt-4 text-sm"
):
refs["log_box"] = ui.log(max_lines=100).classes(
"w-full h-32 text-xs font-mono bg-black text-green-400"
"w-full h-32 text-xs font-mono bg-black text-green-400 analysis-log-box"
)
processing_dialog.props("persistent")
@@ -538,6 +568,12 @@ def index():
"field": "loss_kw",
"sortable": True,
},
{
"name": "note",
"label": "备注",
"field": "note",
"align": "left",
},
]
# 使用内置的 selection='single' 结合行点击事件实现背景高亮
# 这样可以完全由 Python 事件逻辑控制,不依赖 CSS 伪类