fix(gui,gcode): 无数据时格式化显示0s和0.00g替代未知

format_duration/format_filament 接收 None 时返回零值字符串而非未知,
GUI 初始合计标签同步更新。
This commit is contained in:
2026-07-28 10:26:48 +08:00
parent 002b8117d8
commit b749bdd807
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -120,7 +120,7 @@ def format_duration(seconds: float | None) -> str:
格式化后的时间字符串,如 "2h 30m""5m 20s""45s",未知则返回 "未知"
"""
if seconds is None:
return "未知"
return "0s"
total = max(0, int(round(seconds)))
hours, rem = divmod(total, 3600)
minutes, secs = divmod(rem, 60)
@@ -142,7 +142,7 @@ def format_filament(weight_grams: float | None, used_m: float | None = None) ->
格式化后的耗材信息字符串,未知则返回 "未知"
"""
if weight_grams is None and used_m is None:
return "未知"
return "0.00 g"
parts: list[str] = []
if weight_grams is not None:
parts.append(f"{weight_grams:.2f} g")